is there a simple way or function to get the end line of selected line, from drawing view, am looking to shorten a process of tag-ing select items in a drawing view,
is there a simple way or function to get the end line of selected line, from drawing view, am looking to shorten a process of tag-ing select items in a drawing view,
Hello
Try this with 1 or more selected edges
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim SelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swEdge As SldWorks.Edge
Dim swVertex As SldWorks.Vertex
Dim swPt1 As Variant, swPt2 As Variant, swPt3 As Variant, swPt4 As Variant
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
Set swView = swDraw.ActiveDrawingView
Set SelMgr = swDraw.SelectionManager
For i = 1 To SelMgr.GetSelectedObjectCount
If SelMgr.GetSelectedObjectType3(i, -1) = swSelectType_e.swSelEDGES Then
Set swEdge = SelMgr.GetSelectedObject6(i, 0)
Debug.Print "start point:"
Set swVertex = swEdge.GetStartVertex
swPt1 = swVertex.GetPoint
swPt2 = CoordinateInDrawingView(swPt1, swView)
Debug.Print "end point:"
Set swVertex = swEdge.GetEndVertex
swPt3 = swVertex.GetPoint
swPt4 = CoordinateInDrawingView(swPt3, swView)
Debug.Print "mid point:"
Debug.Print " Model coordinates: " & (swPt1(0) + swPt3(0)) / 2 * 1000 & " " & (swPt1(1) + swPt3(1)) / 2 * 1000 & " " & (swPt1(2) + swPt3(2)) / 2 * 1000
Debug.Print " Drawing coordinates: " & (swPt2(0) + swPt4(0)) / 2 * 1000 & " " & (swPt2(1) + swPt4(1)) / 2 * 1000 & " " & (swPt2(2) + swPt4(2)) / 2 * 1000
End If
Debug.Print
Next
End Sub
Function CoordinateInDrawingView(ByVal subPoint As Variant, ByVal subView As SldWorks.View) As Variant
Dim swMathUtils As SldWorks.MathUtility
Dim swXform As SldWorks.MathTransform
Dim swMathPt As SldWorks.MathPoint
Set swMathUtils = swApp.GetMathUtility
Set swXform = subView.ModelToViewTransform
Debug.Print " Model coordinates: " & subPoint(0) * 1000 & " " & subPoint(1) * 1000 & " " & subPoint(2) * 1000
' transform absolute coordinate to view coordinate
Set swMathPt = swMathUtils.CreatePoint(subPoint)
Set swMathPt = swMathPt.MultiplyTransform(swXform)
subPoint = swMathPt.ArrayData
Debug.Print " Drawing coordinates: " & subPoint(0) * 1000 & " " & subPoint(1) * 1000 & " " & subPoint(2) * 1000
CoordinateInDrawingView = subPoint
End Function
Hello
Try this with 1 or more selected edges
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim SelMgr As SldWorks.SelectionMgr
Dim swView As SldWorks.View
Dim swEdge As SldWorks.Edge
Dim swVertex As SldWorks.Vertex
Dim swPt1 As Variant, swPt2 As Variant, swPt3 As Variant, swPt4 As Variant
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
Set swView = swDraw.ActiveDrawingView
Set SelMgr = swDraw.SelectionManager
For i = 1 To SelMgr.GetSelectedObjectCount
If SelMgr.GetSelectedObjectType3(i, -1) = swSelectType_e.swSelEDGES Then
Set swEdge = SelMgr.GetSelectedObject6(i, 0)
Debug.Print "start point:"
Set swVertex = swEdge.GetStartVertex
swPt1 = swVertex.GetPoint
swPt2 = CoordinateInDrawingView(swPt1, swView)
Debug.Print "end point:"
Set swVertex = swEdge.GetEndVertex
swPt3 = swVertex.GetPoint
swPt4 = CoordinateInDrawingView(swPt3, swView)
Debug.Print "mid point:"
Debug.Print " Model coordinates: " & (swPt1(0) + swPt3(0)) / 2 * 1000 & " " & (swPt1(1) + swPt3(1)) / 2 * 1000 & " " & (swPt1(2) + swPt3(2)) / 2 * 1000
Debug.Print " Drawing coordinates: " & (swPt2(0) + swPt4(0)) / 2 * 1000 & " " & (swPt2(1) + swPt4(1)) / 2 * 1000 & " " & (swPt2(2) + swPt4(2)) / 2 * 1000
End If
Debug.Print
Next
End Sub
Function CoordinateInDrawingView(ByVal subPoint As Variant, ByVal subView As SldWorks.View) As Variant
Dim swMathUtils As SldWorks.MathUtility
Dim swXform As SldWorks.MathTransform
Dim swMathPt As SldWorks.MathPoint
Set swMathUtils = swApp.GetMathUtility
Set swXform = subView.ModelToViewTransform
Debug.Print " Model coordinates: " & subPoint(0) * 1000 & " " & subPoint(1) * 1000 & " " & subPoint(2) * 1000
' transform absolute coordinate to view coordinate
Set swMathPt = swMathUtils.CreatePoint(subPoint)
Set swMathPt = swMathPt.MultiplyTransform(swXform)
subPoint = swMathPt.ArrayData
Debug.Print " Drawing coordinates: " & subPoint(0) * 1000 & " " & subPoint(1) * 1000 & " " & subPoint(2) * 1000
CoordinateInDrawingView = subPoint
End Function