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: 

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

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
jdkriek
3257 Views, 3 Replies

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

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
MFG Solutions Engineer
KETIV Technologies, Inc.


3 REPLIES 3
Message 2 of 4
Mike.Wohletz
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

 

Message 3 of 4
jdkriek
in reply to: Mike.Wohletz

Thanks Mike! That works perfect.

 

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

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 4 of 4
EMiller29
in reply to: jdkriek

I'm getting the same error you are except I am trying to convert the layer and style of a dimension.... Any ideas??

 

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 9739 StartFragment: 314 EndFragment: 9707 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

ActiveSheet = ThisDrawing.Sheet("Sheet:1")

'References this document
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document

'References this drawing sheet
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oDim as DrawingDimension
Dim oDimStyle As DrawingStylesManager = oDrawDoc.StylesManager
For Each oDim In oSheet.DrawingDimensions
    If oDim.AttributeSets.Nameisused("iLogic_Created") = True Then
    oDim.Layer = ThisDrawing.Document.StylesManager.Layers("Customer")
    End If
    
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
    
If oDim.Layer = "Customer" Then
oDimStyle = ThisDrawing.Document.StylesManager.DimensionStyles.Item("KG-in")
    
End If

Next

Dim ODDoc as Inventor.Document
ODDoc=ThisApplication.ActiveDocument

ODDoc.AttributeManager.PurgeAttributeSets

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

Post to forums