Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Unable to run rules in parts within a component

865966724
Contributor

Unable to run rules in parts within a component

865966724
Contributor
Contributor

Previously, I sought help and received an answer. Today, I have a new question. I am not good at programming, rules work well in certain aspects. When I put it into a component, it indicates a problem and I don't know how to modify it.😫

Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oSurfaceBody As SurfaceBody = oPartCompDef.SurfaceBodies.Item(1)
Dim YZPlane As WorkPlane = oPartCompDef.WorkPlanes.Item("YZ Plane")

For Each oFace As Face In oSurfaceBody.Faces
    If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
        Dim FaceAngleRadians As Double = oMeasureTools.GetAngle(YZPlane, oFace)
        Dim FaceAngleDegrees As Double = FaceAngleRadians * 180 / Math.PI
        Dim FaceLocation As String
        
        If Not EqualWithinTolerance(FaceAngleDegrees, 90, 0.001) Then
            
            If oFace.PointOnFace.X > 0 Then
                FaceLocation = "Right"
				Parameter("R") =Round(FaceAngleDegrees, 2)
            Else
                FaceLocation = "Left"
				Parameter("L") =Round(FaceAngleDegrees, 2)
            End If

        End If
        
    End If
Next
0 Likes
Reply
Accepted solutions (1)
336 Views
3 Replies
Replies (3)

865966724
Contributor
Contributor

 

1.jpg

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Hi @865966724.  I believe this is simply because Lines 2 & 3 are document type specific for a part only, not an assembly.  Try changing those 2 lines like this:

 

Dim oDoc As Document = ThisDoc.Document
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition

Edit:  Actually, the term 'ThisApplication.ActiveDocument' is referencing the main assembly in that situation, instead of the part type component you are editing at the moment.  The equivalent way to reference the document being referenced by a component that you are in 'Edit Mode' for within an assembly would be 'ThisApplication.ActiveEditDocument'.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

865966724
Contributor
Contributor

Thank you very much

0 Likes