Hello, all.
Once again I am running into something that is probably easy, but just cannot figure it out. A group shape is treated as a Shape by VBA. We can set its parameters with the same commands that are used with simple shapes. Let us pretend our selected shape is a group and do this:
Sub GroupTrouble() Dim S As Shape Set S = ActiveSelectionRange.Shapes.First S.Outline.SetProperties 1, , CreateRGBColor(255, 0, 0) End Sub
That works just fine (as well as most simple shape commands - fill, movement, rotation etc), but this:
Sub GroupTrouble() Dim S As Shape Set S = ActiveSelectionRange.Shapes.First Debug.Print S.Outline.Color.RGBGreen End Sub
Throws an error. We cannot get settings from a group as from a shape.
In my case the important options are outline colors and the ability to do IsOnCurve checkups. I have done some functions that go through the subshapes. But, for example, CreateBoundary creates an object that is already inside the group and that is super annoying. Same with other functions.
Any help with this will be greatly appreciated.
I think what you are searching for is
s.group.shapes.all.getcolors
which yields an array of colors in the group
sorry, i mean: s.shapes.all.getcolors
You can also do this with a little bit of CQL, yes its more complicated, but it is a good example of what can be done with CQL:
Sub AllColors() strColors = ActiveShape.Evaluate("@children.foreach(array(), $lasteval.addarray($item.colors)).unique.convert($item).join(' | ')") Debug.Print strColors End Sub
I am straight up honored to get replies from some of the greatest minds on this forum. This will really help avoid some complex loops and messy code. Thanks, guys!
Hi, Shelby
Your code works with group shapes. If you want to get similar results with all selected objects you can use more simple CQL.
Sub CQLColors() MsgBox ActiveSelection.Evaluate("@colors.convert($item).join('" & vbCr & "')")End SubSub CQLColorsNames() MsgBox ActiveSelection.Evaluate("@colors.convert($item.name).join('" & vbCr & "')")End Sub
You'll have to add more code to dig inside powerclips.