iLogic copy part in assembly with constraints
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to copy a part that is in an assembly and completely constrained and select which constraints I want to leave untouched and which ones I want to redefine. For example say I have a part that is using it's origin planes to constrain to to another part that has planes I've made to constrain to. I want to copy this part but in each of the copies I want to leave the constraints that constrain it in say the X plane and Y plane and I want to choose a new reference to constrain it in the Z axis. Is there a way to retrieve the constraints of the part I want to copy and choose which constraints I want to re-reference them to while leaving the constraint reference of the part I am copying untouched. I have looked at this post https://forums.autodesk.com/t5/inventor-forum/copy-assembly-components-with-constraints/m-p/7401863#... and seen that a Justin K wrote a macro that copies a part along with it's contraints but places it in the same location as the original. This is half the battle I am trying to win as now I want to not only change the location to another plane but also do it multiple times each time changing its location. Here is the VB macro from Justin K .
Private oNewlyInsertedColl As Collection Private oOriginalItemColl As Collection Public Sub DupeSelectionWithConstraints() If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MsgBox ("Rule not valid for non-assembly files!"): Exit Sub Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oSS As SelectSet Set oSS = oDoc.SelectSet If oSS.Count < 1 Then MsgBox ("Rule Requires a Select Set!"): Exit Sub Call DuplicateSS(oDoc, oSS) End Sub Private Sub DuplicateSS(oParentDoc As Document, oSS As SelectSet) Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry Set oPasteMatrix = oTG.CreateMatrix() Set oOriginalItemColl = New Collection Set oNewlyInsertedColl = New Collection For Each oItem In oSS Set oPasteMatrix = oItem.Transformation Set oNewOcc = oParentDoc.ComponentDefinition.Occurrences.Add(oItem.Definition.Document.FullDocumentName, oPasteMatrix) oOriginalItemColl.Add oItem oNewlyInsertedColl.Add oNewOcc Next Dim oTestoOcc1 As Object Dim oTestoOcc2 As Object Dim oOcc1 As ComponentOccurrence Dim oOcc2 As ComponentOccurrence Dim oEntityOne As Object Dim oEntityTwo As Object For Each oConstraint In oParentDoc.ComponentDefinition.Constraints 'Grab entities for new constraint to create Set oTestoOcc1 = GrabObjectFromColl(oOriginalItemColl, oConstraint.OccurrenceOne) Set oTestoOcc2 = GrabObjectFromColl(oOriginalItemColl, oConstraint.OccurrenceTwo) If oTestoOcc1 Is Nothing And oTestoOcc2 Is Nothing Then GoTo NextConstraint If oTestoOcc1 Is Nothing Then Set oEntityOne = oConstraint.EntityOne Else For Each oPossibleOcc In oNewlyInsertedColl If oPossibleOcc.Definition Is oTestoOcc1.Definition Then Set oOcc1 = oPossibleOcc End If Next Call oOcc1.CreateGeometryProxy(GetProxy(oConstraint.EntityOne, oOcc1), oEntityOne) End If If oTestoOcc2 Is Nothing Then Set oEntityTwo = oConstraint.EntityTwo Else For Each oPossibleOcc In oNewlyInsertedColl If oPossibleOcc.Definition Is oTestoOcc2.Definition Then Set oOcc2 = oPossibleOcc End If Next Call oOcc2.CreateGeometryProxy(GetProxy(oConstraint.EntityTwo, oOcc2), oEntityTwo) End If 'End Grab entities 'Check type of constraint Select Case oConstraint.Type Case 100665088 'kAngleConstraintObject 'oParentDoc.Constraints.AddAngleConstraint(EntityOne As Object, ' EntityTwo As Object, ' Angle As Variant, ' [SolutionType] As AngleConstraintSolutionTypeEnum, ' [ReferenceVectorEntity] As Variant, ' [BiasPointOne] As Variant, ' [BiasPointTwo] As Variant ) ' As AngleConstraint Call oParentDoc.ComponentDefinition.Constraints.AddAngleConstraint(oEntityOne, oEntityTwo, oConstraint.Angle, oConstraint.SolutionType, oConstraint.ReferenceVectorEntity) Case 100707840 'kAssemblySymmetryConstraintObject 'oParentDoc.AddSymmetryConstraint( EntityOne As Object, ' EntityTwo As Object, ' SymmetryPlane As Object, ' [EntityOneInferredType] As InferredTypeEnum, ' [EntityTwoInferredType] As InferredTypeEnum, ' [NormalsOpposed] As Boolean ) ' As AssemblySymmetryConstraint Call oParentDoc.ComponentDefinition.Constraints.AddSymmetryConstraint(oEntityOne, oEntityTwo, oConstraint.SymmetryPlane, oConstraint.EntityOneInferredType, oConstraint.EntityTwoInferredType, oConstraint.NormalsOpposed) Case 100666368 'kFlushConstraintObject 'oParentDoc.AddFlushConstraint( EntityOne As Object, ' EntityTwo As Object, ' Offset As Variant, ' [BiasPointOne] As Variant, ' [BiasPointTwo] As Variant ) ' As FlushConstraint Call oParentDoc.ComponentDefinition.Constraints.AddFlushConstraint(oEntityOne, oEntityTwo, oConstraint.Offset.Expression) Case 100665344 'kInsertConstraintObject 'oParentDoc.AddInsertConstraint( EntityOne As Object, ' EntityTwo As Object, ' AxesOpposed As Boolean, ' Distance As Variant, ' [BiasPointOne] As Variant, ' [BiasPointTwo] As Variant ) ' As InsertConstraint Call oParentDoc.ComponentDefinition.Constraints.AddInsertConstraint(oEntityOne, oEntityTwo, oConstraint.AxesOpposed, oConstraint.Distance.Expression) Case 100665856 'kMateConstraintObject 'oParentDoc.AddMateConstraint( EntityOne As Object, ' EntityTwo As Object, ' Offset As Variant, ' [EntityOneInferredType] As InferredTypeEnum, ' [EntityTwoInferredType] As InferredTypeEnum, ' [BiasPointOne] As Variant, ' [BiasPointTwo] As Variant ) ' As MateConstraint Call oParentDoc.ComponentDefinition.Constraints.AddMateConstraint(oEntityOne, oEntityTwo, oConstraint.Offset.Expression, oConstraint.EntityOneInferredType, oConstraint.EntityTwoInferredType) Case 100665600 'kTangentConstraintObject '.AddTangentConstraint( EntityOne As Object, ' EntityTwo As Object, ' InsideTangency As Boolean, ' Offset As Variant, ' [BiasPointOne] As Variant, ' [BiasPointTwo] As Variant ) ' As TangentConstraint Call oParentDoc.ComponentDefinition.Constraints.AddTangentConstraint(oEntityOne, oEntityTwo, oConstraint.InsideTangency, oConstraint.Offset.Expression) End Select NextConstraint: Next 'constraint End Sub Private Function GrabObjectFromColl(ByVal oColl As Collection, ByVal oObj As Object) As Object For Each oItem In oColl If oItem Is oObj Then Set GrabObjectFromColl = oObj Exit Function End If Next Set GrabObjectFromColl = Nothing End Function Private Function GetProxy(ByRef Prxy As Object, ByRef ContOcc As ComponentOccurrence) As Object Dim TempPrxy As Object Dim Occ As Object If Prxy.ContainingOccurrence.Type = kComponentOccurrenceObject Then Set Occ = ContOcc Else On Error Resume Next Set Occ = ContOcc.Definition.Occurrences.ItemByName(Prxy.ContainingOccurrence.Name) If Err.Number <> 0 Then On Error GoTo 0 Set TempPrxy = Prxy.ContainingOccurrence Call ContOcc.CreateGeometryProxy(GetProxy(TempPrxy, ContOcc), Occ) End If End If Call Occ.CreateGeometryProxy(Prxy.NativeObject, GetProxy) End Function
If what I am wanting to do is possible could someone help me figure this out. I know that there has been numerous people asking for a feature like "copy with mates" that Solidworks has and it hasn't been available in Inventor yet but maybe with 2019, which is what I am using, it might be possible.