Simplify Using VBA

Simplify Using VBA

kuldeepWDI
Contributor Contributor
853 Views
5 Replies
Message 1 of 6

Simplify Using VBA

kuldeepWDI
Contributor
Contributor

I am trying to Simplify bunch of assemblies we have. I was wondering if anyone has done these using VBA code and would share that or guide me in the right direction, would be much appreciated. FYI I don't have any experience in VBA or any other type of coding language.  

0 Likes
Accepted solutions (1)
854 Views
5 Replies
  • VBA
Replies (5)
Message 2 of 6

W_Barnett
Enthusiast
Enthusiast
Accepted solution

Not super easy to do.  There is no API access to the simplify command as far as I'm aware, however you can Shrinkwrap (if that's acceptable).  By using some of the DerivedAssemblyDefinition methods listed below, you can effectively perform many of the sub-operations you'd find in the simplify command:

      https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=DerivedAssemblyDefinition

 

As for perfoming the actual Shrinkwrap command, this should get you started:

     https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=Shrinkwrap_Sample

 

Once you build out your iLogic code, follow this to batch run it on every assembly you'd like:

     https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/How-to-run-iLogic-...

 

0 Likes
Message 3 of 6

Maxim-CADman77
Advisor
Advisor

"There is no API access to the simplify command"

 

Before recent I was sure 'Simplify' command makes the same as create new IPT and then place 'Derived Component' to it. But I see some difference in icon (BrowserNode of 'Simplified' icon is outlined) and also they give different file-size when exported to Autocad-DWG-3D (again same export settings used) - Simplified is about 30% smaller.

 

Taking this to a count I'd like somebody from Autodesk comment this.

 

Dear @MjDeck maybe you can?

 

PS:
Of course I'm aware I can call the Simplify command window with line

 

 

ThisApplication.CommandManager.ControlDefinitions("AssemblySimplifyCmd").Execute

 

 

 But then if can't just emulate OK-press - I need to control Style, Exclude parts by size and some other options.
Can I force some Preset settings in this scenario?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 6

MjDeck
Autodesk
Autodesk

Hi @Maxim-CADman77 - there are a lot of options in the Simplify command. If you can post a sample assembly and the options you would use to simplify it in the UI, then I can verify whether the same thing is possible with the API.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 6

tim11_manhhieu
Advocate
Advocate

is this what you are looking for?

 

Option Explicit

Sub SimplifyPart()

Dim AssDoc As AssemblyDocument
Set AssDoc = ThisApplication.ActiveDocument

Dim linkfile As String
linkfile = AssDoc.fullFilename

Dim linkfile2 As String
linkfile2 = AssDoc.DisplayName

' Create a new part document that will be the shrinkwrap substitute
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)

Dim oPartDef As PartComponentDefinition
Set oPartDef = oPartDoc.ComponentDefinition

Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
Set oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)

' Set various shrinkwrap related options
oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll

Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)

Dim oDerivedAss As DerivedAssemblyComponent
Set oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
Call oDerivedAss.BreakLinkToFile

' Save the part
Dim oPart As PartDocument
Set oPart = ThisApplication.ActiveDocument

Dim partName As String
partName = Left(linkfile, Len(linkfile) - 4) & ".ipt"

'ThisApplication.ActiveView.Fit
'ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute

Call oPartDoc.SaveAs(partName, True)

oPart.Close (True)

End Sub

 

0 Likes
Message 6 of 6

Maxim-CADman77
Advisor
Advisor

I want all defaults except
Exclude part by Size - (False)
Style = 'Single Solid Body ...'

Please vote for Inventor-Idea Text Search within Option Names

0 Likes