bigkadz
Automotive
- Apr 3, 2006
- 4
I was wondering if it is possible for Solidworks to give you an IJK vector, I haven't been able to find any info on this matter, perhaps there is a macro made or something. Help would be much appreciated!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Option Explicit
Sub Main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swVertex1 As SldWorks.Vertex
Dim swVertex2 As SldWorks.Vertex
Dim DataObj As New DataObject
Dim vPt1 As Variant
Dim vPt2 As Variant
Dim PointDist As Double
Dim i As Double
Dim j As Double
Dim k As Double
Dim Msg As String
Dim LongStatus As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If Not (swSelMgr.GetSelectedObjectCount = 2) Then
Msg = "Select two vertices to calculate the IJK vectors"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
End If
Set swVertex1 = swSelMgr.GetSelectedObject6(1, -1)
vPt1 = swVertex1.GetPoint
Set swVertex2 = swSelMgr.GetSelectedObject6(2, -1)
vPt2 = swVertex2.GetPoint
PointDist = Sqr((vPt2(0) - vPt1(0)) ^ 2 + (vPt2(1) - vPt1(1)) ^ 2 + (vPt2(2) - vPt1(2)) ^ 2)
Msg = "i = " & (vPt2(0) - vPt1(0)) / PointDist & Chr(13)
Msg = Msg & "j = " & (vPt2(1) - vPt1(1)) / PointDist & Chr(13)
Msg = Msg & "k = " & (vPt2(2) - vPt1(2)) / PointDist
DataObj.SetText Msg
DataObj.PutInClipboard
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End Sub