Unable to run this particular rule from External Rules at Assembly level for sheet metal parts.

Unable to run this particular rule from External Rules at Assembly level for sheet metal parts.

hamza_khan1
Contributor Contributor
492 Views
1 Reply
Message 1 of 2

Unable to run this particular rule from External Rules at Assembly level for sheet metal parts.

hamza_khan1
Contributor
Contributor

Hi there,

 

I am getting the below error When I am trying to run the Bend rule from assembly level through External Rules.

 

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: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Running this rule on part level seems to be working wothout any error, this error occurs only when it is triggered from External Rule.

 

Bend Rule:

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition

oCompDef = oPartDoc.ComponentDefinitions.Item(1)
oBendCount = oCompDef.Bends.Count
'MsgBox("Bend Total: " & oBendCount)
iProperties.Value("Custom", "No Of Bend") = oBendCount

 

 

 

External Rule:

'To run external rule for all sheet metal parts
Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
Dim iDoc As Document
For Each iDoc In aDoc.AllReferencedDocuments
If iDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then

auto = iLogicVb.Automation
auto.RunExternalRule(iDoc, ”Bend”)

iDoc.Close()
End If

Next

iLogicVb.UpdateWhenDone = True

 

0 Likes
Accepted solutions (1)
493 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Try changing the following lines:

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

to this:

Dim oPartDoc As PartDocument = ThisDoc.Document

Since the part document isn't the 'active' document, at the time you run the rule remotely, it should now be referring to the part document, and not the assembly.

OR... you could try using the iDoc.Activate method to make the part document the 'active' document, just before running the rule.

And you shouldn't need that iDoc.Close() line, since you're dealing with an assembly, because those documents will remain open (or at lease 'initiated') due to having the assembly open.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)