Showing results for 
Search instead for 
Did you mean: 

Dynamically Update Element Color

Valued Contributor
Valued Contributor

A peculiar preference of mine is coloring Tri-elements green.  It makes for easy identification for these unsightly elements. (Just as the tried and true Patran does). 


My only issue is that when I remesh geometry, the element colors based on shape do not automatically apply to the new elements.  So I have to go back and manually reset the element colors based on shape.


Is there a way to automate FEMAP into recognizing element shape and assigning it the color associated with the shape?






Re: Dynamically Update Element Color




Unfortunately for you, you've chosen a rule which hasn't yet been included in color modification schemes... What I mean is that through Modify > Element > Color > Random the available rules are "by ID", "by type" and "by group" (which is an indirect rule).

What you are looking for is "by shape" (or "by topology" for coders).


There are 2 main ways to automate FEMAP for this:

- recordable program files: you can record "Modify > Color > Element > select method(Shape)="3.. Tri, 3-noded" > the color you want"

the problem with this is that you'll have to record another one (or pile up on your recorded program) each time you want to do this on a different shape (quads, solids, 1D...etc)


- as always: API!

I wrote a few years ago a "Color by Type" macro which assigns particular colors to different element types. Rather than posting a "Color by Shape" macro, I'll explain how the macro works and what you need to do to modify it to do what you want:


the macro uses an array arranged thus:

column0 - col1 ... n

color1       - types concerned by color1



so for example, in my macro:

line0: gray (134)           - linear plates, parabolic plates

line1: white                   - linear solids, parabolic solids

line2: light gray (142)   - linear laminates, parabolic laminates



then one of the API's most awesome method is used: "addsetrule" (line44). This will fill a set using a rule. You are looking for "elements by shape", so the rule for you is "FGD_elem_byshape".

Here's an example with line0 to explain better:

- I fill a set ("typeSet") with constants which correspond to the types "linear plates" and "parabolic plates"

- by using "addsetrule", FEMAP will fill a set containing all elements which have a type which correspond to any one of the types in "typeSet"

i.e. FEMAP will return a list of all linear and parabolic plates.

- all i need to do now is change their color to the one I chose and indicated in the array (method "femodifycolor")



So basically what you need to do is

1) change the array: first write it out in front of you. then translete it to API language. The main thing is to change the rules I've used form "FET_L_PLATE" (FEMAP element type linear plate") to "FTO_TRIA3" (femap topology tria 3) for example.


you have a list of available topologies (shapes) in Help > API > > > 3.3.7 FEMAP Constants > Element Topology Types

or you can see their ID when selecting elements by shape:




Regarding color IDs, they are indicated in the palette when you select colors, next to "Current color"

you may need to adjust the array's size: cf line 12 "colorArray(6,4)", this means that my array has 7 lines and 5 columns. That is because I didn't need more! You can adjust this to any size you need.


2) modify the rule in line 44 to "FGD_elem_byshape"


If you're lost / don't want to bother with coding, post the array "written out in front of you"



Re: Dynamically Update Element Color

Valued Contributor
Valued Contributor

Thank you astrium for the detailed response.  I'm haven't dealt with API's but I'll just try out the file you posted.