iLogic error "Unable to cast COM object of type"

iLogic error "Unable to cast COM object of type"

phila
Enthusiast Enthusiast
6,692 Views
4 Replies
Message 1 of 5

iLogic error "Unable to cast COM object of type"

phila
Enthusiast
Enthusiast

I started getting this error with an iLogic rule that had been working. Haven't knowingly changed anything.

 

Has anyone else had this happen and what is causing it? If so, how was it resolved?

Help would be much appreciated.

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyComponentDefinition'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{AA044AA1-D685-11D3-B7A0-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

Here is the rule

 

 'set a reference to the assembly component definition.
 'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'define View rep 
Dim oPosRep As DesignViewRepresentation 
Dim sPosRep As String
Dim MyArrayList As New ArrayList

'record the active view rep name
Dim sActiveDesignViewRep As String
sActiveDesignViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

For Each oPosRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
MyArrayList.add(oPosRep.Name)
Next

sPosRep = InputListBox("Select from the list:", MyArrayList, sActivedesignviewRep,  "View Rep Desired")

If sPosRep = "*Add a new Positional Rep*" Then
newPosRep = InputBox("Enter a name:", "iLogic", "New View Rep_" & iArrayList)
newAngle = InputBox("Enter an Angle:", "iLogic", "5")
'create New pos rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(newViewRep)
myAngle = newAngle
Else

'activate the selected View rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(sPosRep).Activate    
End If

 

0 Likes
Accepted solutions (1)
6,693 Views
4 Replies
Replies (4)
Message 2 of 5

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I do not hear any change for such usage.

 

Which release of Inventor you tested with? In 2016 at my side, I simply created a new assembly, added a rule with your code and ran it. It can work without error.  My test video is uploaded to:

https://autodesk.box.com/s/m22q8d0t91euh6b6jg91l4vetfvnxfcp

 

if this problem happened with specific assembly, please share a copy.

 

 

 

0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor
Accepted solution

Try adding an if statement to test the document type, or a try/catch:

 

If ThisApplication.ActiveDocumentType() <> kAssemblyDocumentObject
        MsgBox("You would have better luck if you ran this from an assembly document.")
        Exit Sub
End If

 

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 4 of 5

llorden4
Collaborator
Collaborator

My error stemmed from a part file used in my assembly that I had a rule automatically run with an event trigger of "File Open".  Disabling that event trigger on the part file removed my error.

Autodesk Inventor Certified Professional
0 Likes
Message 5 of 5

_KarlH
Enthusiast
Enthusiast

Too funny, this error just caught me out in a panic too. Always the simple things!!!

0 Likes