Questions about virtual shapes and layers

Hello!

So I have been looking at ways of speeding up my macro projects. Of course virtual shapes and layers sound like the way to go.

But their lack of documentation makes trying to find the correct usage very, very hard (at least for me).

So I wanted to ask some questions to the more experienced users here:

I need to speed up actions for existing objects, in this case I would like to create a contour of certain size and then check if it overlaps with other objects - basically a distance check. What I am currently using is SelectShapesFromRectangle combined with Curve.IntersectsWith. So first we roughly check if our shapes rectangle overlaps with other shapes (by removing the initial shape from the selected range and then comparing shape counts) and then use IntersectsWith command to see if those shapes actually overlap.

If they do, then I would move our shape or the other shape away a certain distance and then check again until that is no longer the case.

Ideally it would be possible to have all these shapes (or their Separated contours) on a virtual layer doing all that intersection checking and movement and then just replace the contours with the real shapes (for example I would name the contours with the parent shapes StaticID or something similar).

I know this is a little long and complex, but can anyone help with understanding what is and what isn't possible for such a task using virtual shapes or layers?

Parents
No Data
Reply
  • What about moving the shape for it's two or three sizes away so that the shapes knowingly do not intersect. Then find the closest distance between two shapes and move the shape back for this distance. So you'll do two shape moves instead of many. You can try to do it with virtual shapes for speeding up.

    You can try to use Curve.GetPolyline instead of initial Curve in IntersectsWith. I have the feeling that it can be faster, but I didn't do real tests.

    Dim d#, xx1#, xx2#, yy1#, yy2#
    Sub dist()
    Dim s1 As Shape, s2 As Shape
    If ActiveSelection.Shapes.Count <> 2 Then MsgBox "Select two curves": Exit Sub
    Set s1 = ActiveSelection.Shapes(1)
    Set s2 = ActiveSelection.Shapes(2)
    Dim sg1 As Segment, sg2 As Segment

    d = 1000000

    For Each sg1 In s1.DisplayCurve.Segments
    For Each sg2 In s2.DisplayCurve.Segments
    MinDist sg1, sg2
    Next sg2
    Next sg1
    ActiveLayer.CreateLineSegment xx1, yy1, xx2, yy2
    End Sub

    Sub MinDist(sg1 As Segment, sg2 As Segment)
    For t# = 0 To 1 Step 0.02
    sg1.GetPointPositionAt x1#, y1#, t
    sg2.FindClosestPoint x1#, y1#, tt#
    sg2.GetPointPositionAt x2#, y2#, tt
    dd = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)
    If dd < d Then
    d = dd
    xx1 = x1
    xx2 = x2
    yy1 = y1
    yy2 = y2
    End If
    DoEvents
    Next t
    End Sub

Children