Change LOD in component

Change LOD in component

mrattray
Advisor Advisor
1,761 Views
4 Replies
Message 1 of 5

Change LOD in component

mrattray
Advisor
Advisor

I have an iLogic controlled assembly with sub assemblies that are also iLogic controlled. The main assembly calculates some lengths and turns some subs on and off and then updates all the subs. The subs also calculate some lengths and turn some parts on and off. I have a rule in both the main assembly and copies in the subs that control the LOD to make sure that it's set to custom before anything else runs.

Now I may be misunderstanding something, but it appears that it's possible to have a sub assembly set to one LOD but be referenced in a top level assembly as a different LOD. In other words I have a sub that shows in the top level browser as Master. If I open this sub and set it from within the sub to custom LOD and switch back to the top level assembly it is still set to master there. It appears that this is what my LOD rule is also doing, setting it to custom in the sub but not changing the top level reference.

Am I misunderstanding something here?  If not, does anyone have an iLogic snippet I can use to change this "referenced LOD" before the rest of my code runs?

 

Thanks in advance,

Mike

Mike (not Matt) Rattray

0 Likes
Accepted solutions (1)
1,762 Views
4 Replies
Replies (4)
Message 2 of 5

mrattray
Advisor
Advisor
Accepted solution

I finally got this figured out thanks to some free time and a bit of help from Curtis!

This will set the top level assemblies LOD to one named "Custom" and also iterate through every component in the assembly and set them to "Custom". This rule is triggered from my configurator's engine via an error catch as well as before any initial operations are executed. It must also be present along with it's associated error catch in any sub assemblies with sub sub assemblies that are configured via iLogic. The first half of the code needs to be present in any sub assembly that is modified via iLogic.

By modified in iLogic I'm refering exlusively to component suppresion and not parameter or other changes.

 

 Option Explicit

Imports Inventor.LevelOfDetailEnum

Sub Main

iLogicVb.UpdateWhenDone = True

Dim doc As AssemblyDocument
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences

doc = ThisDoc.Document
If doc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.LevelOfDetail <> kCustomLevelOfDetail Then 
	oAsmCompDef = doc.ComponentDefinition
	oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Custom")
	oLOD.Activate(True)
End If
oComps = doc.ComponentDefinition.Occurrences
On Error Goto handle
For Each oComp In oComps
	If oComp.Suppressed = False Then
		If Not TypeOf oComp.Definition Is VirtualComponentDefinition Then
			If oComp.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
				If oComp.ActiveLevelOfDetailRepresentation <> "Custom" Then 
					oComp.SetLevelOfDetailRepresentation("Custom", True)
				End If
			End If
		End If
	End If
Next

Exit Sub

handle:
MsgBox("LOD releated error in: " & oComp.Name, vbOKOnly, "LOD error")

End Sub

 

Mike (not Matt) Rattray

Message 3 of 5

mrattray
Advisor
Advisor

I spent some more time on this sub and made some improvements. Most notably error catching for when the desired LOD doesn't exist in the file. The sub will now create the LOD if it is missing and set it.

It also sets the BOM structure to reference if a part is suppressed or default if it is not. That's just to suit the way I work, it doesn't do anything for the LOD setting part of the code and can be removed if desired.

 

 Option Explicit

Imports Inventor.LevelOfDetailEnum
Imports Inventor.BOMStructureEnum

Sub Main

iLogicVb.UpdateWhenDone = True

Dim doc As AssemblyDocument
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences
Dim oCompCompDef As AssemblyComponentDefinition
Dim LODname As String

'Set LODname to whatever you like your LOD's to be named as.
LODname = "Custom"

doc = ThisDoc.Document
If doc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.LevelOfDetail <> kCustomLevelOfDetail Then 
	oAsmCompDef = doc.ComponentDefinition
	Try
		'Try to set our assemblies active LOD to the above specified.
		oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(LODname)
		oLOD.Activate(True)
	Catch
		'It didn't work so we need to create a new one and then set it.
		oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(LODname)
		oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(LODname)
		oLOD.Activate(True)
	End Try
End If

