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: 

LOD of subassemblies

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Holgarsson
2207 Views, 11 Replies

LOD of subassemblies

Anyone please help.

 

I have an assembly that contains multiple subassemblise where I want to set or create a LOD.

 

I have a problem og getting the sub-assemblies to change as I somehow only get the top-level assembly to act to the following code.

 

The following code is written in the iLogic editor:

 

Start:

Dim asmDoc As AssemblyDocument

asmDoc = ThisApplication.ActiveDocument

 

Dim oAsmCompDef As AssemblyComponentDefinition

oAsmCompDef = asmDoc.ComponentDefinition

 

Dim oLODRep As LevelOfDetailRepresentation

Dim doc As Document

 

For Each doc In asmDoc.AllReferencedDocuments

 

' Check for assembly documents.

If doc.DocumentType = kAssemblyDocumentObject Then

    Try

        'Activate a writeable LOD (master LOD is not writeable)

      AsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Test").activate

        Catch

        'Assume error means this LOD does not exist, so create it (will be deleted at end)

        oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("Test")

    End Try

End If

Next

End

 

Can anyone point me in the right direction of getting the sub assemblies to act on the code above?

 

Thanks in advance

Kari

 

11 REPLIES 11
Message 2 of 12

Use ComponentOccurrence.SetLevelOfDetailRepresentation method to switch components to the desired LOD.

At the top level of assembly tree you may consider something like this :

For Each oOcc As ComponentOccurrence In oMainAssyDef.Occurrences
  If oOcc.Suppressed Then Continue For
  Try
    If oOcc.DefinitionDocumentType _
         = DocumentTypeEnum.kAssemblyDocumentObject Then
      oOcc.SetLevelOfDetailRepresentation(TargetLODName)
    End If
  Catch
  End Try
Next

To do the same work in multi-level main assembly you may consider the following workflow.

1.  AllReferencedDocuments property of the top assembly document  gives you access to all referenced subassembly documents.

2. For every found subassembly  you may find  all occurrences that reference this subassembly document at all levels in the main assembly.  Use ComponentOccurrences.AllReferencedOccurrences property for this purpose.  

3. Then you may call ComponentOccurrence.SetLevelOfDetailRepresentation method to set desired LOD in every subassembly occurrence.

 

Alternative workflow:  you may recursively traverse an assembly and set desired LOD in every subassembly occurrence.

See “Traverse an Assembly API Sample” in the Inventor API Help.

 

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 12

Thanks for your promt reply.

It works perfectly. At this time I will settle for the first level assemblies as multi-level main assembly is "over my head" at the moment.
Message 4 of 12

One additional quick question: If the "TargetLODName" does not excist I want to create it in the Catch part...

How can I acces the Component definition for each Occurrence an add the LOD if it does not excist?
Message 5 of 12

1. You could get ComponentDefinition object.from ComponentOccurrence.Definition property.

2. To create new LOD use RepresentationsManager:

' Create a new level of detail representation.
' The new representation is automatically activated.
Dim oLODRep As LevelOfDetailRepresentation
Set oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("Part2Suppressed")

Look at the “Create a level of detail representation API Sample” in the Inventor API Help.

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 12

I cannot figure it out... I works fine for the top-level assembly according to the API-samples You are reffering to, but when it comes to the occurrences in the assembly I fail.

 

Dim oMainAssyDef As AssemblyComponentDefinition

oMainAssyDef = ThisApplication.ActiveDocument.ComponentDefinition

 

Dim oLODRep As LevelOfDetailRepresentation

 

Try

    'Activate a writeable LOD (master LOD is not writeable)

    oMainAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Test").activate

    Catch

    'Assume error means this LOD does not exist, so create it (will be deleted at end)

    oLODRep = oMainAssyDef.RepresentationsManager.LevelOfDetailRepresentations.Add("Test")

End Try

 

 

'Iterate through all of the referenced documents at

'all levels of the assembly.

For Each oOcc As ComponentOccurrence In oMainAssyDef.Occurrences

 

'If the Occurent is suppressed then leav it as such

If oOcc.Suppressed Then Continue For

