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.
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As part
Set part1 = partDocument1.part
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim angle1 As Angle
Set angle1 = parameters1.CreateDimension("", "ANGLE", 0)
Dim relations1 As Relations
Set relations1 = part1.Relations
Dim formula1 As Formula
Set formula1 = relations1.CreateFormula("Formula.1", "", angle1, "angle(Final_Part\Line.1 ,Final_Part\Line.2 ) ")
formula1.Rename "Formula.1
part1.Update
End Sub
Sub GetLinesAndMeasure()
'Get the selection of the active part (user needs to pre-select 2 lines to measure)
Dim uSel As Selection
Set uSel = CATIA.ActiveDocument.Selection
'Get the active part to be able to make references (what is shown will only work if the part is the open document)
Dim ActivePart As Part
Set ActivePart = CATIA.ActiveDocument.Part
'Create a reference to the first selected line
Dim Line1Ref As Reference
Set Line1Ref = ActivePart.CreateReferenceFromObject(uSel.Item(1).Value)
'Create a reference to the second selected line
Dim Line2Ref As Reference
Set Line2Ref = ActivePart.CreateReferenceFromObject(uSel.Item(2).Value)
'Calculate and output the measured angle between the lines
MsgBox "Angle between lines is: " & AngleMeasure(Line1Ref, Line2Ref) & "°", vbOKOnly, "Angle Measure"
End Sub
Function AngleMeasure(Line1Ref As Reference, Line2Ref As Reference) As Double
'Get the "measurable" workbench
Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")
'Create a measurable of the first line ref
Dim TheMeasurable As Measurable
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(Line1Ref)
'Measure the angle between the measurable and the second line
Dim MeasuredAngle As Double
MeasuredAngle = TheMeasurable.GetAngleBetween(Line2Ref)
'Return the measured angle
AngleMeasure = MeasuredAngle
End Function