Community
I have this code, cobbled together from a few other posts. It takes a part in an assy and adds copies that part into each of the parts in a subassy. The parts copy just fine but don't update with the original part despite being associative. If I had only parts in my assy instead of a subassy the associativity updates just fine. Not sure why the surface is called out as assoc. but not updating.
Dim assyDoc As AssemblyDocument Dim assyDef As AssemblyComponentDefinition Dim baseOcc As ComponentOccurrence Public Sub AddObjects() ' Open the existing sample assembly. Set assyDoc = ThisApplication.ActiveDocument Set assyDef = assyDoc.ComponentDefinition Set baseOcc = assyDef.ActiveOccurrence Dim subOcc As ComponentOccurrence ' Get the second occurrence, which will be used as the interference cut tool. Dim coIntTool As ComponentOccurrence Set coIntTool = assyDef.Occurrences.ItemByName("INT:1") ' Get the second occurrence, which will be used as the caution cut tool. Dim coCautTool As ComponentOccurrence Set coCautTool = assyDef.Occurrences.ItemByName("CAUT:1") Set baseOccs = baseOcc.SubOccurrences For Each subOcc In baseOccs Call AssociativeBodyCopy(subOcc, coIntTool) Call AssociativeBodyCopy(subOcc, coCautTool) Next subOcc End Sub Sub AssociativeBodyCopy(coPart As ComponentOccurrence, coCopyObject As ComponentOccurrence) ' Get the component definition of the base part. Dim baseDef As PartComponentDefinition Set baseDef = coPart.Definition '** Create an associative surface base feature in the second part. ' Create a definition object in the context of the first part. Dim baseFeatureDef As NonParametricBaseFeatureDefinition Set baseFeatureDef = baseDef.Features.NonParametricBaseFeatures.CreateDefinition ' Add the body of the second part to the list of items to be copied. Since this ' is getting the body from the occurrence it is actually a SurfaceBodyProxy ' object in the context of the assembly. Dim bodyColl As ObjectCollection Set bodyColl = ThisApplication.TransientObjects.CreateObjectCollection bodyColl.Add (coCopyObject.SurfaceBodies.Item(1)) ' Set up the definition object. When setting the IsAssociative flag to True, the ' Output type must be either a Surface or Composite. A solid is not valid in that case. baseFeatureDef.BRepEntities = bodyColl baseFeatureDef.OutputType = kSurfaceOutputType baseFeatureDef.TargetOccurrence = baseOcc baseFeatureDef.IsAssociative = True ' Create the associative copy. Dim baseFeature As NonParametricBaseFeature Set baseFeature = baseDef.Features.NonParametricBaseFeatures.AddByDefinition(baseFeatureDef) assyDoc.Update Dim ptfeatSculpt As PartFeature Dim ptFeats As PartFeatures Dim ptfeatsSculpt As SculptFeatures Dim sbInt As WorkSurface Dim sbIntSculpt As SculptSurface Set ptFeats = baseDef.Features Set ptfeatsSculpt = ptFeats.SculptFeatures Dim sbIntID As Long sbIntID = baseDef.WorkSurfaces.Count Set sbInt = baseDef.WorkSurfaces.Item(sbIntID) Set sbIntSculpt = baseDef.Features.SculptFeatures.CreateSculptSurface(sbInt) sbIntSculpt.Direction = kSymmetricExtentDirection Dim ocSculpt As ObjectCollection Set ocSculpt = ThisApplication.TransientObjects.CreateObjectCollection Call ocSculpt.Add(sbIntSculpt) Set ptfeatSculpt = ptfeatsSculpt.Add(ocSculpt, kNewBodyOperation) ThisApplication.ActiveView.Update End Sub