Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find area of faces by color

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
bob_clark5J5M8
305 Views, 5 Replies

Find area of faces by color

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

 

5 REPLIES 5
Message 2 of 6

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 )) 

Message 3 of 6

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.

EESignature


Blog: hjalte.nl - github.com

Message 4 of 6

Perfect, thanks 🙏🙏🙏

Message 5 of 6

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.

EESignature

Message 6 of 6

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.

Post to forums  

Technology Administrators


Autodesk Design & Make Report