Message 1 of 3
AddInsertConstraint
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
at first i have not so much experience in programming that why here in this case i have no idea. We use from a previous colleagues a script which has the function: in a assembly we have different parts a: tubes b: ubends. the you select a ubend and than the edges of 2 tubes and you get 2 constraints. helpful is that a copy of the ubend is placed.
But now we have to constrain in the same assembly simple tubes too. Which takes by hand a lot time.
maybe somebody has a idea how to get a script which works like the actual but for 1 constraint only (circular to circular) with benefit that we have a loop like in the actual script.
our actual code:
Sub Main()
Dim Uname As String
Uname = "B_"
Dim ConstraintDirection As String
ConstraintDirection = "True"
Dim nx, ny, nz, ox, oy, oz As Double
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
Dim oCommandMgr As CommandManager
oCommandMgr = ThisApplication.CommandManager
Dim oBody As SurfaceBody
1:
oBody = ThisApplication.CommandManager.Pick(kPartBodyFilter, "Pick U-Bend")
If oBody Is Nothing Then
Exit Sub
End If
If Left(oBody.Parent.Name, 2) <> Uname Then
GoTo 1
End If
On Error Resume Next
Dim occ As ComponentOccurrence
occ = oAsmCompDef.Occurrences.ItemByName(oBody.Parent.Name)
If occ.Constraints.Count > 0 Then
'Debug.Print "Constrainted"
GoTo 1
End If
If Err.Number <> 0 Then
Debug.Print(Err.Number, Err.Description)
'Original Code: Debug.Print Err.Number; Err.Description
On Error GoTo 0
' MsgBox "Exit from procedure / ESC.."
Exit Sub
End If
Dim part As PartDocument
part = ThisApplication.Documents.ItemByName(occ.ReferencedDocumentDescriptor.FullDocumentName)
'Debug.Print "Full Document Name: " & part.FullDocumentName & vbCrLf & "Document Name: " & part.DisplayName
Dim oPath As String
oPath = part.FullDocumentName
Dim oTransform As Matrix
oTransform = occ.Transformation
Dim oOrigin As Point
Dim oXAxis As Vector
Dim oYAxis As Vector
Dim oZAxis As Vector
Call oTransform.GetCoordinateSystem(oOrigin, oXAxis, oYAxis, oZAxis)
Dim vZ As Vector
Dim vX As Vector
Dim vY As Vector
vX = oTG.CreateVector(1, 0, 0)
vY = oTG.CreateVector(0, 1, 0)
vZ = oTG.CreateVector(0, 0, 1)
Dim oUOM As Inventor.UnitsOfMeasure
oUOM = oAsmCompDef.Parent.UnitsOfMeasure
nx = oOrigin.X
ny = oOrigin.Y
nz = oOrigin.Z
Do
Call oMatrix.SetTranslation(oTG.CreateVector(nx, ny, nz))
Dim f As Edge
Dim fp As EdgeProxy
Dim oc As ObjectCollection
oc = ThisApplication.TransientObjects.CreateObjectCollection
For Each f In occ.SurfaceBodies.Item(1).ConvexEdges
Call occ.CreateGeometryProxy(f, fp)
oc.Add (fp)
Next
Dim iOcCount As Long
iOcCount = oc.Count
Dim oEdge1 As Edge
Dim oEdge2 As Edge
Dim oEdge3 As Edge
Dim oEdge4 As Edge
oEdge1 = oc(1)
oEdge2 = oc(iOcCount)
oEdge3 = ThisApplication.CommandManager.Pick(kPartEdgeCircularFilter, "Select the Circular Edge 1.")
oEdge4 = ThisApplication.CommandManager.Pick(kPartEdgeCircularFilter, "Select the Circular Edge 2.")
Dim oInsert As InsertConstraint
On Error Resume Next
oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge1, oEdge3, ConstraintDirection, 0)
If Err.Number <> 0 Then
On Error GoTo 0
Exit Sub
End If
On Error Resume Next
oInsert = oAsmCompDef.Constraints.AddInsertConstraint(oEdge2, oEdge4, ConstraintDirection, 0)
If Err.Number <> 0 Then
On Error GoTo 0
Exit Sub
End If
If oInsert.HealthStatus = 11786 Then
If occ.Constraints.Count > 0 Then
occ.Delete
End If
End If
occ = oAsmCompDef.Occurrences.Add(oPath, oMatrix) 'Place part
ThisApplication.ActiveDocument.Rebuild
Loop
End Sub
MR
Autodesk Inventor Professional 2025
Autodesk Vault Professional 2025
Autodesk Inventor Professional 2025
Autodesk Vault Professional 2025