Hi everybody!
I trying to script a macro that will draw lines in place of controlpoints arrows (of Bezier curves). My problem is (see row 37): Why ShapeRange.Group returns "Nothing"? But in other subroutine it working fine... Please help me - where is my error?
Generally I want to draw lines at selected nodes if it was selected... In other case - it must draw lines at starting and ending nodes of each subpaths of selected shapes. After all drawns - lines must be grouped and remain selected.
This is how I try to do it:
Having looked through the help, I found that NodeRange can collect nodes only from a single curve. Also, I discovered that if we'll trying to group something, when ShapeTool (cdrToolNodeEdit) is active - ShapeRanges will be grouped, but as result always will return Nothing. So, before to group ShapeRanges, always you must switch to "Pick Tool" (cdrToolPick). And, if we made some selection with ShapeTool - we need also to clear all selections, before switching to Pick Tool. So, I rewrote my code. And it work fine! Look my post below.
Here is my version. Very similar but I thought I would post as another example.
Sub DrawControlPointLines() Dim s As Shape Dim sr As ShapeRange, srControls As New ShapeRange Dim n As Node, sPath As SubPath Dim nodeX As Double, nodeY As Double Dim controlX As Double, controlY As Double Set sr = ActiveSelectionRange On Error GoTo ErrHandler Optimization = True ActiveDocument.BeginCommandGroup "Draw Control-Point Lines" EventsEnabled = False ActiveDocument.SaveSettings ActiveDocument.PreserveSelection = False For Each s In sr.Shapes If s.Type = cdrCurveShape Then If s.Curve.Selection.Count = 0 Then For Each sPath In s.Curve.SubPaths sPath.Nodes.First.Selected = True Next sPath End If For Each n In s.Curve.Selection nodeX = n.PositionX nodeY = n.PositionY If Not n.PrevSegment Is Nothing Then If n.PrevSegment.Type = cdrCurveSegment Then controlX = n.PrevSegment.EndingControlPointX controlY = n.PrevSegment.EndingControlPointY srControls.Add ActiveLayer.CreateLineSegment(nodeX, nodeY, controlX, controlY) End If End If If Not n.NextSegment Is Nothing Then If n.NextSegment.Type = cdrCurveSegment Then controlX = n.NextSegment.StartingControlPointX controlY = n.NextSegment.StartingControlPointY srControls.Add ActiveLayer.CreateLineSegment(nodeX, nodeY, controlX, controlY) End If End If Next n End If Next s srControls.SetOutlineProperties Width:=0.028, Color:=CreateCMYKColor(0, 100, 100, 0), EndArrow:=ArrowHeads(2) srControls.CreateSelection srControls.Group.CreateSelection ExitSub: ActiveDocument.PreserveSelection = True ActiveDocument.RestoreSettings EventsEnabled = True Optimization = False ActiveWindow.Refresh Application.Refresh ActiveDocument.EndCommandGroup Exit Sub ErrHandler: MsgBox "Error occured: " & Err.Description Resume ExitSub End Sub
Happy Coding,
-Shelby