Inventor Customization

Inventor Customization

Reply
*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 1 of 3 (669 Views)
Accepted Solution

Unable to cast COM object to System.String (iLogic)

669 Views, 2 Replies
03-15-2012 11:24 AM

What I'm trying to do is detect if a Sweep exists - any sweep, not just a specific name (that part works) and then run an iLogic rule if it does. But when I convert to a string to do Feature.IsActive(), then it gives me a "Unable to cast COM object" error. 

 

'Ref the part
Dim oDoc As Inventor.Document oDoc = ThisApplication.ActiveDocument Dim oDef As PartComponentDefinition
'Find the sweep, reguardless of name, and ref it Dim oSweep As SweepFeature oSweep = oDef.Features.SweepFeatures.Item(1)
'This line is throwing the error, because it doesn't like being a string If Feature.IsActive(oSweep) Then iLogicVb.RunRule("CalcSweep") Else 'Do something End If

 

Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

How can I make this work?

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

try this out. 

 

 'Ref the part
Dim oDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
'Find the sweep, reguardless of name, and ref it
Dim oSweep As SweepFeature = oDef.Features.SweepFeatures.Item(1)
If Feature.IsActive( oSweep.Name) Then
iLogicVb.RunRule("CalcSweep")
Else
'Do something
End If

 

Valued Mentor
Mike.Wohletz
Posts: 376
Registered: ‎07-29-2008
Message 2 of 3 (651 Views)

Re: Unable to cast COM object to System.String (iLogic)

03-15-2012 06:54 PM in reply to: jdkriek

try this out. 

 

    'Ref the part
        Dim oDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
        Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
        'Find the sweep, reguardless of name, and ref it
        Dim oSweep As SweepFeature = oDef.Features.SweepFeatures.Item(1)
        
        If Feature.IsActive( oSweep.Name) Then
            iLogicVb.RunRule("CalcSweep")
            Else
            'Do something
        End If

 

*Expert Elite*
jdkriek
Posts: 528
Registered: ‎03-29-2007
Message 3 of 3 (645 Views)

Re: Unable to cast COM object to System.String (iLogic)

03-16-2012 05:29 AM in reply to: Mike.Wohletz

Thanks Mike! That works perfect.

 

Makes sense as well, now that I can see the flow.

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.