<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Explode all sub-assemblies in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203618#M156980</link>
    <description>&lt;P&gt;Try this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oOccs As ComponentOccurrences = oDef.Occurrences
	Dim oTM As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Explode Assembly")
	ReturnStep :
	For Each oOcc As ComponentOccurrence In oOccs
		Dim oRefDoc As Document = oOcc.Definition.Document
		If oRefDoc.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject _
			Or Not oRefDoc.IsModifiable Then Continue For
		Dim oTargetNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
		For Each oSubOcc As ComponentOccurrence In oOcc.SubOccurrences
			If oSubOcc.DefinitionDocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject Then
				Try : oSubOcc.Name = oOcc.Name &amp;amp; " - " &amp;amp; oSubOcc.Name :	Catch : End Try
			End If
		    Dim oSourceNode As BrowserNode
		    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
		    Try : Call oPane.Reorder(oTargetNode, True, oSourceNode) : Catch : End Try
		Next
		oOcc.Delete()
	Next
	If HasSubAsm(oOccs) Then GoTo ReturnStep
	oTM.End()
End Sub

Private Function HasSubAsm(ByVal oOccs As ComponentOccurrences) As Boolean
	For i As Integer = 1 To oOccs.Count
		If oOccs(i).DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Return True
	Next i
	Return False
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new name of the component is written in line 15.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2023 09:27:20 GMT</pubDate>
    <dc:creator>Andrii_Humeniuk</dc:creator>
    <dc:date>2023-08-29T09:27:20Z</dc:date>
    <item>
      <title>Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203466#M156972</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;i'm looking for a rule able to explode all sub assemblies in order to have only single parts in the "main assembly".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 08:15:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203466#M156972</guid>
      <dc:creator>rbertoletti</dc:creator>
      <dc:date>2023-08-29T08:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203517#M156975</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13540634"&gt;@rbertoletti&lt;/a&gt;&amp;nbsp;.&amp;nbsp;Please try this code. But it does not process patterns.&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oOccs As ComponentOccurrences = oDef.Occurrences
	ReturnStep :
	For Each oOcc As ComponentOccurrence In oOccs
		Dim oRefDoc As Document = oOcc.Definition.Document
		If oRefDoc.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject _
			Or Not oRefDoc.IsModifiable Then Continue For
		For Each oSubOcc As ComponentOccurrence In oOcc.SubOccurrences
		    Dim oSourceNode As BrowserNode
		    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
		    Try : Call oPane.Reorder(oTargetNode, True, oSourceNode) : Catch : End Try
		Next
		oOcc.Delete()
	Next
	If HasSubAsm(oOccs) Then GoTo ReturnStep
End Sub

Private Function HasSubAsm(ByVal oOccs As ComponentOccurrences) As Boolean
	For i As Integer = 1 To oOccs.Count
		If oOccs(i).DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Return True
	Next i
	Return False
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 08:41:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203517#M156975</guid>
      <dc:creator>Andrii_Humeniuk</dc:creator>
      <dc:date>2023-08-29T08:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203556#M156977</link>
      <description>I tested it, but seems that the code delete the sub-assemblies and not explode.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Aug 2023 08:57:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203556#M156977</guid>
      <dc:creator>rbertoletti</dc:creator>
      <dc:date>2023-08-29T08:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203576#M156978</link>
      <description>&lt;P&gt;Sorry, I made one small mistake. Try this code:&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oOccs As ComponentOccurrences = oDef.Occurrences
	ReturnStep :
	For Each oOcc As ComponentOccurrence In oOccs
		Dim oRefDoc As Document = oOcc.Definition.Document
		If oRefDoc.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject _
			Or Not oRefDoc.IsModifiable Then Continue For
		Dim oTargetNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
		For Each oSubOcc As ComponentOccurrence In oOcc.SubOccurrences
		    Dim oSourceNode As BrowserNode
		    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
		    Try : Call oPane.Reorder(oTargetNode, True, oSourceNode) : Catch : End Try
		Next
		oOcc.Delete()
	Next
	If HasSubAsm(oOccs) Then GoTo ReturnStep
End Sub

Private Function HasSubAsm(ByVal oOccs As ComponentOccurrences) As Boolean
	For i As Integer = 1 To oOccs.Count
		If oOccs(i).DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Return True
	Next i
	Return False
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 09:03:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203576#M156978</guid>
      <dc:creator>Andrii_Humeniuk</dc:creator>
      <dc:date>2023-08-29T09:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203596#M156979</link>
      <description>Ok, now it works great! I've also found that if i have some components which has the same name the duplicated are deleted.&lt;BR /&gt;In order to avoid this is it possible to rename all the components inside the sub-assemblies by adding as prefix the sub-assembly name?&lt;BR /&gt;In this case i think no one of them will be deleted.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 29 Aug 2023 09:14:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203596#M156979</guid>
      <dc:creator>rbertoletti</dc:creator>
      <dc:date>2023-08-29T09:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Explode all sub-assemblies</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203618#M156980</link>
      <description>&lt;P&gt;Try this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub main
	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oOccs As ComponentOccurrences = oDef.Occurrences
	Dim oTM As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Explode Assembly")
	ReturnStep :
	For Each oOcc As ComponentOccurrence In oOccs
		Dim oRefDoc As Document = oOcc.Definition.Document
		If oRefDoc.DocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject _
			Or Not oRefDoc.IsModifiable Then Continue For
		Dim oTargetNode As BrowserNode = oPane.GetBrowserNodeFromObject(oOcc)
		For Each oSubOcc As ComponentOccurrence In oOcc.SubOccurrences
			If oSubOcc.DefinitionDocumentType &amp;lt;&amp;gt; DocumentTypeEnum.kAssemblyDocumentObject Then
				Try : oSubOcc.Name = oOcc.Name &amp;amp; " - " &amp;amp; oSubOcc.Name :	Catch : End Try
			End If
		    Dim oSourceNode As BrowserNode
		    oSourceNode = oPane.GetBrowserNodeFromObject(oSubOcc)
		    Try : Call oPane.Reorder(oTargetNode, True, oSourceNode) : Catch : End Try
		Next
		oOcc.Delete()
	Next
	If HasSubAsm(oOccs) Then GoTo ReturnStep
	oTM.End()
End Sub

Private Function HasSubAsm(ByVal oOccs As ComponentOccurrences) As Boolean
	For i As Integer = 1 To oOccs.Count
		If oOccs(i).DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Return True
	Next i
	Return False
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new name of the component is written in line 15.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 09:27:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/explode-all-sub-assemblies/m-p/12203618#M156980</guid>
      <dc:creator>Andrii_Humeniuk</dc:creator>
      <dc:date>2023-08-29T09:27:20Z</dc:date>
    </item>
  </channel>
</rss>

