Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need to change the level of detail of a derived assembly.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
shastu
343 Views, 8 Replies

Need to change the level of detail of a derived assembly.

Can someone please help me figure out a way to do this?  I have a part file with a derived assembly in it and before I perform my code, I need to make sure that the derived assembly is using the Master level of detail.  This code needs to be done in VBA automatically but to be clear of what I am needing, it would be like I right mouse click on the derived assembly from the part file, click on the "edit derived assembly", then click on the Representation tab and then change the Level of Detail to "Master".  I already have the logic to check the value first and if it is already using the "Master", it will skip the step, but if it is not, I need a way to change it to "Master".  I tried doing a call like 

 

LOD = "Master"

Call oSubs.Item(1).Definition.ActiveLevelOfDetailRepresentation(LOD)

 

But that didn't work.

8 REPLIES 8
Message 2 of 9
WCrihfield
in reply to: shastu

Hi @shastu.  You mentioned already having the logic for checking the current value, but it sounds like you just need to add more code or modify some existing code to make it work the way you want.  Can you please copy your existing code (the text, not just an image of it), and paste that code text here, using the </> tool in the forum response, so it will be pasted into a code window.  That will help us to be able to help you easier and faster.  Also, what version of Inventor are you using?  It sounds like you must be using 2021 or older version, if you are still working with LOD's. 

 

Does the result need to be in VBA, or would an iLogic rule work better for you.  I highly recommend transitioning your existing codes and any new codes from VBA to iLogic, as time permits.  Although I do realize that in earlier versions of Inventor, VBA offered a convenient way to run codes from 'macro' buttons in the ribbon, while iLogic did not offer that yet, so it is definitely understandable.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 9
shastu
in reply to: WCrihfield

/ Dim oSubs As Inventor.DerivedAssemblyComponents
Set oSubs = oDef.ReferenceComponents.DerivedAssemblyComponents

Dim DerivedNameRef As String
DerivedNameRef = oSubs.Item(1).Definition.ActiveLevelOfDetailRepresentation
If DerivedNameRef <> "Master" Then

LOD = "Master"

Call oSubs.Item(1).Definition.ActiveLevelOfDetailRepresentation(LOD)
End If /

 

Also, yes we are currently using 2021.  We will be upgrading to 2024 soon.

Message 4 of 9
WCrihfield
in reply to: shastu

I had to dig back into the 2021 documentation, and type up the rest of a similar VBA macro on my end, to make sure the code made sense, but I think it should be like ' ... = LOD', instead of like 'Call ... (LOD)'.

Below is what I typed up in a temporary macro.  I have not tested this, because I do not have a good test subject, and am using 2024.2.1 version right now.

 

Sub ChangeDerivedAsmLOD()

    Dim oActivePartDoc As PartDocument
    Set oActivePartDoc = ThisApplication.ActiveDocument
    
    Dim oActivePartDef As PartComponentDefinition
    Set oActivePartDef = oActivePartDoc.ComponentDefinition
    
    Dim oSubs As Inventor.DerivedAssemblyComponents
    Set oSubs = oActivePartDef.ReferenceComponents.DerivedAssemblyComponents
    
    Dim oSub As Inventor.DerivedAssemblyComponent
    Set oSub = oSubs.Item(1)
    
    Dim oSubDef As DerivedAssemblyDefinition
    Set oSubDef = oSub.Definition
    
    If oSubDef.ActiveLevelOfDetailRepresentation <> "Master" Then
        oSubDef.ActiveLevelOfDetailRepresentation = "Master"
    End If
    
End Sub

 

Edit:  Here is the link to the 2021 online help page about that property.  It says it is Get/Set (so Read/Write).

DerivedAssemblyDefinition.ActiveLevelOfDetailRepresentation Property 

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-5EAB958B-D89E-415B-964A-016E2AC76B68 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 9
shastu
in reply to: WCrihfield

No, I had already tried that and in the code the value does change to "Master", but it doesn't do anything in the actual model.  That is why I thought I needed some type of "Call" statement.

Message 6 of 9
WCrihfield
in reply to: shastu

