- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I'm using the API to control Inventor with a Windows Forms application I built in VisualStudio. The program simply launches Inventor and uses data from an external source to change parameters in a given Inventor assembly. The Inventor assembly contains an iLogic rule that overrides the display color of all components in an assembly based on a parameter value.
This is the code I'm using to change the color. It works just fine when I open the document manually and change the parameter.
'get the assembly document
Dim myAssembly As AssemblyDocument = ThisDoc.Document
'set the desired display color
Dim displayColor As String = "Light Gray" 'I get this value from a parameter. This is simply an example.
'get the correct library from Inventor
Dim oAssetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Inventor Material Library")
'choose that display color asset from the library
Dim oColorAsset As Asset = oAssetLib.AppearanceAssets.Item(displayColor)
'get the color asset. Copy it locally as needed
Dim oLocalAsset As Asset
Try 'Copy the asset locally.
oLocalAsset = oColorAsset.CopyTo(ThisDoc.Document)
Catch 'or just use it if it's already local
oLocalAsset = ThisDoc.Document.Assets.Item(displayColor)
End Try
'change the color (appearance) of each component occurrence in the assembly
For Each oOcc As ComponentOccurrence In myAssembly.ComponentDefinition.Occurrences
oOcc.Appearance = oLocalAsset
Next
However, I am using the Windows Forms application to open a new instance of Inventor, open the assembly, and change the parameter values. When I do that, the iLogic rule runs into an error at this line:
Dim oAssetLib As AssetLibrary = ThisApplication.AssetLibraries.Item("Inventor Material Library")
With some more debugging, I was able to discover that Inventor has not yet loaded this library. In other words, the library is not attached to Inventor after the API launch.
I am not sure if it is supposed to load this library after it opens a document or at Inventor launch.
I tried to use a try-catch block with the ThisApplication.AssetLibraries.Add("filename") command inside the catch statement, but that threw an error as well...
Is there a way to use the API to wait for Inventor to load this asset library before continuing with the program?
Solved! Go to Solution.