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.
I work in Photo-Paint alot but my work is never automated. However reading this I see that the script nomenclature is quite different than what's reported to the user via the interface.
PP never uses layers only objects but your script says layers andvfunctionsvwith that nomenclature, interesting.
Also all objects once combined are returned to the background. The background in PP (for lack of a better description) can be promoted to an object on a transparent object however iscrathervstatic until that happens.
David Milisock said:I work in Photo-Paint alot but my work is never automated.
I saw the power of scripting as soon as it came available in PP. It has always been frustrating, but once you work out the bugs can be really helpful.
David Milisock said:PP never uses layers only objects but your script says layers andvfunctionsvwith that nomenclature, interesting.
Yes although they are objects in PP layers via VBA works the same, mostly.
Yes the scripting tool that produces CSC scripts is more like the old procedural "CorelScript". In fact some things like applying effects require the CorelScript object and you can take recorder's script and adapt it for VBA
Application.CorelScript.BitmapEffect ...
The snippet in the orginal post done with recorder as CorelScript looks like this:
WITHOBJECT "CorelPHOTOPAINT.Automation.18" .SetDocumentInfo 635, 29 .ObjectSelectionEx "4,3,2,1", "", TRUE, TRUE, FALSE, 4, -1 .ObjectCombine .ObjectSelectNone .ObjectSelect 1, TRUE .ObjectSelect 2, TRUE .ObjectSelect 3, TRUE .ObjectSelect 4, TRUE .EndObject END WITHOBJECT
The issue with old CorelScript was each time I upgraded CorelDRAW I had to change my scripts to match the version with the line "CorelPHOTOPAINT.Automation.18" which is not needed with VBA. (Yes I did create a utility function that queried the CDR version and set a global variable, but VBA allowed script to be more generic and efficient). Of course other preferable aspects are for example VBA can select objects by name without having to know their stacking index. As Eskimo said with DRAW the VBA support has been much better. Paint has been the stepchild to Corel after they conceded to PhotoShop. I do have Corel PaintShop Pro but it seems more focused for digital photographers than graphic artists and is not integrated with DRAW. Maybe in the 2020 version (fingers crossed) which would entice me to upgrade.
"CorelPHOTOPAINT.Automation.18"
I've been doing custom graphics in CorelDRAW for a very long time. Nothing I do is repeated enough to benefit from a script. I thought about it a couple times but the jobs didn't repeat enough to pay for the cost of a Macro or the time to develop one. Add to that the issues, read costs with Macros when the app updates. I never saw enough ROI. With staffing costs exceeding $65 an hour in a very short time a Macro costs more than what it's worth.
My image editing is for the architectural industry mostly and I won't even batch process RAW files.
In my 30 years of image editing I've found that there's always a set of images that can be improved with a batch process but never a set of images that will be GREAT with a batch process.
David Milisock said:I've been doing custom graphics in CorelDRAW for a very long time. Nothing I do is repeated enough to benefit from a script.
just depends on ones needs... the genius' behind these macros etc work wonders and really automate things that would normally take MUCH LONGER and minimize extra cost.