'Iterate through all of the component's in the assembly.
oComps = doc.ComponentDefinition.Occurrences
For Each oComp In oComps
	'Make sure the component isn't suppressed to avoid the resulting error.
	If oComp.Suppressed = False Then
		'The following 1 line is optional, feel free to remove it. Do NOT remove the if suppressed check!
		oComp.BOMStructure = kDefaultBOMStructure
		'Make sure the component isn't a virtual component to avoid the resulting error.
		If Not TypeOf oComp.Definition Is VirtualComponentDefinition Then
			'Make sure the component is an assembly.
			If oComp.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
				'Check if the active LOD is already correct or not.
				If oComp.ActiveLevelOfDetailRepresentation <> LODname Then 
					Try
						'Try to set our copmponent's active LOD to the above specified.
						oComp.SetLevelOfDetailRepresentation(LODname, True)
					Catch
						'It didn't work so we need to create a new one and then set it.
						oCompCompDef = oComp.Definition
						oCompCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(LODname)
						oComp.SetLevelOfDetailRepresentation(LODname, True)
					End Try
				End If
			End If
		End If
	Else
             'The following 5 lines are optional, feel free to remove them.
        If oComp.BOMStructure <> kReferenceBOMStructure Then
             Component.IsActive(oComp.Name) = True
             oComp.BOMStructure = kReferenceBOMStructure
             Component.IsActive(oComp.Name) = False
        End If
         ' End If Next End Sub

 

 

Mike (not Matt) Rattray

Message 4 of 5

mrattray
Advisor
Advisor

I found that the rule throws an error when ran in a weldment. This new revision includes a check for weld beads, which are apprently members of the components collection.

 

 Option Explicit

Imports Inventor.LevelOfDetailEnum
Imports Inventor.BOMStructureEnum

Sub Main

iLogicVb.UpdateWhenDone = True

Dim doc As AssemblyDocument
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences
Dim oCompCompDef As AssemblyComponentDefinition
Dim LODname As String

'Set LODname to whatever you like your LOD's to be named as.
LODname = "Custom"

doc = ThisDoc.Document
If doc.ComponentDefinition.RepresentationsManager.ActiveLevelOfDetailRepresentation.LevelOfDetail <> kCustomLevelOfDetail Then 
	oAsmCompDef = doc.ComponentDefinition
	Try
		'Try to set our assemblies active LOD to the above specified.
		oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(LODname)
		oLOD.Activate(True)
	Catch
		'It didn't work so we need to create a new one and then set it.
		oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(LODname)
		oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(LODname)
		oLOD.Activate(True)
	End Try
End If

'Iterate through all of the component's in the assembly.
oComps = doc.ComponentDefinition.Occurrences
For Each oComp In oComps
	'Make sure the component isn't a weld bead.
	If Left(oComp.Name, 10) <> "_Weldbead:"
		'Make sure the component isn't suppressed to avoid the resulting error.
		If oComp.Suppressed = False Then
			'The following 1 line is optional, feel free to remove it. Do NOT remove the if suppressed check!
			oComp.BOMStructure = kDefaultBOMStructure
			'Make sure the component isn't a virtual component to avoid the resulting error.
			If Not TypeOf oComp.Definition Is VirtualComponentDefinition Then
				'Make sure the component is an assembly.
				If oComp.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
					'Check if the active LOD is already correct or not.
					If oComp.ActiveLevelOfDetailRepresentation <> LODname Then 
						Try
							'Try to set our copmponent's active LOD to the above specified.
							oComp.SetLevelOfDetailRepresentation(LODname, True)
						Catch
							'It didn't work so we need to create a new one and then set it.
							oCompCompDef = oComp.Definition
							oCompCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(LODname)
							oComp.SetLevelOfDetailRepresentation(LODname, True)
						End Try
					End If
				End If
			End If
		Else
			'The following 5 lines is optional, feel free to remove it.
			If oComp.BOMStructure <> kReferenceBOMStructure Then
				Component.IsActive(oComp.Name) = True
				oComp.BOMStructure = kReferenceBOMStructure
				Component.IsActive(oComp.Name) = False
			End If
			'
		End If
	End If
Next

End Sub

 

Mike (not Matt) Rattray

Message 5 of 5

Anonymous
Not applicable
Nice piece of code. Thanks for posting.
0 Likes