<?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: iLogic Occurrence.Add or replace with CommandManager.Pick in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8316083#M83561</link>
    <description>&lt;P&gt;&lt;EM&gt;à Inventor.ComponentOccurrences.Add(String FullDocumentName, Matrix Position)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This tells me that it's failing at this line at the bottom of the loop:&lt;/P&gt;&lt;PRE&gt;oOcc = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)&lt;/PRE&gt;&lt;P&gt;If the FullFileName is correct in the message box you have coming up we don't have to worry about that.&amp;nbsp; Can you insert another message box after doing the matrix translation to see if the resulting Matrix data is correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not seeing any API that needs to be changed, maybe there's some extra VB work that has to be done before calling that Matrix.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 16:58:39 GMT</pubDate>
    <dc:creator>philip1009</dc:creator>
    <dc:date>2018-10-05T16:58:39Z</dc:date>
    <item>
      <title>iLogic Occurrence.Add or replace with CommandManager.Pick</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8315273#M83560</link>
      <description>&lt;P&gt;Hi, I have a strange behavior with some of my rules I created years ago with IV2014.&lt;/P&gt;
&lt;P&gt;The rule allow user :&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;to pick some component(s)&lt;/LI&gt;
&lt;LI&gt;Add them to a selection&lt;/LI&gt;
&lt;LI&gt;Then copy these components in pattern following user entries&lt;/LI&gt;
&lt;LI&gt;Or replace components following user entry&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;But, when adding the collection using the SelectMultiple, the command Occurrences.Add or Replace fails.&lt;/P&gt;
&lt;P&gt;The error message :&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;EM&gt;System.Runtime.InteropServices.COMException (0x80004005): Erreur non spécifiée (Exception de HRESULT : 0x80004005 (E_FAIL))&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; à System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&amp;amp; msgData)&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; à Inventor.ComponentOccurrences.Add(String FullDocumentName, Matrix Position)&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; à ThisRule.Main()&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; à Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp; à iLogic.RuleEvalContainer.ExecRuleEval(String execRule)&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;If I add a simple message box command (anywhere), it works well !!! &lt;img id="smileyindifferent" class="emoticon emoticon-smileyindifferent" src="https://forums.autodesk.com/i/smilies/16x16_smiley-indifferent.png" alt="Smiley Indifferent" title="Smiley Indifferent" /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If user select components first, then run the rule with oSelSet = oDoc.SelectSet, it works well too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happen &lt;FONT size="3"&gt;here &lt;/FONT&gt;? &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://forums.autodesk.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here an example of code :&lt;/P&gt;
&lt;PRE&gt;Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document
Dim oOcc As ComponentOccurrence
Dim oOccCol As Inventor.ObjectCollection
oOccCol = ThisApplication.TransientObjects.CreateObjectCollection

Do
	'Ask user for a selection
	oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component :")
	If Not oOcc Is  Nothing Then
	'Add component to collection
	oOccCol.Add(oOcc)
	'Set selected component inactive
	oOcc.Enabled = False
	End If
Loop While Not oOcc Is Nothing 
'Add collection to selection
oDoc.SelectSet.SelectMultiple(oOccCol)
oSelSet = oDoc.SelectSet

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
Dim Coords(2) As Double
Dim FullFileName As String

For Each oOcc In oSelSet
	'Set selected component active
	oOcc.Enabled = True
	'Get the full file name of selected occurence
	FullFileName = oOcc.Definition.Document.FullFileName
	'Get occurence coordinates
	oMatrix = oOcc.Transformation
	oMatrix.Translation.GetVectorData(Coords)'in cm
	'Copy occurence according to user parameters
	For x = 2 To 4
		'Set new matrix
		&lt;FONT color="#008000"&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;'''MessageBox.Show(FullFileName, "Title")&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
		oMatrix.SetTranslation(oTG.CreateVector( _
		Coords(0) + (x - 1) * 500 / 10, _
		Coords(1), _
		Coords(2)))
		oOcc = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
		oOcc.Grounded = True
	Next
Next&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 12:10:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8315273#M83560</guid>
      <dc:creator>ThomasB44</dc:creator>
      <dc:date>2018-10-05T12:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Occurrence.Add or replace with CommandManager.Pick</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8316083#M83561</link>
      <description>&lt;P&gt;&lt;EM&gt;à Inventor.ComponentOccurrences.Add(String FullDocumentName, Matrix Position)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This tells me that it's failing at this line at the bottom of the loop:&lt;/P&gt;&lt;PRE&gt;oOcc = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)&lt;/PRE&gt;&lt;P&gt;If the FullFileName is correct in the message box you have coming up we don't have to worry about that.&amp;nbsp; Can you insert another message box after doing the matrix translation to see if the resulting Matrix data is correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not seeing any API that needs to be changed, maybe there's some extra VB work that has to be done before calling that Matrix.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 16:58:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8316083#M83561</guid>
      <dc:creator>philip1009</dc:creator>
      <dc:date>2018-10-05T16:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Occurrence.Add or replace with CommandManager.Pick</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8318847#M83562</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1251402"&gt;@philip1009&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I've put a message box after this command line, but the FullFileName and the matrix are correct before and after...&lt;/P&gt;</description>
      <pubDate>Mon, 08 Oct 2018 07:02:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8318847#M83562</guid>
      <dc:creator>ThomasB44</dc:creator>
      <dc:date>2018-10-08T07:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Occurrence.Add or replace with CommandManager.Pick</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8318873#M83563</link>
      <description>&lt;P&gt;If I had a double Try/Catch it will work...&lt;/P&gt;
&lt;P&gt;Strangely, the error occurs, as it should not inside the Try/Catch, and the code continue to run.&lt;/P&gt;
&lt;PRE&gt;Try
oOcc = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
Catch
	Try
	oOcc = oAsmCompDef.Occurrences.Add(FullFileName, oMatrix)
	Catch
	End Try
End Try&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Oct 2018 07:16:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/8318873#M83563</guid>
      <dc:creator>ThomasB44</dc:creator>
      <dc:date>2018-10-08T07:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Occurrence.Add or replace with CommandManager.Pick</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/11012638#M83564</link>
      <description>&lt;P&gt;this deserves more likes. Works in 2020&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 21:28:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/ilogic-occurrence-add-or-replace-with-commandmanager-pick/m-p/11012638#M83564</guid>
      <dc:creator>maxim.teleguz</dc:creator>
      <dc:date>2022-03-17T21:28:35Z</dc:date>
    </item>
  </channel>
</rss>

