Create simplified part by API

<?xml encoding=”UTF-8″>by Xiaodong Liang

The [Create Simplified Part] actually creates a derived assembly for the new part document. You will firstly create DerivedAssemblyDefinition, and configure the relevant options, finally add it to the new part by DerivedAssemblyComponents.Add.

6-14-2013 12-05-08 PM

 

6-14-2013 12-06-53 PM

The following is a small code demo. 

<span>Sub CreateSimplifiedPart()</span><br><br><span>' Set a reference to the active assembly document</span><br><span>Dim oDoc As AssemblyDocument</span><br><span>Set oDoc = ThisApplication.ActiveDocument</span><br><br><span>Dim oDef As AssemblyComponentDefinition</span><br><span>Set oDef = oDoc.ComponentDefinition</span><br><br><span>' Create a new part document that will derive the assembly</span><br><span>Dim oPartDoc As PartDocument</span><br><span>Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, , True)</span><br><br><span>Dim oPartDef As PartComponentDefinition</span><br><span>Set oPartDef = oPartDoc.ComponentDefinition</span><br><br><span>Dim oDerivedAssemblyDef As DerivedAssemblyDefinition</span><br><span>Set oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oDoc.FullDocumentName)</span><br><br><span>' Set various related options</span><br><span>oDerivedAssemblyDef.DeriveStyle = kDeriveAsSingleBodyNoSeams</span><br><span>oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll</span><br><span>oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedIncludeAll</span><br><span>oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll</span><br><span>oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll</span><br><span>oDerivedAssemblyDef.ReducedMemoryMode = True</span><br><span>Call oDerivedAssemblyDef.SetHolePatchingOptions(kDerivedPatchAll)</span><br><span>Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(kDerivedRemovePartsAndFaces, 25)</span><br><br><span>' Create the shrinkwrap component</span><br><span>Dim oDerivedAssembly As DerivedAssemblyComponent</span><br><span>Set oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)</span><br><br><span> 'save the new part file</span><br><span>Call oPartDoc.SaveAs("c:tempnewpart.ipt", False)</span><br>  <br><span>End Sub</span><br>

 

 


Comments

One response to “Create simplified part by API”

  1. Xiaodong, not all the code is visible at this website. The end of the lines are cut of. Can you provide the full code?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading