I have a VBA script I am working on in which I collect a number of image layers into a range object. I use the Combine() method which should return a layer object, but I cannot see to set it to a variable for further processing. "pix" variable here is the current image document in this code fragment.
Set myLayers = New LayerRange' Add layers to rangemyLayers.Add pix.Layers.Item("a")myLayers.Add pix.Layers.Item("b")myLayers.Add pix.Layers.Item("c")myLayers.Add pix.Layers.Item("d")' Combine layers to new layerSet newLayer = myLayers.Combine()
Set myLayers = New LayerRange
' Add layers to range
myLayers.Add pix.Layers.Item("a")
myLayers.Add pix.Layers.Item("b")
myLayers.Add pix.Layers.Item("c")
myLayers.Add pix.Layers.Item("d")
' Combine layers to new layer
Set newLayer = myLayers.Combine()
However newLayer is still nothing. The image still shows layer "a" as the combined layers "a" through "d" in Object Manager. Although "pix" the current document has "a" at index 2 in Items collection:
TypeName(newlayer) returns 'nothing'
TypeName(pix.Layers.Item("a")) returns 'iPaintLayer'
TypeName(pix.Layers.Item(2)) returns 'iPaintLayer'
So the layer seems to be there but cannot be accessed or assign to a variable. If you try you get a runtime error 'The references object doesn't exist anymore. So how do you combine several layer objects to a single layer object and access it afterwards?
--
Jonathan
Wow! So I get this email announcing that I earned "Ask A Question I" achievement whatever that means. To be honest I would rather received is information on the problem at hand or at least a pointer towards where I can find some real information on Corel's version of VBA. Google has be failing me here... I have be using CD since version 4 and the scripting not only has changed drastically over that time, but it has always been woefully undocumented and quirky. Yes I know that I am still on X8, but viewing all the instability issues with 2019 I do no see any compelling reason to upgrade.
I'd help you if I could, friend, but Photo-Paint is a mystery to me when it comes to automation using VBA.
Though there's always room for improvement, the situation is better for DRAW.
Yes and what is infuriating is stuff that works in Draw fails in Paint. Automation is SO HANDY, I have created many scripts over the years that is a real asset to my workflow. I have discovered little PAINT-only quirks for instance where some BitmapEffects only apply properly if the image is set to 100% zoom BEFORE applying the effect.
But here is what I find strange in my code snippet above. Creating the LayerRange object from layers in image becomes a workable object. The Combine() method on LayerRange object is defined as:
Function Combine() As Layer Member of PHOTOPAINT.LayerRange Combines the layers of the layer range with an object
So it is a function not a sub and SHOULD return a Layer object. Yet I cannot set the results to a variable. It is always nothing. The original document object now shows the format four layers reduce to one, the first one in the list to create the range "a". It can be counted via:
ActiveDocument.Layers.Count()
It does return the new layer count but trying to access it or set to a variable either by name
ActiveDocument.Layers.Item("a")
or by layer index
ActiveDocument.Layers.Item(2)
fails. It is like a ghost. I can see it, can get some properties of it, but cannot access or modify it. There must be some way to access the resultant layer after combining several.
I did a little testing based on the code fragments you provided, and I see the same thing. It combines the Layers in the LayerRange, but I don't get a Layer from it.
I also can't get anything for ActiveLayer after combining, either. I was hoping that might be a workaround.
See the posts from Alex Vakulenko in this thread on his Oberon forum: VBA problem in PP11.
Yep that's it. 17 years later same crap. Another "quirk" I need to put on my list. Luckily in this script all I wanted to do was rename the resultant layer and the workaround is to name the top most layer what I want before combining. I guess if I want to do any more processing it will take a second script. I bet this issue is still in v2019. I'll wait on any upgrades.