iLogic Occurrence.Add or replace with CommandManager.Pick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I have a strange behavior with some of my rules I created years ago with IV2014.
The rule allow user :
- to pick some component(s)
- Add them to a selection
- Then copy these components in pattern following user entries
- Or replace components following user entry
But, when adding the collection using the SelectMultiple, the command Occurrences.Add or Replace fails.
The error message :
System.Runtime.InteropServices.COMException (0x80004005): Erreur non spécifiée (Exception de HRESULT : 0x80004005 (E_FAIL))
à System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
à Inventor.ComponentOccurrences.Add(String FullDocumentName, Matrix Position)
à ThisRule.Main()
à Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
à iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
If I add a simple message box command (anywhere), it works well !!!
If user select components first, then run the rule with oSelSet = oDoc.SelectSet, it works well too.
What happen here ?
Here an example of code :
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 '''MessageBox.Show(FullFileName, "Title") 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
Thomas
Mechanical Designer / Inventor Professional 2025