Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.