Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy object code creates associative surface that doesn't update.

0 REPLIES 0
Reply
Message 1 of 1
Anonymous
241 Views, 0 Replies

Copy object code creates associative surface that doesn't update.

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

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report