I too was sort of looking for a Set... type of 'method' for this sort of thing, instead of just a Read/Write property, but did not find one.  Seems like it would have been under the DerivedAssemblyDefinition object's online help documentation web page, but...

I just noticed something else that may help though.  The DerivedAssemblyComponent.Definition property is Read/Write, which to me means we can set a different/edited definition as its value.  Maybe we need to get the existing definition, change it as needed, then set that definition object back as the value of that property.  Just a quick thought, that I unfortunately can not test on my end.

Edit:  And of course, a document update or rebuild command thrown in there at the end would be a good idea too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 9
shastu
in reply to: WCrihfield

That is basically what we have done.  The DerivedAssemblyComponent.Definition of the ActiveLevelOfDetailRepresentation is equal to "Master".  I just can't figure out the syntax to execute it or make it happen after it has been set.  I tried a rebuild and it did the rebuild, but the level of detail did not change.

 

I feel like after the osubDef.ActiveLevelOfDetailRepresentation is set to "Master" then I need a statement of

oSub."something".  If I put in oSub.Delete then it deletes the derived assembly that I am trying to change so Instead of .Delete, I feel like I need an oSub.update but that is not an option.

 

I just realized that the oSub.Definition.ActiveLevelOfDetailRepresentation is still set to the original which I think is the problem.  I tried to set it = to "Master" just like I did for the oSubDef, but it doesn't work.  It still shows the value as the original value.

 

I also tried this:

Sub ChangeDerivedAsmLOD()

Dim oActivePartDoc As PartDocument
Set oActivePartDoc = ThisApplication.ActiveDocument

Dim oActivePartDef As PartComponentDefinition
Set oActivePartDef = oActivePartDoc.ComponentDefinition

Dim oSubs As Inventor.DerivedAssemblyComponents
Set oSubs = oActivePartDef.ReferenceComponents.DerivedAssemblyComponents

Dim oSub As Inventor.DerivedAssemblyComponent
Set oSub = oSubs.Item(1)

Dim oSubDef As DerivedAssemblyDefinition
Set oSubDef = oSub.Definition

Dim oRepManager As RepresentationsManager
Set oRepManager = oActivePartDoc.ComponentDefinition.RepresentationsManager

Dim oLOD As LevelOfDetailRepresentation
Set oLOD = oRepManager.LevelOfDetailRepresentations.Item("Master")
Call oLOD.Activate

 

But it fails on the Set oLOD statement.

 

Message 8 of 9
WCrihfield
in reply to: shastu

Hi @shastu.  What I meant was to set a new value to the DerivedAssemblyComponent.Definition property directly.  But only after the ActiveLevelOfDetailRepresentation Property's value had been changed.  Below is what I had in mind (notice Line 15), but I am still not sure if this will work or not.  It was just an idea that seemed logical to try.  I also added a line of code to 'rebuild' the part.  Not sure a rebuild would really be needed, but it should force an update, even if it does not believe an update is needed.  Not usually an efficient one to use, but can be changed later if it works.

Sub ChangeDerivedAsmLOD()
    Dim oActivePartDoc As PartDocument
    Set oActivePartDoc = ThisApplication.ActiveDocument
    Dim oActivePartDef As PartComponentDefinition
    Set oActivePartDef = oActivePartDoc.ComponentDefinition
    Dim oSubs As Inventor.DerivedAssemblyComponents
    Set oSubs = oActivePartDef.ReferenceComponents.DerivedAssemblyComponents
    Dim oSub As Inventor.DerivedAssemblyComponent
    Set oSub = oSubs.Item(1)
    Dim oSubDef As DerivedAssemblyDefinition
    Set oSubDef = oSub.Definition
    If oSubDef.ActiveLevelOfDetailRepresentation <> "Master" Then
        oSubDef.ActiveLevelOfDetailRepresentation = "Master"
    End If
    oSub.Definition = oSubDef
    Call oActivePartDoc.Rebuild2(True)
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9
ashhof
in reply to: WCrihfield

Oh,  Thanks for clarifying.  Sorry that I did not follow what you were saying.  Yes, this works and without the rebuild.  Thanks so much for your help!!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report