Hide Table of Contents

Get Angle Between Plane and Line Example (VBA)

This example shows how to get the angle between a selected plane and a selected sketch line.

 

'-----------------------------------------------

'

' Preconditions: Sketch containing a Line1@3DSketch1 exists.

'

' Postconditions: None

'

'-----------------------------------------------

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim boolstatus As Boolean

 

Sub main()

 

Dim swMath As SldWorks.MathUtility

Set swApp = Application.SldWorks

Set swMath = swApp.GetMathUtility

 

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swModelDocExt = swModel.Extension

swModel.ClearSelection2 True

boolstatus = swModelDocExt.SelectByID2("Top Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

boolstatus = swModelDocExt.SelectByID2("Line1@3DSketch1", "EXTSKETCHSEGMENT", 0.07751735119544, 0.02644237600659, -0.0634797539437, True, 0, Nothing, 0)

 

Dim swFeat As SldWorks.Feature

Dim swSkSeg As SldWorks.SketchSegment

Set swFeat = swSelMgr.GetSelectedObject6(1, 0)

Set swSkSeg = swSelMgr.GetSelectedObject6(2, 0)

 

Dim swRefPlane As SldWorks.RefPlane

Set swRefPlane = swFeat.GetSpecificFeature2

 

Dim normVec As MathVector

Dim dirArr(2) As Double

Dim params As Variant

 

dirArr(0) = 0#

dirArr(1) = 0#

dirArr(2) = 1#

Set normVec = swMath.CreateVector((dirArr))

Set normVec = normVec.MultiplyTransform(swRefPlane.Transform)

Debug.Print normVec.ArrayData(0), normVec.ArrayData(1), normVec.ArrayData(2)

 

Dim curveVec As SldWorks.MathVector

Dim swCurve As SldWorks.Curve

Set swCurve = swSkSeg.GetCurve

params = swCurve.LineParams

dirArr(0) = params(3)

dirArr(1) = params(4)

dirArr(2) = params(5)

Set curveVec = swMath.CreateVector((dirArr))

Debug.Print curveVec.ArrayData(0), curveVec.ArrayData(1), curveVec.ArrayData(2)

 

Dim crossVec As SldWorks.MathVector

Set crossVec = curveVec.Cross(normVec)

 

Dim dot As Double

Dim vecLen As Double

Dim angle As Double

dot = curveVec.dot(normVec)

vecLen = crossVec.GetLength()

angle = Atn(dot / vecLen)

Debug.Print angle

 

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Angle Between Plane and Line Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.