IPT iLogic Rule error while in IAM

IPT iLogic Rule error while in IAM

pedronicolosi
Explorer Explorer
275 Views
2 Replies
Message 1 of 3

IPT iLogic Rule error while in IAM

pedronicolosi
Explorer
Explorer

Hey everyone!

 

Recently I added this rule to my ipt sheet template (I found this rule here, at Autodesk Knowledge).

 

Dim oSMDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSMDef As SheetMetalComponentDefinition = oSMDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
Return
End If
Dim oTopFace As Face = oSMDef.FlatPattern.TopFace
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double = 0
For Each oEdgeLoop As EdgeLoop In oTopFace.EdgeLoops
oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
Next

iProperties.Value("Custom", "CONTORNOTOTAL") = Round(oLoopLength*10)

 

Inside the IPT template, this rule is working fine! No problems at all!

 

But, if I add the IPT with this rule to a IAM enviroment and save it, it gives me this error in rule:

 

ERROR MESSAGE

 

Error in rule: CONTORNOTOTAL, in document: Peça6.ipt

Unable to cast COM object of type 'Inventor._DocumentClass' 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: There is no support to this interface (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

MORE INFO

 

System.InvalidCastException: Unable to cast COM object of type 'Inventor._DocumentClass' 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: There is no support to this interface (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Does anyone knows the cause of it and how to fix it?

 

 

Thanks!!

0 Likes
Accepted solutions (1)
276 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

The problem is in your first line. in an assembly it will set the oSmdoc to the assembly instead of the part. try it like this:

Dim oSMDoc As PartDocument = ThisDoc.Document
Dim oSMDef As SheetMetalComponentDefinition = oSMDoc.ComponentDefinition
If oSMDef.HasFlatPattern = False Then
    MsgBox("There is no Flat Pattern yet.", vbOKOnly, "NO FLAT PATTERN")
    Return
End If
Dim oTopFace As Face = oSMDef.FlatPattern.TopFace
Dim oMeasureTools As MeasureTools = ThisApplication.MeasureTools
Dim oLoopLength As Double = 0
For Each oEdgeLoop As EdgeLoop In oTopFace.EdgeLoops
    oLoopLength = oLoopLength + oMeasureTools.GetLoopLength(oEdgeLoop)
Next

iProperties.Value("Custom", "CONTORNOTOTAL") = Round(oLoopLength * 10)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

pedronicolosi
Explorer
Explorer

thanks for your help, @JelteDeJong !!

 

it worked pretty well!! 🤜🤛

0 Likes