Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
PCP7
in reply to: Curtis_Waguespack

Hey, I used your code to change the color of selected faces, but it only works if I run it within the part. If I try to run it from the assembly where components are used it gives me following error :

 

System.InvalidCastException: 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)).
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

CODE USED :

 

  1. Inside part : 

    Dim oDoc As PartDocument 
    oDoc = ThisApplication.ActiveDocument
    
    'get color name to use
    Dim oColor As String
    oColor = "Black"
    
    Dim oAssetLib As AssetLibrary
    oAssetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
    
    ' Get an asset in the library
    Dim oLibAsset As Asset
    oLibAsset = oAssetLib.AppearanceAssets.Item(oColor)
    
    
    Dim oLocalAsset As Asset
    Try 'Copy the asset locally.
    	oLocalAsset = oLibAsset.CopyTo(oDoc)
    Catch 'or just use it if it's already local
    	oLocalAsset = oDoc.Assets.Item(oColor)
    End Try
    
    
    Dim oEntities As Object 
    oEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
    
    'get the named face
    Dim oFace1 As Face 
    Dim oFace2 As Face 
    oFace1 = oEntities.FindEntity("Tail A1")
    oFace2 = oEntities.FindEntity("Tail A2")
    
    oFace1.Appearance = oDoc.Assets.Item(oColor)
    oFace2.Appearance = oDoc.Assets.Item(oColor)
  2. From assembly:

    iLogicVb.RunRule("INSIDE RAIL", "Tail A")
    iLogicVb.RunRule("OUTSIDE RAIL", "Tail A")

    Is there a way to make it run from the assembly ?