Code:
Sub Main CreateShrinkwrapSubstitute()
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition
' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, "C:\Users\", False)
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(oDoc.FullDocumentName)
' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = kDeriveAsSingleBodyNoSeams
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedIncludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll
oDerivedAssemblyDef.ReducedMemoryMode = True
'Call oDerivedAssemblyDef.SetHolePatchingOptions(kDerivedPatchAll)
'Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(kDerivedRemovePartsAndFaces, 25)
' Create the shrinkwrap component
Dim oDerivedAssembly As DerivedAssemblyComponent
oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
oDerivedAssembly.BreakLinkToFile
' Get the PropertySets object.
Dim oPropSets As PropertySets
oPropSets = oDoc.PropertySets
' Get the design tracking property set.
Dim oPropSet As PropertySet
oPropSet = oPropSets.Item("Design Tracking Properties")
' Get the part number iProperty.
oPartNumiProp = oPropSet.Item("Part Number")
' Save the part
Dim strSubstituteFileName As String
strSubstituteFileName = f & oPartNumiProp.Value & ".ipt"
' strSubstituteFileName = Left$(oDoc.FullFileName, Len(oDoc.FullFileName) - 4)
' strSubstituteFileName = strSubstituteFileName & "_ShrinkwrapSubstitute.ipt"
ThisApplication.SilentOperation = True
Call oPartDoc.SaveAs(strSubstituteFileName, False)
ThisApplication.SilentOperation = False
' ' Create a substitute level of detail using the shrinkwrap part.
' Dim oSubstituteLOD As LevelOfDetailRepresentation
' Set oSubstituteLOD = oDef.RepresentationsManager.LevelOfDetailRepresentations.AddSubstitute(strSubstituteFileName)
' Release reference of the invisibly opened part document.
oPartDoc.ReleaseReference
End Sub