All View Representations to Default - how to run it in all subassemblies

All View Representations to Default - how to run it in all subassemblies

G.DeGheest
Participant Participant
316 Views
2 Replies
Message 1 of 3

All View Representations to Default - how to run it in all subassemblies

G.DeGheest
Participant
Participant

Hello,

 

I have an iLogic code that works on all assemblies in the Main Assembly.

And I want to make it work in all the Assemblies and Subassemblies also. But I don't know how.

Can anyone help me to adjust the code?

 

Dim doc As AssemblyDocument = ThisDoc.Document
Dim cdef As ComponentDefinition = doc.ComponentDefinition
Dim occ As Inventor.ComponentOccurrence

For Each occ In cdef.Occurrences
	Try
	occ.SetDesignViewRepresentation("Default", True, True)
	Catch
	End Try
Next

 

0 Likes
Accepted solutions (1)
317 Views
2 Replies
Replies (2)
Message 2 of 3

Cadkunde.nl
Collaborator
Collaborator
Accepted solution

You can try this:

 

Sub Main()
Dim doc As AssemblyDocument = ThisDoc.Document
TraverseAssembly(doc.ComponentDefinition.Occurrences, 1)
doc.activate
End Sub

Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer)

	For Each occ In Occurrences
		If occ.suppressed = False Then
			If occ.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
				Try
					occ.SetDesignViewRepresentation("Default", True, True)
				Catch
				End Try
				Dim occdoc As AssemblyDocument = occ.Definition.Document
				ThisApplication.Documents.Open(occdoc.FullFileName, False)

				TraverseAssembly(occdoc.ComponentDefinition.Occurrences, Level + 1)
				ThisApplication.Documents.ItemByName(occdoc.FullFileName).close

			End If
		End If
	Next
End Sub

Not sure if you need to activate the assembly and open with visible = true
Also this disregards any levelofdetails

 

Using how to iterate through assembly from: https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

0 Likes
Message 3 of 3

G.DeGheest
Participant
Participant

I just tested your code and it works great. Thank you so much for your professional feedback!

This code will save me a lot of time! 

 

0 Likes