By Adam Nagy
You might need to insert lots of instances of the same Content Center part in an assembly - e.g. placing rivets in similar holes on the same part. You could write some code that would help replicate an instance, so that you would only need to insert a single component manually then select the inserted component and all the holes where you would need the same component and the code would insert them and add the constraints.
This sample is just to show the idea and is far from a robust solution which would work in all scenarios. In this case we assume that the rivet has been placed with a single insert constraint and the selected holes are the same size as the original one.
So we already have a rivet placed in the assembly and now we select it and the other holes where we want to place them:
Then we run this VBA code:
Sub InsertSameInstances() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument Dim acd As AssemblyComponentDefinition Set acd = doc.ComponentDefinition ' Instance to copy Dim occ As ComponentOccurrence Set occ = doc.SelectSet(1) ' Store selected faces Dim fs As ObjectCollection Set fs = ThisApplication.TransientObjects.CreateObjectCollection Dim i As Integer For i = 2 To doc.SelectSet.Count Call fs.Add(doc.SelectSet(i)) Next ' Faces of holes that the copies should be placed to Dim h As Face For Each h In fs ' Insert same component Dim tg As TransientGeometry Set tg = ThisApplication.TransientGeometry Dim occNew As ComponentOccurrence Set occNew = acd.Occurrences.AddByComponentDefinition( _ occ.Definition, tg.CreateMatrix()) ' Check original component's constraints Dim c As AssemblyConstraint For Each c In occ.Constraints If TypeOf c Is InsertConstraint Then Dim ic As InsertConstraint Set ic = c ' Get native edge Dim e As Edge Set e = c.EntityOne.NativeObject ' Get its equivalent in the new occurrence Dim ep As EdgeProxy Call occNew.CreateGeometryProxy(e, ep) ' Get hole's edge Dim eh As Edge Set eh = h.Edges(1) Call acd.Constraints.AddInsertConstraint( _ ep, eh, ic.AxesOpposed, ic.Distance.value) End If Next Next End Sub
And get this:
I think based on this someone could create a nice Inventor App Store plugin - hint, hint ;)