iLogic Shrinkwrap Substitute causes error for only some files

iLogic Shrinkwrap Substitute causes error for only some files

kalantarikavian
Explorer Explorer
530 Views
4 Replies
Message 1 of 5

iLogic Shrinkwrap Substitute causes error for only some files

kalantarikavian
Explorer
Explorer

Hello all,

 

This is my first time posting anything to the forums, so please be gentle (coder noob)! I'm running into a weird issue when it comes to creating a Shrinkwrap Substitute in iLogic. Basing my code pretty much exactly from VBA help (no funny business or anything):

 

    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 = 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)

    ' Save the part
    Dim strSubstituteFileName As String
    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
    oSubstituteLOD = oDef.RepresentationsManager.LevelOfDetailRepresentations.AddSubstitute(strSubstituteFileName)

    ' Release reference of the invisibly opened part document.
    oPartDoc.ReleaseReference

 This code works fine and dandy for about 90% of the files I'm working with. But for some reason, I am getting an error on certain files. 

 

Error shown when creating shrinkwrap sub manually:

kalantarikavian_0-1628629617565.png

 

Error shown when creating shrinkwrap sub through iLogic:

kalantarikavian_1-1628629839789.png

kalantarikavian_2-1628629854553.png

 

Now when doing this Shrinkwrap manually, I can simply hit the handy dandy "accept" button and continue working with my file....is there a way I could do this in iLogic as well?

 

Not sure if this is allowed or not but here's the link to one of the .stp files I'm using that is causing the issue.

https://drive.google.com/file/d/1zziK5iAzys2I0R4eZQJsaJ50WODc3zcA/view?usp=sharing

Using Inventor Professional 2021 on Win10.

 

Thanks in advance!

 

0 Likes
531 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor

Does this help:

bradeneuropeArthur_0-1628799323800.png

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 5

bradeneuropeArthur
Mentor
Mentor

Modified a little:

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 = kDeriveAsSingleBodyNoSeams
    oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedIncludeAll
    oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll
    oDerivedAssemblyDef.ReducedMemoryMode = True
	oDerivedAssemblyDef.IndependentSolidsOnFailedBoolean = True
	
    Call oDerivedAssemblyDef.SetHolePatchingOptions(kDerivedPatchAll)
    Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(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)
	
	Dim fio As New System.IO.FileInfo(strSubstituteFileName & "_ShrinkwrapSubstitute.ipt")
	If fio.Exists = False
    strSubstituteFileName = strSubstituteFileName & "_ShrinkwrapSubstitute.ipt"
Else 
	MsgBox("File Exist")
	
End If

    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

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 5

bradeneuropeArthur
Mentor
Mentor

And a check it the Model State is not in Substitute State:

 

Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument

If oDoc.ModelStateName.Contains("Substitute") Then
	MsgBox ("Model state is Substitute")
	Exit Sub
End If
    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 = kDeriveAsSingleBodyNoSeams
    oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = kDerivedIncludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelSketches = kDerivedIncludeAll
    oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = kDerivedExcludeAll
    oDerivedAssemblyDef.IncludeAllTopLevelParameters = kDerivedExcludeAll
    oDerivedAssemblyDef.ReducedMemoryMode = True
	oDerivedAssemblyDef.IndependentSolidsOnFailedBoolean = True
	
    Call oDerivedAssemblyDef.SetHolePatchingOptions(kDerivedPatchAll)
    Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(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)
	
	Dim fio As New System.IO.FileInfo(strSubstituteFileName & "_ShrinkwrapSubstitute.ipt")
	If fio.Exists = False
    strSubstituteFileName = strSubstituteFileName & "_ShrinkwrapSubstitute.ipt"
Else 
	MsgBox("File Exist")
	
End If

    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

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 5

kalantarikavian
Explorer
Explorer

Tried all 3 things you suggested. First two didn't work and had same error as before, 3rd one resulted in an error regarding ModelStateName.

kalantarikavian_0-1628862939441.png

Still very confused why "ThisApplication.SilentOperation = True" doesn't manage to suppress the error coming from the Shrinkwrap (because when running it manually you can simply accept it and everything is fine)

 

Thank you @bradeneuropeArthur for your help in trying to diagnose this issue....confused as to why no one else has run into this before me

0 Likes