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.
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.
Yes, for example I have created scripts that do preparatory work. One that strips EXIF info from images making images smaller for web sites. Auto resizing to a max size also for websites, in fact one for one of my websites that resizes, create thumbnails, and code fragment for a one-click process to maintain that site. Others for one-click to modify scan drawings as preparation for tracing to make DRAW lineart. And the list goes on...
Like I said you must have repetitive work for a Macro to be useful. From my view with alot of repetitive work euthanasia can be useful.