Ilogic Sub Assembly set view rep

Ilogic Sub Assembly set view rep

Anonymous
Not applicable
875 Views
3 Replies
Message 1 of 4

Ilogic Sub Assembly set view rep

Anonymous
Not applicable

Hi, 

 

Hoping somebody can help me to get my ilogic code working.

 

Tree.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Am wanting to use ilogic in the main assembly (Single Hinged Door) to set view reps in 2nd level assembly (61 LK 1806 L) and have that rep shown in both 1st level (Dynamic Door) and main (Single Hinged Door) assemblies. Want to avoid LODs if possible.

 

My attempt below is based on old forum posts for older Inventor versions (currently running up to date 2018) and comes up with a the "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" error

 

SyntaxEditor Code Snippet

' set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define the Component Occurrence collection
Dim oCompOcc As Inventor.ComponentOccurrence 
Dim oSubCompOcc As Inventor.ComponentOccurrence
'set top level view rep to CUSTOM
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("CUSTOM").activate

For Each oCompOcc in oAsmCompDef.Occurrences
    oCompOcc.SetDesignViewRepresentation("CUSTOM",, True) 'True sets the view rep to be CUSTOM
Next

Dim occurDocDef as AssemblyComponentDefinition

'modify actual subassembly document
If oCompOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
    'get assembly component defintion in the subassembly document
    occurDocDef = oCompOcc.Definition
    
    For Each oSubCompOcc in occurDocDef.Occurrences
        If oSubCompOcc.Name = "61 LK 1806 L" Then
            oSubCompOcc.SetDesignViewRepresentation("CUSTOM",, True) 'True sets the view rep to be CUSTOM
        End If
    Next
    
End If

 Any Help would be hugely appreciated.

 

Regards,

 

Harrison

0 Likes
876 Views
3 Replies
Replies (3)
Message 2 of 4

JaneFan
Autodesk
Autodesk

Hello @Anonymous,

 

It make things not hard since the condition is clear that you want to control the first and second level occurrence.

SetDesignViewRepresentation can only be used in assembly occurences, so you were seeing the error before becasue the part occurrences were not filtered out.

Please using following code instead:

SyntaxEditor Code Snippet

' set a reference to the assembly component definition.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define the Component Occurrence collection
Dim oCompOcc As Inventor.ComponentOccurrence 
Dim oSubCompOcc As Inventor.ComponentOccurrence
'set top level view rep to CUSTOM
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("CUSTOM").Activate

Dim oSecondLevelOcc As ComponentOccurrence 
 
'The following code can set design view rep to "Custom" for all assembly occurrences
For Each oCompOcc In oAsmCompDef.Occurrences
	If oCompOcc.definition.document.documenttype = kAssemblyDocumentObject Then
    	oCompOcc.SetDesignViewRepresentation("CUSTOM", , True) 'True sets the view rep to be CUSTOM
		
		'Go through the sub occurrences of the assembly occurrence
		For Each oSecondLevelOcc In oCompOcc.SubOccurrences
			If oSecondLevelOcc.Name = "61 LK 1806 L" Then
            	oSecondLevelOcc.SetDesignViewRepresentation("CUSTOM",, True) 'True sets the view rep to be CUSTOM
        	End If
    Next	
	End If
Next

 

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Jane,

 

Thanks for your reply. This code appears to work for a second while the code is computing but then sets all three assemblies to MASTER view rep?

0 Likes
Message 4 of 4

JaneFan
Autodesk
Autodesk

Hi Harrison,

 

The code is used to set design view of top assembly to CUSTOM first, then go through all sub assemblies and set them to CUSTOM design view. If it is not what you want, please adjust the code as needed. Please let me know if you need more clues.




Jane Fan
Inventor/Fusion QA Engineer
0 Likes