Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic error when triggered in a part within an assembly

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
viavacvacuumlifting
606 Views, 4 Replies

iLogic error when triggered in a part within an assembly

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!

 

4 REPLIES 4
Message 2 of 5

Try changing ThisApplication.ActiveDocument to
ThisApplication.ActiveEditDocument
in the first line. At the moment you are trying to declare an assembly
document as a part document. Does that work?

Luke
Message 3 of 5

Thanks!

That worked (and made sense...)

Message 4 of 5

Excellent!

Message 5 of 5
miechh
in reply to: LukeDavenport

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?


Product Design Suite 2024
Inventor 2024 (v 28.20.27200.0000), Vault Basic 2024
Fusion 360
HP Workstation Z4
Intel Xeon 3.4GHz
32GB RAM
Windows 10 Professional (64bit)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report