<?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: Delete occurrence in Assembly in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498923#M144165</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7623721"&gt;@filippo.costantin3HZMT&lt;/a&gt;.&amp;nbsp; If you just need to open the document so you can read or edit its iProperty, then close it again, there is an easier, and more logical way to do that.&lt;/P&gt;
&lt;P&gt;Instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Call AddComponent(file)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oFileDoc As Document = ThisApplication.Documents.Open(file, False)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...then, instead of this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Call DeleteComponent()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;oFileDoc.Close(True) 'True = skip save&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, instead of the oFileDoc.Close, you might also be able to use the following routine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;oFileDoc.ReleaseReference&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...but then, after the end of the loop, if you used the ReleaseReference method, you can use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;ThisApplication.Documents.CloseAll(True) 'True  = only close all unreferenced documents&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Oct 2022 12:43:42 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2022-10-21T12:43:42Z</dc:date>
    <item>
      <title>Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498510#M144156</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a code for read iproperties from part or assembly in folder. The code run:&lt;/P&gt;&lt;P&gt;1 - read all file in folder&lt;/P&gt;&lt;P&gt;2 - filter file in folder (.asm, .ipt)&lt;/P&gt;&lt;P&gt;3 - add component to assembly&lt;/P&gt;&lt;P&gt;4 - read iproperties&lt;/P&gt;&lt;P&gt;5 - delete component&lt;/P&gt;&lt;P&gt;All works very weel but the last phase give me the error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filippocostantin3HZMT_0-1666341928679.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1130310iA0D01D4510D93C52/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filippocostantin3HZMT_0-1666341928679.png" alt="filippocostantin3HZMT_0-1666341928679.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I create many logger for control the code anche the code raw that give me a problem is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Sub DeleteComponent()
	Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oAsmCompDef.Occurrences
		
		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
			Logger.Info("⃝⃝⃝⃝  [ Rimozione assieme " &amp;amp; oOcc.Name &amp;amp; " ]")
			oOcc.Delete()
			Logger.Info("⃝⃝⃝⃝  [ Fine rimozione dell'elemento  " &amp;amp; oOcc.Name &amp;amp; " ]")
		End If	
	Next
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;oOcc.Delete()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've already use this function in other code but now I've this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i Solve it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In attached the complete code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 08:50:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498510#M144156</guid>
      <dc:creator>filippo.costantin3HZMT</dc:creator>
      <dc:date>2022-10-21T08:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498787#M144159</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7623721"&gt;@filippo.costantin3HZMT&lt;/a&gt;.&amp;nbsp; I can't read what the error message says, because it is not in English, but it kind of looks like "Unspecified Error", which would not be that helpful anyways.&amp;nbsp; The second tab of the error message dialog sometimes has more useful information somewhere within it, but not always.&amp;nbsp; Are you sure it is that 'oOcc.Delete' line causing the error?&amp;nbsp; I don't know if it would be any different functionality, but the first alternative I might have tried would be oOcc.Delete2(True).&amp;nbsp; The 'True' there tells it to skip saving the source document of the component.&amp;nbsp; Another thing that comes to mind is that the assembly may need to be updated, because maybe it is trying to delete a component that no longer exists or something like that, though it seems a bit unlikely.&amp;nbsp; It was rather difficult to follow along with your code, due to the language difference, and the amount of commented out stuff remaining within it, but it kind of looks like you may be adding an assembly type component to the 'active' assembly, then almost immediately deleting it again, without any document update of any sort in between the two.&amp;nbsp; If that is true, what is the purpose...just curiosity.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 11:41:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498787#M144159</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-21T11:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498848#M144163</link>
      <description>&lt;P&gt;Hi, Yes It's the workflow, I need to open, read iporperties and close file. After this simple action i want to create a list with all iproperty that I extract from file and write on excel.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the specification of error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filippocostantin3HZMT_0-1666354100425.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1130362i80E2601F4B4B4C2E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filippocostantin3HZMT_0-1666354100425.png" alt="filippocostantin3HZMT_0-1666354100425.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 12:08:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498848#M144163</guid>
      <dc:creator>filippo.costantin3HZMT</dc:creator>
      <dc:date>2022-10-21T12:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498923#M144165</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7623721"&gt;@filippo.costantin3HZMT&lt;/a&gt;.&amp;nbsp; If you just need to open the document so you can read or edit its iProperty, then close it again, there is an easier, and more logical way to do that.&lt;/P&gt;
&lt;P&gt;Instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Call AddComponent(file)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oFileDoc As Document = ThisApplication.Documents.Open(file, False)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...then, instead of this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Call DeleteComponent()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;oFileDoc.Close(True) 'True = skip save&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, instead of the oFileDoc.Close, you might also be able to use the following routine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;oFileDoc.ReleaseReference&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...but then, after the end of the loop, if you used the ReleaseReference method, you can use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;ThisApplication.Documents.CloseAll(True) 'True  = only close all unreferenced documents&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 12:43:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498923#M144165</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-21T12:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498928#M144166</link>
      <description>&lt;P&gt;Thanks for your advice. But how can I save the iProperties in a list if I open every file?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 12:44:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498928#M144166</guid>
      <dc:creator>filippo.costantin3HZMT</dc:creator>
      <dc:date>2022-10-21T12:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498963#M144168</link>
      <description>&lt;P&gt;It looks like you are creating a new String type variable between those two processes called "Codice".&amp;nbsp; Then you are setting its value from that file's custom iProperty.&amp;nbsp; Then you are writing that value out to the iLogic Logger.&amp;nbsp; If you do not intend to copy data from the Logger, and you do not want to inject a call to a custom Sub routine there that would write that value directly into an Excel sheet, then I would suggest that you create something like a New List(Of String) type variable somewhere before this point in your code (before the loop), then 'Add' this custom iProperty value to that List between those two processes.&amp;nbsp; Then later, after the loop, you will have that List object filled with those values that you can do what you want with.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:00:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11498963#M144168</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-21T13:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499051#M144172</link>
      <description>&lt;P&gt;How can I read the iproperties after use&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim oFileDoc As Document = ThisApplication.Documents.Open(file, False)&lt;/PRE&gt;&lt;P&gt;I can't read because the rule find the iProperties in the assembly where I launch the rule.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:23:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499051#M144172</guid>
      <dc:creator>filippo.costantin3HZMT</dc:creator>
      <dc:date>2022-10-21T13:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499125#M144175</link>
      <description>&lt;P&gt;Good point.&amp;nbsp; That iLogic only shortcut snippet 'iProperties.Value()' is limited to only being able to access the iProperties of documents that are referenced by the 'active' document.&amp;nbsp; So, in this case, I would suggest using the API route to access that document's iProperty.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oFileDoc As Document = ThisApplication.Documents.Open(file, False)
Dim Codice As String
Codice = oFileDoc.PropertySets.Item("Inventor User Defined Properties").Item("PR_Codice").Value&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 13:51:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499125#M144175</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-10-21T13:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete occurrence in Assembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499485#M144188</link>
      <description>&lt;P&gt;It works very well. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2022 15:44:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/delete-occurrence-in-assembly/m-p/11499485#M144188</guid>
      <dc:creator>filippo.costantin3HZMT</dc:creator>
      <dc:date>2022-10-21T15:44:31Z</dc:date>
    </item>
  </channel>
</rss>

