MACRO LIBRARY

Get the normal value in relative to assembly

Free public access. No account or subscription required.

Files

Get the normal value in relative to assembly

Code

'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
'Preconditions: Face is selected in transform_test.SLDASM
'Results: unit normal vector relative to part and assembly is displayed in immediate window
    
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swComp As SldWorks.Component2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim vNormal As Variant
Dim swTransform As SldWorks.MathTransform
Dim swMathUtil As SldWorks.MathUtility
Dim swMathPt As SldWorks.MathPoint
Dim swMathVect As SldWorks.MathVector
Dim vVectData As Variant
    
Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swAssy = swModel
    Set swMathUtil = swApp.GetMathUtility
    
    Set swSelMgr = swModel.SelectionManager
    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
    Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, -1)
    Set swTransform = swComp.Transform2
    vNormal = swFace.Normal
    
    Debug.Print "Unit normal vector relative to part: "
    Debug.Print Round(vNormal(0), 4) & ", " & Round(vNormal(1), 4) & ", " & Round(vNormal(2), 4)
    
    Set swMathPt = swMathUtil.CreatePoint(vNormal)
    Set swMathVect = swMathPt.ConvertToVector
    Set swMathVect = swMathVect.MultiplyTransform(swTransform)
    vVectData = swMathVect.ArrayData
    
    Debug.Print "Unit normal vector relative to assembly: "
    Debug.Print Round(vVectData(0), 4) & ", " & Round(vVectData(1), 4) & ", " & Round(vVectData(2), 4)
End Sub