As the title says, does anyone know how to do this?
What's I'm doing is creating a "duplicate part with constraints" macro that will allow me to reinsert a select set with all of the constraints the previous selection set had, but constrained to the references in the duplicated copy.
In order to do this, I need to recreate all of the constraints that the original select set had, but with the references to the new parts. Which leads me to iterating through the constraints and finding the occurrences that are in both the new/old lists. The problem is using the constraint entity/geometry/occurrence info and grabbing that same information, except from the newly placed occurrence.
Any help would be appreciated!
Thanks,
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Solved by bshbsh. Go to Solution.
I've done something similar but with "sick" constraints, where some entities were lost due to component replaces. But it's not very different, some ideas:
Let's say your original constraint between the two original occurrences is called AC1 (AssemblyConstraint1), and you want to create AC2 between the two new occurrences (NewOcc1, NewOcc2).
You can get both entities from AC1, then create a geometry proxy of the entities' nativeobjects within the new occurrences. You have to make absolutely sure that AC1.OccurrenceOne (with EntityOne) is the same as your NewOcc1 and not swapped (or other occurrences), otherwise you'll get an error. (Same for NewOcc2).
Public Sub dupeconstraintexample() Dim AC1 As AssemblyConstraint Dim NewOcc1 As ComponentOccurrence Dim NewOcc2 As ComponentOccurrence Dim E1Proxy As Object Dim E2Proxy As Object Set AC1 = ThisApplication.ActiveDocument.ComponentDefinition.Constraints.Item(1) 'Insert between Occurrences.Item(1) and Item(2) Set NewOcc1 = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(3) 'copy of Item(1) Set NewOcc2 = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences.Item(4) 'copy of Item(2) Call NewOcc1.CreateGeometryProxy(GetProxy(AC1.EntityOne, NewOcc1), E1Proxy) Call NewOcc2.CreateGeometryProxy(GetProxy(AC1.EntityTwo, NewOcc2), E2Proxy) Call ThisApplication.ActiveDocument.ComponentDefinition.Constraints.AddInsertConstraint(E1Proxy, E2Proxy, AC1.AxesOpposed, AC1.Distance.Value) End Sub Private Function GetProxy(ByRef Prxy As Object, ByRef ContOcc As ComponentOccurrence) As Object If Prxy.ContainingOccurrence.Type = kComponentOccurrenceObject Then Set Occ = ContOcc Else Set Occ = ContOcc.Definition.Occurrences.ItemByName(Prxy.ContainingOccurrence.Name) End If Call Occ.CreateGeometryProxy(Prxy.NativeObject, GetProxy) End Function
Worked beautifully!
Thanks a bunch!
I lied. I can't quite get this working.
What I'm having issues with is that the the proxy I'm trying to get in my newOcc is actually a proxy within old Occ.
ie;
OldOcc
- OldOccChild
- - Item I want to use.
In this case, it is a circular curve on a PART within the ASSEMBLY that I have copied as my main occurrence, of whose constraints I would like to duplicate.
I think I figured it out now!
Had to add in a recursive call to the function in order to be able to grab a proxy within that proxy so I could use my proxy as a proxy.