Hi Guys,
I have an assembly which has Hole feature,my aim is to get 2d cordinates and transform it to 3d cordinates which I can use to
make referance point.I have used following macro but when I am trying to make point its creating point at differance location which is not similar to sketch
point of hole.
Please anyone help me !!!!
Help is appreciated.
'------------------------------------------------------------------
'
' Preconditions:
' (1) Part, assembly or drawing is open.
' (2) If a part or assembly, then a sketch is being edited.
' (3) If a part or assembly, then an entity is selected in
' the sketch.
' (4) If a drawing, then an entity is selected.
'
' Postconditions: None
'
' NOTES:
' (1) If the sketch is a 3D sketch, then the selected sketch
' point is automatically in model coordinates.
' (2) If the sketch is a 3D sketch, then its transform is the
' unit transform.
'
'------------------------------------------------------------------
Option Explicit
Public Function GetModelCoordinates _
( _
swApp As SldWorks.SldWorks, _
swSketch As SldWorks.sketch, _
vPtArr As Variant _
) As Variant
Dim swMathPt As SldWorks.MathPoint
Dim swMathUtil As SldWorks.MathUtility
Dim swMathTrans As SldWorks.MathTransform
Set swMathUtil = swApp.GetMathUtility
Set swMathPt = swMathUtil.CreatePoint(vPtArr)
' Is a unit transform if 3D sketch; for example, selected sketch
' point is automatically in model space
Set swMathTrans = swSketch.ModelToSketchTransform
Set swMathTrans = swMathTrans.Inverse
Set swMathPt = swMathPt.MultiplyTransform(swMathTrans)
GetModelCoordinates = swMathPt.ArrayData
End Function
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSketch As SldWorks.sketch
Dim vSketchSelPt As Variant
Dim vModelSelPt As Variant
Dim i As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swSketch = swModel.GetActiveSketch2
vSketchSelPt = swSelMgr.GetSelectionPointInSketchSpace(1)
vModelSelPt = GetModelCoordinates(swApp, swSketch, vSketchSelPt)
Debug.Print "File = " & swModel.GetPathName
Debug.Print " Is3D sketch = " & swSketch.Is3D
Debug.Print " SelPt (sketch space) = (" & vSketchSelPt(0) * 1000# & ", " & vSketchSelPt(1) * 1000# & ", " & vSketchSelPt(2) * 1000# & ") mm"
Debug.Print " SelPt (model space) = (" & vModelSelPt(0) * 1000# & ", " & vModelSelPt(1) * 1000# & ", " & vModelSelPt(2) * 1000# & ") mm"
End Sub
'------------------------------------------
Regards
Sameer Deshmukh.
SolidworksApi macros