02-12-2021
06:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
02-12-2021
06:47 AM
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 :
- 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)
- 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 ?