Hello,
im new at using macro in corel, i just take code from this forum, and tried to customized thing with trial and error, i cant write script to be honest (hehe)im working at laser cutting. after finising the design i need to clean-up the design, like remove the small shape that too small for laser cutting, like image below
for now, i have to break apart the object, then manually deleting the small shapes.
is it possible to do it with macro?
im thinking a code that
- break apart the shape,
- selecting shape that too short with parameter "length of curve" < 3 cm
- then delete that selection
- and put everything back
thanks
Yep, you can do this with a macro. I have kepts this very simple since you are just learning. It basically does your exact steps, breaks apart the selection, deletes the small shapes, then combines everthing back to a single shape.
Sub DeleteSmallShapes() Dim srSelection As ShapeRange, s As Shape 'Break apart the active selection Set srSelection = ActiveSelectionRange.BreakApartEx 'Delete all shapes that are smaller than 1.5cm srSelection.Shapes.FindShapes(Query:="@width < {1.5cm} and @height < {1.5cm}").Delete 'Combine back to a single shape Set s = srSelection.Combine 'Select the combined shape s.CreateSelection End Sub
Happy coding,
-Shelby
wow thanks for fast reply, shelby.
I've tried the code, and it's works perfectly for general shapes.
but sometimes, the small shapes is wide but short, or tall but thin, or is rotated. is there workaround for this case?
this is example, left image is initial design, right is expected design.
also, is it possible to add query with @lengthofcurve?
Thanks.
Robby,
Sure you could do it by length or by area if you wanted. I normally use DisplayCurve for this. And pay attention to the change in the Unit.
Delete by Area
srSelection.Shapes.FindShapes(Query:="@com.DisplayCurve.Area < {1cm^0}").Delete
Delete by Length
srSelection.Shapes.FindShapes(Query:="@com.DisplayCurve.Length < {1.5cm^0}").Delete
Thank you Shelby, I've tried the code, and works as expected. i'll play with the number, to figure out what
Shelby Moore said:{1cm^0}
means.
Thank you, for your time Shelby, i really appreciated it.