- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
In a part file, I am trying to control and switch the color of certain faces through a view representation. I made a manual process for this and now trying to create a rule in iLogic to automate this procedure. See pdf for the step-by-step.
Anyway, I believe I need the pick(k...filter) function in order for this work but I cannot figure how to write the function to select faces on a part file. I have only seen this command be applied in assembly files for part instances. I managed to put this together so far. Can someone explain how to use this function to select multi faces and change the color of those faces in a part file?
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition
Dim oFeature As PartFeature
For Each oFeature In oPartDoc.ComponentDefinition.Features
Feature.Color(oFeature.Name)="As Part"
Next
'Step 2 : part i cannot figure out. It will be something like:
' This.Application.CommandManager.Pick ( k...Filter, "Select the face")
oPartDef.RepresentationsManager.DesignViewRepresentations.Add("Red Surfaces")
Dim oColor As RenderStyle
oColor = oPartDoc.RenderStyles.Item("4-Red")
oPartDoc.ActiveRenderStyle = oColor
Regards,
Anthony
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Not sure if the Part environment is different, but this is what I use for assemblies.
ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Select the face")
Currently I'm on the hunt for a kParallelPlaneFilter if anyone happens to know the syntax for that
Thanks,
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am still fiddling with mine. It looks like kAllPlanarEntities will highlight a face but it crashes when I attempt to apply a color to the face so I am not sure yet it is the command or if something else is wrong with my code.
Maybe try kWorkPlaneFilter.
I did not know about this tool at the time of my original post but enter the VBA editor in Inventor (you can find it under tools or type in the search bar) . Then press F2 and type kfilter into the search bar. If I had to guess the kSketchBlockFilter member is the most relevant but it looks like kWorkPlaneFilter exist in all the members.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Here's a small iLogic Rule that will change the color of Faces as you select them.
SyntaxEditor Code Snippet
Public Sub Main() Dim oFace As Face 'Copy the asset from the library to this document Dim localAsset As Asset = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library").AppearanceAssets.Item("Bamboo").CopyTo(ThisDoc.Document, True) 'Keep Selecting Faces, Hit Esc to finish Do oFace = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Pick a feature") If Not oFace Is Nothing Then oFace.Appearance = localAsset End If Loop While Not oFace Is Nothing End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you, this code will work for my purposes but I noticed a couple of things that maybe of value to point out.
1. As the name would suggest, SelectionFilterEnum.kAllPlanarEntities will only work flat planes. I ended up switching it to SelectionFilterEnum.kPartFaceFilter in order to be able to also select curved surfaces.
2. For an asset, .CopyTo will fail if it you copy to a location that already exist. In other words, you can only run this rule only once with a particular apperance asset. I have not implemented it yet but looking at the help page on asset objects, I think would need to have a delete asset method prior to the CopyTo and use the IsUsed property as a condition to make sure it exist.
Sorry if this is off topic but originally I planned to set the appearance to "As Feature", "As Body, etc. These options exist when when you right-click and go to properties but they do not exist in the Appearance Browser. I also confirmed that I cannot CopyTo As Body. It is like "As Feature" and "As Body" are sometimes grouped with appearance assets but at the same time they do not seem to be treated as appearance assets because it is not something that will be in the library and they do not work in the code. Are they Appearance Assets? If not, what are they and what member are they associated with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I like the code.
Also, I like to expand the idea for components in an assembly document: i.e. to keep selecting some components until done.
When the rule is done, selected parts must be available (as selected using Ctrl+V) for further processing.
I appreciate your help.