Hello,
I am trying to get the color "Magenta" in the following code but I do not know which index I need to insert to get it.
Writing string: Item("Magenta") does not seem to work.
The original code is in the link below and there is a string used to define the color but it does not seem to work for all colors:
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "") Exit Sub End If Dim oPDoc As PartDocument = ThisDoc.Document oPDef = oPDoc.ComponentDefinition 'try to find/get the named face Dim oNEs As NamedEntities = iLogicVb.Automation.GetNamedEntities(oPDoc) Dim oOutsideFace As Face = oNEs.FindEntity("OWH1") If IsNothing(oOutsideFace) Then MsgBox("Could not find a face named 'OWH1'.", vbCritical, "") Return End If 'try to get the 'Appearance Assets Magenta Dim oDocAppAssets As AssetsEnumerator = oPDoc.AppearanceAssets Dim oLibAppAssets As AssetsEnumerator oLibAppAssets = ThisApplication.ActiveAppearanceLibrary.AppearanceAssets Dim oMagenta As Asset Try oMagenta = oDocAppAssets.Item(13) <---- ?? Catch oMagenta = oLibAppAssets.Item(10) Catch MsgBox("Could not find Appearance Asset named 'Magenta'.", vbCritical, "") Return End Try oOutsideFace.Appearance = oMagenta
Tom
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @tomislav.peran. You need to either find or create that 'appearance' before you can retrieve it within the code. This code sample is only looking in two places for that appearance, but there are other possible places that it could be found, so the sources may need to be changed, or you may need to take another manual step to prepare for using this code. If there is not a 'local copy' (saved within that document) of that appearance, then it must be found in one of the asset libraries. If it is not in the 'active' appearance library, then you will have to either find which library it is in, then set that one to the 'active' one, or you will need to look for that specific library within the code, instead of the 'active' library. Either way, a local copy of the appearance must be made, before it can be used.
Wesley Crihfield
(Not an Autodesk Employee)
Another good practice for stuff like this is to create a separate feedback routine, that will look at each one's 'Name' &/or 'DisplayName', and either show them to you in a message, or put them in a list, then show the list to you, so that you know not only which ones are available, but what the different versions of their names may look like, from the code perspective. The 'DisplayName' may change from one environment/language pack to another, but the 'Name' value should always stay the same. However, the 'Name' value may not always be exactly what you are expecting, because you usually only see the value of the 'DisplayName'.
Wesley Crihfield
(Not an Autodesk Employee)
Hi WCrihfield,
I have updated the code following your post. All I have to do is add Magenta color to my part, at least temporarily, to add it to the library of used colors on a part:
Dim oDocAppAssets As AssetsEnumerator = oPDoc.AppearanceAssets
I can check what colors I have with the following code:
Dim oColors As New List(Of String) For Each oColor In oDocAppAssets oColors.Add(oColor.DisplayName) Next MultiValue.List("Appearances") = oColors
Just to check if I understood your first post I need to make a local copy of the color, or in other words, use the color on a part otherwise It will not work? Because there is a whole library of colors that I have in every file.
I am a bit lost here with colors :D. In any case, the suggestion to make a Multivalue parameter to identify colors definitely helps.
Tom
Hi @tomislav.peran. When you click that little drop-down list on the 'Quick Access Toolbar' for appearances, that is showing you the list of appearances available within the currently 'active' appearances library, not necessarily which appearances there are 'local' copies of (within that document). To see which ones you have local copies of in your document, click the Appearance icon (looks like a colored pie chart icon, with no other little icon on it).
When you click that, it will show the 'Appearances Browser' dialog. In the top portion of that dialog you will see an area labeled 'Document Appearances'. That will contain any appearance you may have applied to anything within that part, even if you are no longer using that appearance for anything anymore. You can usually delete any of those that you are no longer using, to help clean up the document. Then in the lower area you will see a huge amount of other appearances. Those will be representing what is available in one of the 'libraries'. You may see a structured tree of stuff to the left of those appearances, similar to the model browser, only this is the appearance library browser. You can select one of the other libraries over there to see what appearances are available within it to the right. When you right-click on one of those appearances in that lower right area, you can choose to either 'Assign to selection' or 'Add to' > 'Document Materials'.
Wesley Crihfield
(Not an Autodesk Employee)
Ok, got it. Those on the top are local copies that I use in the code. Now I understand. Indeed bunch of those should be deleted in my case.
Thanks a lot!
Edit: Useful link on how to copy assets from a library to a file, or in other words, make them local
Can't find what you're looking for? Ask the community or share your knowledge.