In a hose shaped part I use an external iLogic rule to determine the length of the sweep, round it and populate the value to a parameter:
'Set a reference to the active part document Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition oDef = oDoc.ComponentDefinition On Error Goto ExitEarly Dim oparams As Parameters Dim oparam As Parameter Dim exists As Boolean exists = False oparams = oDoc.ComponentDefinition.Parameters 'Find out if parameter exists For Each oparam In oparams If oparam.Name = "G_L" Then exists = True Next oparam Dim opath As Path opath = oDef.Features.SweepFeatures.Item(1).Path Dim TotalLength As Double TotalLength = 0 Dim oCurve As Object Dim i As Integer For i = 1 To opath.Count oCurve = opath.Item(i).Curve Dim oCurveEval As CurveEvaluator oCurveEval = oCurve.Evaluator Dim MinParam As Double Dim MaxParam As Double Dim length As Double Call oCurveEval.GetParamExtents(MinParam, MaxParam) Call oCurveEval.GetLengthAtParam(MinParam, MaxParam, length) TotalLength = TotalLength + length Next i Dim inc as Double inc = 50 'round up by increments of 50 mm If (TotalLength*10) < 250 Then inc = 10 'round up by increments of 10 mm If (TotalLength*10) < 100 Then inc = 5 'round up by increments of 5 mm inc=inc/10 'correction of units TotalLength = Ceil(Round(TotalLength,4)/inc)*inc 'Change the value if the parameter exists otherwise add the parameter If exists Then oparams.Item("G_L").Value = TotalLength Else oparams.UserParameters.AddByValue( "G_L", TotalLength, 11266) End If oDoc.Update Exit Sub '________________________________ ExitEarly: If exists Then oDoc.ComponentDefinition.Parameters.Item("G_L").Delete oDoc.Update
This rule is triggered whenever the part geometry is changed. This works flawlessly in the part itself, but when the part is inside an assembly and edited within that assembly, then the triggered iLogic rule results in the following error:
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D463-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). at LmiRuleScript.Main() at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Any suggestions to solve this will be appreciated!
Solved! Go to Solution.
Solved by LukeDavenport. Go to Solution.
This challenge was solved more than two years ago, but I still have a question.
In our sheet-metal parts we use an iproperty that represents an articlenumber which has to be engraved in the flatpattern. In the flat pattern I created an Emboss-feature to engrave this articlenumber. For that I used an iLogic rule that is triggered when iProperties change. This works OK when I'm in the part itself. But when I change the iproperties of the part through the BOM in the top-level assembly in which the part is, this same error is generated, even when I change the PartDoc = ThisApplication.ActiveDocument to PartDoc = ThisApplication.ActiveEditDocument statement. I've added a Trace.WriteLine command in which I can detect what the ActiveEditDocument is at the time the rule triggers, and for both options (ActiveDocument or ActiveEditDocument) it shows the document which is active at that moment which is the top-level assembly in this case, not the part that's being edited.
How can I let the (local) iLogic rule run correctly when editing iProperties from the top-level BOM inside an assembly?