Is there anyway to measure the IJK vector value for an axis. Our customer would like to see the output for co-ordinates of contact in XYZ and IJK. Please advise.
SolidworksApi macros
Is there anyway to measure the IJK vector value for an axis. Our customer would like to see the output for co-ordinates of contact in XYZ and IJK. Please advise.
SolidworksApi macros
Perhaps if you took about five minutes to better explain your problem and maybe even outlined some of what you have tried then someone might venture to help. Lots of people (especially in the API area where your post is) will post a short question like this, and the answer is beyond their understanding of programming in general, not to mention Solidworks and its API. I'm not saying that you are or aren't in that camp. Your post just doesn't really tell me what you need. You might just need a nudge in the right direction with the correct API function, (which I could do) or you may need someone to write a complete macro for you (which I could also do, but I don't have the time). Nobody is being paid to be here (except possibly Richard and Jim).
Thanks for your response. I wasn't actually looking for anyone to have to do any work for this. In Keycreator, I simply pick the measure IJK button that is standard in the software. I can do the same in Rhino3D, and in Igestoolbox. I was just asking for someone to tell me where that button is in Solidworks?
IJK vectors are the cosine values of the X, Y, and Z angles. they provide you with the direction of your vector. So as an example, a digital indicator would hit a customers part at a certain XYZ co-ordinate, and along a certain vector. I can output the XYZ of the co-ordinate, however, I cannot find where the output of the IJK values of the vector is in solidworks.
I posted this in General questions before posting it here. Hope this explains a little better what feature I am looking for. Thanks for any help you can provide.
Mark
Mark-
This can be done through the api using the refaxis interface. This gives you the start and end points of the axis. This can be converted into a unit vector using the mathvector interface.
I sure can't find anything either in the regular user interface short of measuring between the axis and the three reference planes in turn.
-Jason S.
I found this on another forum. It was an old post from 2006 by a person names Stoker. I have no knowledge when it comes to the Solidworks Api. I have tried this script, but found that it does nothing. Is there anyone that can take a look at this and let me know what needs to change in order to have it function in Solidworks 2011.
Thanks very much.
Mark
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
Mark,
If you are trying to measure it by using SW commands then I have no solution for you. The simpler method which I can think of is by using API.
By using API, you can compute the mathvector object. The MathVector object can be normalised (by using MathVector::Normalise) to get a unit vector along that direction. The co-efficients of x, y and z of this unit vector are the direction cosines you are looking for.
The macro (which you have attached) also calculates the unit vector but you can use Normalise to compute it directly.
Hope it helps!!!
Rajat Jain
Thanks for your help, however, the macro I have attached does not work. I have no idea how to get it to work in Solidworks 2011. I am interested in your version, could you please take a look at the macro I have posted, and let me know what I would need to do to modify it so that it would actually work please?
Thanks
Mark
So, again, what do you want? Do you want to insert a reference axis and get its IJK values, or do you want to pick a point and a face and have SW tell you XYZ of the point and the normal vector to the surface? Either is possible through API. Unfortunately, neither is possible with built-in functionality. Also unfortunately I don't have time to write that macro, although I think it would be a fun one.
This is one I wrote some time ago that will allow you to select a face and run the macro. It will report ijk of the normal vector at your selection point.
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swFace As SldWorks.Face2
Dim swSurf As SldWorks.Surface
Dim swSelMgr As SldWorks.SelectionMgr
Dim SelPt As Variant
Dim FacePt As Variant
Dim SurfEval As Variant
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSelMgr = swDoc.SelectionManager
If swSelMgr.GetSelectedObjectType3(1, -1) <> swSelFACES Then
MsgBox "You must select a face."
Exit Sub
End If
Set swFace = swSelMgr.GetSelectedObject6(1, -1)
Set swSurf = swFace.GetSurface
SelPt = swSelMgr.GetSelectionPoint2(1, -1)
FacePt = swFace.GetClosestPointOn(SelPt(0), SelPt(1), SelPt(2))
'FacePt = swFace.GetClosestPointOn(0, 0, 0)
SurfEval = swSurf.EvaluateAtPoint(FacePt(0), FacePt(1), FacePt(2))
Debug.Print "[" & SurfEval(0) & " " & SurfEval(1) & " " & SurfEval(2) & "]"
MsgBox "i: " & SurfEval(0) & vbCrLf & "j: " & SurfEval(1) & vbCrLf & "k: " & SurfEval(2)
Set swSurf = Nothing
Set swFace = Nothing
Set swSelMgr = Nothing
Set swDoc = Nothing
Set swApp = Nothing
End Sub
Mark,
I have attached a part containing 1 ref axis. Open this part and run the attached macro.
The macro shall select the part and show you the ijk values.
Hope this helps!!!
Rajat Jain
Outstanding guys. The macros both of you have provided will suit my application perfectly. Thanks so much for your help. I really appreciate it!
Mark
Hello,
It's a old discussion but I try to find a resolution of my problem.
I'm a new user.
In Solid Works CAD I have a part with a lot of holes (300-600). I can trace in SW the axis of whole holes. I'd like to export in Excel file the angles or cosines (i,j,k) of all axis. It is possible?
I've found this macro in other discussion, but it doesn't work. When I run it a warning message appears, it says (I try to translate): "Compilation error: type defined by user is not defined".
Sub Main()
On Error Resume Next
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swMathUtil As SldWorks.MathUtility
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSketchLine As SldWorks.SketchLine
Dim oMyLine As Object
Dim oMathVector As SldWorks.MathVector
Dim oUnitVector As SldWorks.MathVector
Dim vPt1 As Variant
Dim vPt2 As Variant
Dim dArr(2) As Double
Dim i As Long
Dim dArrUnit As Variant
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim swStartPt As SldWorks.SketchPoint
Dim swEndPt As SldWorks.SketchPoint
Set swApp = Application.SldWorks
If Not swApp Is Nothing Then
Set swModel = swApp.ActiveDoc
Set swMathUtil = swApp.GetMathUtility
If Not swModel Is Nothing And Not swMathUtil Is Nothing Then
Set swSelMgr = swModel.SelectionManager
Set swSketchLine = swSelMgr.GetSelectedObject6(1, -1)
If Not swSketchLine Is Nothing Then
Set swEndPt = swSketchLine.GetEndPoint2
Set swStartPt = swSketchLine.GetStartPoint2
dArr(0) = swEndPt.X
dArr(1) = swEndPt.Y
dArr(2) = swEndPt.Z
vPt2 = dArr
dArr(0) = swStartPt.X
dArr(1) = swStartPt.Y
dArr(2) = swStartPt.Z
vPt1 = dArr
dArr(0) = vPt2(0) - vPt1(0)
dArr(1) = vPt2(1) - vPt1(1)
dArr(2) = vPt2(2) - vPt2(2)
Set oMathVector = swMathUtil.CreateVector(dArr)
If Not oMathVector Is Nothing Then
Set oUnitVector = oMathVector.Normalise()
dArrUnit = oUnitVector.ArrayData()
MsgBox ("Line vector is " & dArr(0) & "i + " & dArr(1) & "j + " & dArr(2) & "k" & vbCrLf & "Unit vector is " & dArrUnit(0) & "i + " & dArrUnit(1) & "j + " & dArrUnit(2) & "k")
Set oUnitVector = Nothing
Set oMathVector = Nothing
End If
Set oMyLine = Nothing
Set swSelMgr = Nothing
End If
Set swSketchLine = Nothing
End If
Set swModel = Nothing
Set swMathUtil = Nothing
End If
'get the results into excel
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWorkbook = xlApp.Workbooks.Add
With xlWorkbook.Worksheets(1)
.Cells(1, 1).Value = "i"
.Cells(1, 2).Value = "j"
.Cells(1, 3).Value = "k"
.Cells(i + 2, 1).Value = dArrUnit(0)
.Cells(i + 2, 2).Value = dArrUnit(1)
.Cells(i + 2, 3).Value = dArrUnit(2)
End With
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub
Please, could you explain me what wrong with this? Or do you know a way to export the coordinates that I need?
Thank you very much