Wednesday, January 4, 2012

Setting the Level of Detail with iLogic

iLogic requires a custom Level of Detail (LoD) before it can perform an operation that suppresses a component. If a custom LoD is not active or one does not exist you will get an error message. I get a lot of enquires about this dialog box and how one can avoid the hassle.



Many times the LoD will revert back to “Master” when using the Copy Design functionality from Autodesk Vault or when an assembly is opened by a new user. Sometimes users will have several custom LoDs set up to help manage a large assembly. In either case we would like a specific LoD to be set when executing rules from iLogic.


This assembly shows the default Level of Details present in every assembly, but before we can use any code to suppress a component we would need to create a custom LoD. The new LoD can be any name, but I prefer one I know is specific to iLogic rules – I’ll call it “iLogic”.

Of course I could simply create and activate the LoD via normal Inventor methods but perhaps a bit of code will be better for assuring the whole concept works smoothly every time.

First create a rule called “LoD” and populate with the following code:

Dim doc as AssemblyDocument = ThisDoc.Document 
Dim oLOD As LevelOfDetailRepresentation 
Dim oAsmCompDef As ComponentDefinition 
oAsmCompDef = doc.ComponentDefinition
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
Catch
Dim nLOD As LevelOfDetailRepresentation
nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
oLOD = nLOD
Finally
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
End Try


This code will  make sure that a Level of Detail called “iLogic” exists in the assembly and, if not, will create it (handy when/if the original got deleted). The LoD is then made active, assuring smooth operation of other rules that will utilize suppression.
Remember, iLogic rules run in sequence, so placing this rule at the top of this list assures it is the first one fired. You could also use the event triggers to have this rule run when the file is initially opened.

4 comments:

  1. Hi Carl,

    Fantastic post! I am currently using a modified version of your code to switch between LOD’s but I was wondering if you know of a way to automatically apply the "link Levels of Detail" command on the Productivity panel of the Assembly tab?

    I have assemblies that are placed into a master assembly using the Place iLogic command. All of the assemblies have identical LODs and if I use the Link Levels of Detail command, I can use an iLogic switch to do some real cool stuff –but the problem is remembering to do the linking of the LOD’s. It would be nice to do so on placement. Any thoughts?

    Mark Randa

    The Open design Project
    http://opendesignproject.org/

    ReplyDelete
  2. check out...this code below

    If LOD="Master" Then
    ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Master").Activate
    iLogicVb.UpdateWhenDone=True
    ThisApplication.ActiveView.Fit
    ElseIf LOD="LevelofDetail1" Then
    ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("LevelofDetail1").Activate
    iLogicVb.UpdateWhenDone=True
    ThisApplication.ActiveView.Fit
    End If

    Source:http://forums.autodesk.com/t5/Autodesk-Inventor/level-of-detail-with-ilogic/td-p/3074270

    ReplyDelete
  3. After looking over this code some more I realized it wasn't really correct. Well its correct but a bit sloppy.

    Here is how I would do it.

    Dim doc as AssemblyDocument = ThisDoc.Document
    Dim oLOD As LevelOfDetailRepresentation
    Dim oAsmCompDef As ComponentDefinition
    oAsmCompDef = doc.ComponentDefinition

    Try
    oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
    Catch ex As System.ArgumentException
    oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
    Finally
    oLOD.Activate(True)
    End Try

    ReplyDelete
  4. Perhaps someone can write some code to delete this "Level of Detail." It's way too much detail for this topic. :P

    ReplyDelete