Hello!I have a 2 -point line. It's simple to determine X,Y coordinates of each of two nodes with VBA code.
But how to determine X,Y coordinates of selected node /with Shape tool/?Or how to make VBA code return MsgBox "Coordinates of selected node are: X = " & Snode.positionX & ", Y = " & Snode.positionY"
OrMsgBox "Coordinates of UNselected node are: X = " UNnode.positionX & ", Y = " & UNnode.positionY"
One way to do that is to "walk through" the node range of the selected curve, check each node to see if it is selected, and then add it to a node range if it is.
I already have a function written to do that. Here is a small macro that uses that function, then reports the coordinates of the selected nodes.
Dim noderangeSelected As NodeRange
Dim nodeThis As Node
Set noderangeSelected = get_selected_nodes_from_curve(ActiveShape.Curve)
For Each nodeThis In noderangeSelected
MsgBox "X: " & nodeThis.PositionX & vbCrLf & "Y: " & nodeThis.PositionY
Function get_selected_nodes_from_curve(ByVal Curve As Curve) As NodeRange
Dim nodeThis As Node
Dim noderangeSelected As New NodeRange
On Error GoTo ErrHandler
For Each nodeThis In Curve.Nodes
If nodeThis.Selected Then
Set get_selected_nodes_from_curve = noderangeSelected
MsgBox "Error occurred: " & Err.Description & vbCrLf & vbCrLf & "get_selected_nodes_from_curve"
If there is a more elegant way to find the selected nodes, I would be interested in knowing what it is.
Shape.Curve.Selection returns NodeRange with selected nodes
Thank You!My improved code, thanks to the replies from colleagues above:
Private Sub CommandButton232_Click()On Error GoTo errorh'IS NODE SELECTED AND RETURN COORDINATES X, YMsgBox "Selected nodes = " & ActiveShape.Curve.Selection.CountIf ActiveShape.Curve.Selection.Count = 1 Then'MsgBox ActiveShape.Curve.Selection.FirstNode.AbsoluteIndex
If ActiveDocument.Rulers.HUnits = 1 ThenMsgBox "SELECTED NODE X = " & ActiveShape.Curve.Selection(1).PositionX & Chr(34) _& vbCr & "SELECTED NODE Y = " & ActiveShape.Curve.Selection(1).PositionY & Chr(34) _& vbCr & "Node " & ActiveShape.Curve.Selection.FirstNode.AbsoluteIndex & " selected"End If
If ActiveDocument.Rulers.HUnits = 3 ThenMsgBox "SELECTED NODE X = " & ActiveShape.Curve.Selection(1).PositionX * 25.4 & " mm" _& vbCr & "SELECTED NODE Y = " & ActiveShape.Curve.Selection(1).PositionY * 25.4 & " mm" _& vbCr & "Node " & ActiveShape.Curve.Selection.FirstNode.AbsoluteIndex & " selected"End If
End IfExit Suberrorh:MsgBox "Select node with shape tool"End Sub
shark_ said:Shape.Curve.Selection returns NodeRange with selected nodes
Thank you! I was not aware of the Curve.Selection method.
That is much more convenient than the way I have been doing it.