Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
chandra.shekar.g
in reply to: Anonymous

@Anonymous,

 

Try below iLogic code.

Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oAxis1 As WorkAxis
Dim oAxis2 As WorkAxis
Dim oproxyAxis2 As WorkAxisProxy
Dim oAConstraint As AngleConstraint
Dim comps As New List(Of ComponentOccurrence)
For Each comp As ComponentOccurrence In oAsm.ComponentDefinition.Occurrences
oFilename = comp.Definition.Document.displayname
If InStr(oFilename, "VLV_MAN") <> 0 Or InStr(oFilename, "VLV_HYD") <> 0 Then
comps.Add(comp)
End If
Next
' If there are selected components we can do something
For Each comp In comps
On Error Resume Next

	Dim oAngle As Boolean
    oAngle = False
    
    Dim oConstraint As AssemblyConstraint
    For Each oConstraint In comp.Constraints
        If oConstraint.Type = kAngleConstraintObject Then
            oAngle = True
        End If
    Next
    
    If oAngle = False Then
        oAxis1 = oAsmCompDef.WorkAxes.Item ("Y Axis")
		oAxis2 = comp.Definition.WorkAxes("Y Axis")
		comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
		oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
		'78594 refers to the undirected angle constraint solution type. 78593 refers to
		'directed (which is default), and 78595 is the referenced vector solution

		If oAConstraint.HealthStatus = oAConstraint.HealthStatus.kInconsistentHealth Then
			oAConstraint.Delete
			oAxis1 = oAsmCompDef.WorkAxes.Item("Z Axis")
			oAxis2 = comp.Definition.WorkAxes("Y Axis")
			comp.CreateGeometryProxy(oAxis2, oproxyAxis2)
			oAConstraint = oAsmCompDef.Constraints.AddAngleConstraint(oproxyAxis2, oAxis1, 0, 78593)
			'78594 refers to the undirected angle constraint solution type. 78593 refers to
			'directed (which is default), and 78595 is the referenced vector solution
		End If
    End If

Next

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network