Hi all,
I have an assembly of several parts.
I derive this into a part and make the color "yellow".
I now change the color of one of the faces to "Black"
I then want to run a rule and get the 'area' of both the colored black faces and the faces that are colored "yellow"
I have this code below.
It works well if the derived part is of an assembly that contains only 1 part. If there are multiple parts in the assembly, then when it is derived into a part, the color changed and the rule ran, it only gives me an output of the derived part, in my case "yellow". Can anyone show me where I am going wrong pls?
Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oFaces As Faces oFaces = oPartDoc.ComponentDefinition.SurfaceBodies(1).Faces Dim Colors As Object Colors = CreateObject("Scripting.Dictionary") Dim oFace As Face For Each oFace In oFaces Colors(oFace.Appearance.DisplayName) = Colors(oFace.Appearance.DisplayName) + oFace.Evaluator.Area Next For Each Item In Colors MessageBox.Show("Color: " & Item & vbLf & "Area: " &Colors(Item) & "cm^2", "Surface Area by Color") Next
Solved! Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by JelteDeJong. Go to Solution.
I think I need to cycle through each solid body within the derived part and find the color of the faces within those bodies? It seems that when the code is run; it checks only the first solid body, reports the color to the message box, then exits the code. Can anyone provide some help how to do that. I have no hair left now ))
try this:
Dim doc As PartDocument = ThisDoc.Document
For Each body As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
For Each face As Face In body.Faces
Dim color = Face.Appearance.DisplayName
Dim area = Face.Evaluator.Area
Logger.Info(String.Format("Color: {0} - Area: {1} cm^2", color, area ))
Next
Next
Info is written to iLogic log.
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Hi @bob_clark5J5M8 . You can also use my free app that calculates the color area and changes the color in the assembly.
An update to the application will be released soon, which will increase the functionality and stability of the application.
Andrii Humeniuk - Leading design engineer
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi Andrii, Thank you very much for sharing. In my case I needed to run it in part mode, so a derived part or shrinkwrap was best for me. 🙂
Can't find what you're looking for? Ask the community or share your knowledge.