'iLogic code by Clint Brown @ClintCadline adapted from the Inventor API samples 'Code originally posted on Cadline Community 'https://www.cadlinecommunity.co.uk/hc/en-us/articles/214383385 Sub Main() On Error Goto 1: 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, , 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 = 80642 '"kDeriveAsSingleBodyNoSeams" oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = 27137 '"kDerivedIncludeAll" oDerivedAssemblyDef.IncludeAllTopLevelSketches = 27137 '"kDerivedIncludeAll" oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = 27138'"kDerivedExcludeAll" oDerivedAssemblyDef.IncludeAllTopLevelParameters = 27138'"kDerivedExcludeAll" oDerivedAssemblyDef.ReducedMemoryMode = True '============================================================================================ 'Hole Patching.... Dim ClintCadline As New ArrayList ClintCadline.add("Do not patch Holes") ClintCadline.add("Patch a Range") ClintCadline.add("Patch All Holes") HolePatcher = InputListBox("Choose from one of the above", ClintCadline, d0, Title := "Cadline iLogic", ListName := "Cadline iLogic: Shrinkwrap Hole Patching Options ") If HolePatcher = "Do not patch Holes" Then HolePatcher = 88321 Else If HolePatcher ="" Then MessageBox.Show("You Must choose a hole patching option", "Cadline iLogic: No Selection made > Exiting Rule") Exit Sub Else If HolePatcher ="Patch a Range" Then HolePatcher = (88323) MinimumPerimeter = InputBox("Minimum Hole Diameter to Patch", "Cadline: iLogic Shrinkwrapper", "0.5") MaximumPerimeter = InputBox("Maximum Hole Diameter to Patch", "Cadline: iLogic Shrinkwrapper", "10") Else If HolePatcher ="Patch All Holes" Then HolePatcher = 88322 End If Call oDerivedAssemblyDef.SetHolePatchingOptions(HolePatcher,MinimumPerimeter, MaximumPerimeter) '============================================================================================ Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(88579,25)'(kDerivedRemovePartsAndFaces, 25) ' Create the shrinkwrap component Dim oDerivedAssembly As DerivedAssemblyComponent oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef) ' Save the part Dim strSubstituteFileName As String strSubstituteFileName = Left$(oDoc.FullFileName, Len(oDoc.FullFileName) - 4) strSubstituteFileName = strSubstituteFileName & "_iLogic_Shrinkwrap.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 oSubstituteLOD = oDef.RepresentationsManager.LevelOfDetailRepresentations.AddSubstitute(strSubstituteFileName) ' Release reference of the invisibly opened part document. oPartDoc.ReleaseReference Exit Sub 1: MessageBox.Show("You must be in an Assembly to run this rule. If you are in an Assembly file, you probably have a substitute level of detail active, switch back to *Master* And try again! ", "Oops! Something went wrong") End Sub