I used the code to obtain the part angle. Now I have encountered a new problem where the judgment criteria in my code are limited. When my parts are not on either side of the shaft, it seems that I cannot obtain the left and right parts. I am not good at coding and need help😫How to turn the axis into the center of the solid model?This is a solution that I came up with, but I cannot achieve it
'Assume ProfileHeight and ProfileWidth are defined and have values.
Dim isTall As Boolean = Measure.ExtentsLength > Measure.ExtentsWidth
Try
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oDoc As Document = ThisDoc.Document
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oSurfaceBody As SurfaceBody = oCompDef.SurfaceBodies.Item(1)
Dim referencePlane As WorkPlane
If isTall Then
referencePlane = oCompDef.WorkPlanes.Item("YZ Plane")
Else
referencePlane = oCompDef.WorkPlanes.Item("XZ Plane")
End If
For Each oFace As Face In oSurfaceBody.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
Dim FaceAngleRadians As Double = oMeasureTools.GetAngle(referencePlane, oFace)
Dim FaceAngleDegrees As Double = FaceAngleRadians * 180 / Math.PI
Dim FaceLocation As String
If Not EqualWithinTolerance(FaceAngleDegrees, 90, 0.001) Then
If isTall Then
If oFace.PointOnFace.X > 0 Then
FaceLocation = "Right"
Parameter("R") = Round(FaceAngleDegrees, 2)
Else
FaceLocation = "Left"
Parameter("L") = Round(FaceAngleDegrees, 2)
End If
Else
If oFace.PointOnFace.Y > 0 Then
FaceLocation = "Right"
Parameter("R") = Round(FaceAngleDegrees, 2)
Else
FaceLocation = "Left"
Parameter("L") = Round(FaceAngleDegrees, 2)
End If
End If
End If
End If
Next
Catch
End Try