Try

    If oOcc.DefinitionDocumentType _

         = DocumentTypeEnum.kAssemblyDocumentObject Then

      oOcc.SetLevelOfDetailRepresentation("Test")

    End If

  Catch

    'Assume error means this LOD does not exist, so create it (will be deleted at end)

    'THIS IS WHERE I FAIL...

  End Try

Next

 

I have looked through the API samples but I cannot figure out how to access the ComponentOccurrence.Definition for each individual occurrence in the iteration. Please assist me some more.

 

Message 7 of 12

Could you look at this thread:

http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Change-LOD-in-component/m-p/3452094/hi...

 


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 8 of 12

Perfect!

 

With:

"If oOcc.Suppressed Then Continue For"

 

And some other small addtioins/adjustments... This will fit fine for an external rule.

 

Thanks!

Message 9 of 12
Holgarsson
in reply to: Holgarsson

I have taken the task to traverse through the assembly.

 

It works fine, but, when I traverse the assembly structure I cannot maintain the LOD that I set throughout the structure as it changes when the code reaches the next level, see attached code and picture.

 

The assembly that I tested on consists of:

  • Top level assembly
  • Two sub assemblies where one of the sub assemblies contains multiple level of subassemblies

The code does the following: (The numbering relates to the pictures in the attached file)

  1. Looks at the top level assembly LOD
  2. See if the first subassembly contains this LOD; if yes set it as active, if not create it and set it as active
  3. See if the next subassembly contains this LOD; if yes set it as active, if not create it and set it as active
  4. As the next subassembly contains multiple subassemblies the code traverses through the assembly structure... But here the code failes
  5. The code goes to the next level again but with the same result...

How can I maintain the LOD of all the assemblies and subassemblies?

Or should I try another approach?

 

Any input would be helpful.

 

 

CODE start

 

PrivateSub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click

 

        ' Get the active assembly.

        Dim oAsmDoc AsAssemblyDocument

        oAsmDoc = _invApp.ActiveDocument 'ThisApplication.ActiveDocument

        'Debug.Print(oAsmDoc.DisplayName)

 

        Dim oAsmDocDef AsAssemblyComponentDefinition

        oAsmDocDef = oAsmDoc.ComponentDefinition

 

        Dim ActiveLODRepName AsString

        Try

            ActiveLODRepName = oAsmDocDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name

        Catch ex1 AsException

            ActiveLODRepName = "Test"

        EndTry

 

        ' Call the function that does the recursion.

        Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1, ActiveLODRepName)

    EndSub

 

 

    PrivateSub TraverseAssembly(Occurrences AsComponentOccurrences, _

    Level AsInteger, ActiveLODRepName AsString)

 

        ' Iterate through all of the occurrence in this collection. This

        ' represents the occurrences at the top level of an assembly.

        Dim oOcc AsComponentOccurrence

        Dim oCompDef AsAssemblyComponentDefinition

        ForEach oOcc In Occurrences

 

            ' Check to see if this occurrence represents a subassembly

            ' and recursively call this function to traverse through it.

 

            If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

                If oOcc.Suppressed ThenContinue For

                Try

                    'Activate a writeable LOD (master LOD is not writeable)

                    oOcc.SetLevelOfDetailRepresentation(ActiveLODRepName)

                Catch

                    'Assume error means this LOD does not exist, so create it

                    oCompDef = oOcc.Definition

                    oCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(ActiveLODRepName)

                    oOcc.SetLevelOfDetailRepresentation(ActiveLODRepName)

                EndTry

 

                Call TraverseAssembly(oOcc.SubOccurrences, Level + 1, ActiveLODRepName)

            EndIf

        Next

    EndSub

 

CODE end

Message 10 of 12
Holgarsson
in reply to: Holgarsson

Any idea?

 

Feel free...

Message 11 of 12

I prefer two-step workflow.

Step 1

We can obtain the list of all subassembly documents filtering TopAssemblyDoc.AllReferencedDocuments collection.  In every found assembly document we may (if required) set up all desired LODs (+ update & save)

Step 2

For every custom LOD in the top assembly:  

Activate this LOD in the top assembly and then traverse top assembly tree to activate this LOD in subassemblies using SetLevelOfDetailRepresentation(LODname) method.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 12 of 12

I just came across this same issue. Did you ever find a solution?

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

Post to forums  

Autodesk Design & Make Report