How to select multiple polygons by material ID

How to select multiple polygons by material ID

Anonymous
Not applicable
4,973 Views
8 Replies
Message 1 of 9

How to select multiple polygons by material ID

Anonymous
Not applicable
Hello-

I am wondering if anyone knows how I can simplify a process.

I have a model with duplicate materials in multi/sub-object material, but the materials have different names.

What I want to do is select those Material IDs and assign them the same ID.

From the Listener:

$.EditablePoly.selectByMaterial 7
$.EditablePoly.setMaterialIndex 5
$.EditablePoly.selectByMaterial 71
$.EditablePoly.setMaterialIndex 5
$.EditablePoly.selectByMaterial 72
$.EditablePoly.setMaterialIndex 5
$.EditablePoly.selectByMaterial 73
$.EditablePoly.setMaterialIndex 5
$.EditablePoly.selectByMaterial 74
$.EditablePoly.setMaterialIndex 5
$.EditablePoly.selectByMaterial 75
$.EditablePoly.setMaterialIndex 5

If I know the IDs I want to change, can I input them all at once (i.e 80, 81, 82, 83, 84, etc...)?

Thanks for the help!
0 Likes
4,974 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Have you tried with a for loop. If your matID's are in order you can do something like this:

for i = 70 to 85 by 1 do 
(
$.EditablePoly.selectByMaterial i
$.EditablePoly.setMaterialIndex 5
)
0 Likes
Message 3 of 9

barigazy
Enthusiast
Enthusiast

...
What I want to do is select those Material IDs and assign them the same ID.
...
If I know the IDs I want to change, can I input them all at once (i.e 80, 81, 82, 83, 84,

You not need to select first this faces to be able to set new mtlID.
That process is slow.
This function will do the job.(works only with editable poly objects)

fn findAndSetMtlID obj findIDs: newID: selectFaces: = if isKindOf obj Editable_Poly do
(
local getfaceID = polyop.getFaceMatID
local facesList = #{}
for f in obj.faces as bitarray where finditem findIDs (getfaceID obj f) != 0 do append facesList f
if facesList.numberset != 0 then polyop.setFaceMatID obj facesList newID else false
if selectFaces == on do obj.selectedfaces = facesList
)
mtlArr = #(75,76,77,78,79,80)
findAndSetMtlID $ findIDs:mtlArr newID:5 selectFaces:off
0 Likes
Message 4 of 9

Anonymous
Not applicable
Thanks guys-

I will give these methods a try.

I appreciate the help!

-Jonny5isAlive
0 Likes
Message 5 of 9

Anonymous
Not applicable

Hello;

 

I'm interrested by this post. My issue is : i have a hunded of CivilView cars in my model. CivilView car have a multi/subobject material depending on the model of the car.

If i poly edit a car i can select the body of the car simply by clicking the sub material in the Polygons Material IDs lists (just below set ID). I'd like to fetch this material list butr i can't find the command.

 

Capture.PNG

 

Thanks for help

0 Likes
Message 6 of 9

denisT.MaxDoctor
Advisor
Advisor

this list of id - name corresponds to the list of submaterial names of the applied multimaterial. which can be accessed as:

 

$.material.names

 

 

PS. the order of names in the material names and poly-id name list can be different. As far as I remember, for poly it is always ascending order of ids. For material, name order corresponds to the order in the list of id, which can be anything.

see:


$ .material.materialIDList

 

0 Likes
Message 7 of 9

Anonymous
Not applicable

Thanks Denis. Unfortunatly it's not the solution.

A CivilView car material consist in 26 submaterials. The first 9 are different body colors, they are the ones i want to play with.

I need to access the used submaterial list which i can find in the polygons material IDs section.

 

Annotation 2020-09-04 110553.png

The function you gave me sends me back the whole list of submaterials.

 

I attach an exemple file of CivilView cars.

0 Likes
Message 8 of 9

denisT.MaxDoctor
Advisor
Advisor

Some of us have misunderstood something ...

I repeat once more -

to get the Editable_Poly object's id names list, you need to ask the applied multi-material name list. The index of the name corresponds to the index in the Material ID list.

Thus, if you know the name of the sub material and use what I explained above, you can select faces as the following:

fn selectByMaterialName poly name = 
(
	if iskindof poly Editable_Poly and iskindof (mat = poly.material) MultiMaterial do
	(
		if (k = finditem mat.names name) > 0 do
		(
			id = mat.materialIDList[k]
			poly.selectByMaterial id clearCurrentSelection:on
		)
	)
)

/* 
selectByMaterialName poly name
*/

 

where poly is the current edit object and the face sub-object selection level used

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

Thanks Denis. I found a workaround. But i'll try your function.

0 Likes