Help! Why ShapeRange.Group returns "Nothing"?

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:

  1. Sub DrwCtrlPntLines()
  2. 'Draw lines in place of controlpoints arrows
  3. Dim OSel As ShapeRange
  4. Dim sr As ShapeRange
  5. Dim s As Shape
  6. Dim nr As New NodeRange
  7. Dim n As node
  8. Dim sp As SubPath
  9. Dim crv As Curve
  10. Set OSel = ActiveSelectionRange
  11. 'collect selected nodes
  12. For Each s In OSel
  13.   If (s.Type = cdrCurveShape) And (s.Curve.Selection.Count > 0) Then nr.AddRange s.Curve.Selection
  14. Next
  15. 'if nodes not selected - set begining and ending nodes
  16. If nr.Count = 0 Then
  17.   For Each s In OSel 'look in each shapes
  18.     If s.Type = cdrCurveShape Then 'of curve
  19.       For Each sp In s.Curve.SubPaths 'in it's each subpath
  20.         nr.Add sp.StartNode 'for one of the ending nodes
  21.         nr.Add sp.EndNode 'and collect it
  22.       Next sp
  23.     End If
  24.   Next s
  25. End If
  26. 'draw control point lines at collected nodes
  27. Set sr = New ShapeRange
  28. sr.RemoveAll
  29. For Each n In nr
  30.   Set s = ActiveLayer.CreateCurveSegment(n.PositionX, n.PositionY, _
  31.   n.Segment.EndingControlPointX, n.Segment.EndingControlPointY)
  32.   sr.Add s
  33. Next n
  34. Dim sg As Shape
  35. Set sg = sr.Group 'sg becomes Nothing when nodes was selected
  36. If Not sg Is Nothing Then sg.CreateSelection
  37. End Sub

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.