You are using an assembly with many LODs. Each time you place a component in your assembly , that one will be active in all level of Details.
For some configurations, you would like one component to be active in only one LOD.
Solved! Go to Solution.
Solved by pierre.masson. Go to Solution.
With the code below, you can select one part, and then select on LOD. The code will run through all LODs and suppress the part in all LODs except the one you selected, and the standard ones and Substitutes of course.
So you part will only be active in one of your User defined LOD.
Public Sub SuppressComponentreps()
' Set reference to active document.
' This assumes the active document is an assembly
Dim oDoc As Inventor.AssemblyDocument
Dim selset As SelectSet
Dim PartList As New Collection
Dim LODList As New Collection
Dim compOcc As ComponentOccurrence
Dim oCompDef As Inventor.ComponentDefinition
Dim lodrep As LevelOfDetailRepresentation
Dim lod As LevelOfDetailRepresentation
Set oDoc = ThisApplication.ActiveDocument
Set oCompDef = oDoc.ComponentDefinition
oDoc.SelectSet.Clear
MsgBox ("Select a Part or a Subassembly")
Do While oDoc.SelectSet.Count = 0
DoEvents ' Yield to other processes.
Loop
Set selset = oDoc.SelectSet
Dim obj As Object
For Each obj In selset
If TypeOf obj Is ComponentOccurrence Then
PartList.Add obj
End If
Next
oDoc.SelectSet.Clear
MsgBox ("Select the Level of Detail where the component will be active." & Chr(13) & "Master, Components Suppressed, Parts Suppressed and Concent center suppressed won't be treated" & Chr(13) & "Substitutes cannot be treated")
Do While oDoc.SelectSet.Count = 0
DoEvents ' Yield to other processes.
Loop
Dim selSetLOD As SelectSet
Set selSetLOD = oDoc.SelectSet
Dim objLOD As Object
For Each objLOD In selSetLOD
LODList.Add objLOD
Next
Set compOcc = PartList.Item(1)
Set lod = LODList.Item(1)
For Each lodrep In oCompDef.RepresentationsManager.LevelOfDetailRepresentations
If (lodrep.Name = lod.Name) And (lodrep.LevelOfDetail <> kSubstituteLevelOfDetail) Then
lodrep.Activate
If compOcc.Suppressed = True Then
compOcc.Unsuppress
End If
oDoc.Update
oDoc.Save
End If
If (lodrep.LevelOfDetail <> kMasterLevelOfDetail) And (lodrep.LevelOfDetail <> kAllComponentsSuppressedLevelOfDetail) And _
(lodrep.LevelOfDetail <> kAllPartsSuppressedLevelOfDetail) And (lodrep.LevelOfDetail <> kAllContentSuppressedLevelOfDetail) And (lodrep.Name <> lod.Name) And (lodrep.LevelOfDetail <> kSubstituteLevelOfDetail) Then
lodrep.Activate
compOcc.Suppress
oDoc.Update
oDoc.Save
End If
Next
oDoc.Update
End Sub
This API needs to be more tested, with big assemblies. If you like it, please Kudo.
If you find improvements or other solutions, please post.
This looks like just the tweak we need, we are using LODs on huge assemblies, so big that none of our computers can open the master LOD and when we put aan assembly in it insists on going in to all other LODs at the master level which often means we can't then open them.
I know this is probably a bit obvious but how do I use this?
Paste the code i wrote above in the VBA Editor of Inventor and run it.
It will ask you to select one part, and then one LOD.
The code will run through all LODs and suppress the part in all LODs except the one you selected, and the standard ones and Substitutes of course.
So you part will only be active in one of your User defined LOD.
I tested it in 2012, but it should be working fine in 2011.
Yes, you need to activate a LOD to make some changes in it. Even via API.
If I understand your problem well :
Thanks.
Hi
That's true. I understand your issue now. The macro could solve this, but it might take a lot of time if have really huge assemblies.
You can probably try to lower the Display and Hardware Settings in Application options (just for Running the code).
Please submit us your feedback here, it is an interesting improvement request :
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1109794
It shows following error
Compiler error:
Syntax error
with following line of code shown in red
For Each lodrep In oCompDef.RepresentationsManager.LevelOfDetailRepre?sentations
Please suggest what to do.
Regards,
Sajid Mahmood
Hello
You pasted this text :
For Each lodrep In oCompDef.RepresentationsManager.LevelOfDetailRepre?sentations
There is a question mark in Repre?sentations. If this is also in your code, then you need to remove it.
Hi,
I realise that the original code you placed on the forum was in 2012...but any chance you have an updated code that works on 2017?
Can't find what you're looking for? Ask the community or share your knowledge.