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
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.
Macros are good but Corel never supports 3rd party developers so they're never great!
Imagine if they kept them in the loop and Macros worked without BS from version to version.