<?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: VBA not working randomly with IPT files on my computer only in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7038636#M101409</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link you provided is almost right (in my case at least) since we can reproduce the issue with the sequence indicated but the reversed sequence reproduces the issue randomly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my final code to prevent this issue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;...
Dim actBomStrucInt As Integer

Dim doc = ThisApplication.ActiveDocument
Dim BOMStruc As BOMStructureEnum = Nothing

If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim assemDoc As AssemblyDocument = doc
	BOMStruc = assemDoc.ComponentDefinition.BOMStructure
ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim partDoc As PartDocument = doc
	BOMStruc = partDoc.ComponentDefinition.BOMStructure
End If

actBomStrucInt = BOMStruc
...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2017 18:09:51 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-04-24T18:09:51Z</dc:date>
    <item>
      <title>VBA not working randomly with IPT files on my computer only</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7037980#M101407</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope somebody will&amp;nbsp;give ideas to explore on why iLogic rules don't work properly on my computer sometimes only. Following line of code was working properly last friday and doesn't work this morning (my computer only). I restarted Inventor and now it works. See attached image for error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;actBomStrucInt = ThisApplication.ActiveDocument.ComponentDefinition.BOMStructure&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use the integer to set the value of a custom iproperty.&amp;nbsp;It always works properly within assemblies but not always within parts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not the first time I have this problem but today I have time to post for an answer.&amp;nbsp;By the way, I'll be out of my office until next week so it may take some time before I get back here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 14:34:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7037980#M101407</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-24T14:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: VBA not working randomly with IPT files on my computer only</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7038100#M101408</link>
      <description>&lt;P&gt;Please look into the information provided in this blog. I do believe it could be the issue with the documents/files and how you access the component definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adndevblog.typepad.com/manufacturing/2016/11/ilogic-activedocumentcomponentdefinition-throws-exception-for-specific-document.html" target="_blank"&gt;http://adndevblog.typepad.com/manufacturing/2016/11/ilogic-activedocumentcomponentdefinition-throws-exception-for-specific-document.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ie; the solution is to call component definition on the explicitly declared document type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;Dim doc = ThisApplication.ActiveDocument

Dim oCD As ComponentDefinition
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
  Dim assemDoc As AssemblyDocument = doc
  oCD = assemDoc.ComponentDefinition
ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
  Dim partDoc As PartDocument = doc
  oCD = partDoc.ComponentDefinition
End If

actBomStrucInt = oCD.BOMStructure
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:11:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7038100#M101408</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-04-24T15:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: VBA not working randomly with IPT files on my computer only</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7038636#M101409</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Link you provided is almost right (in my case at least) since we can reproduce the issue with the sequence indicated but the reversed sequence reproduces the issue randomly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my final code to prevent this issue:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;...
Dim actBomStrucInt As Integer

Dim doc = ThisApplication.ActiveDocument
Dim BOMStruc As BOMStructureEnum = Nothing

If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	Dim assemDoc As AssemblyDocument = doc
	BOMStruc = assemDoc.ComponentDefinition.BOMStructure
ElseIf doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	Dim partDoc As PartDocument = doc
	BOMStruc = partDoc.ComponentDefinition.BOMStructure
End If

actBomStrucInt = BOMStruc
...&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 18:09:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-not-working-randomly-with-ipt-files-on-my-computer-only/m-p/7038636#M101409</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-04-24T18:09:51Z</dc:date>
    </item>
  </channel>
</rss>

