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?
Solved! Go to Solution.
Solved by Mike.Wohletz. Go to Solution.
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
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