Notifications
Clear all

[Closed] Is this the best way to do this?

I want to create a script that will assign a unique material id to each element of an object.
is this the best way to do this?

  • hide all unselected objects
  • convert selected object to mesh
  • explode it with face angle set to 180; to objects
  • select all the objects in the viewport
  • assign material id modifier to all of them and set each modifier’s id to its object’s array index in the selection array.
  • convert all of them to poly
  • attach them in to one object

or is there any modifier or quick and easy way to do this?

4 Replies

I used all from this side (except last For):
http://creativescratchpad.blogspot.sk/2011/06/select-random-elements-by-percentage.html
So it s work of Vojtěch Čada.

and it is working only with polyObj:


faces = #{}
obj_faces = $.faces as bitArray
obj_faces_arr = obj_faces as array
obj_faces_count = obj_faces_arr.count

op = polyOp
getElement = op.getElementsUsingFace

elements = for i in obj_faces where obj_faces[i] == true collect
(
	element = getElement $ i
	obj_faces -= element
	element
)
For i = 1 to elements.count do
(
	polyop.setFaceMatID  $ elements[i] i
)


woow this is awesome. can someone please brake down this code for me?

faces = #{}
 obj_faces = $.faces as bitArray
 obj_faces_arr = obj_faces as array
 obj_faces_count = obj_faces_arr.count

Take faces as bitarray convert it to array. (U really do not need firs and last line from it)

op = polyOp
 getElement = op.getElementsUsingFace

He ( Vojtěch Čada ) was using “op” to chose if object is mesh or poly. I just chose to work with poly. Those two lines could be one : getElement = polyOp.getElementsUsingFace.

elements = for i in obj_faces where obj_faces[i] == true collect
 (
 	element = getElement $ i
 	obj_faces -= element
 	element
 )

Create array of arrays “elements”.
For loop: For every face ID if it is still part of “obj_faces” bittarray. Take “element” – array of faces containing in this element. Remove all thouse faces from “obj_faces” bittarray. Could be written as: “obj_faces = obj_faces – element”.
Return “element” and append (collect) to “elements”.
So U have array of arrays.

For i = 1 to elements.count do
 (
 	polyop.setFaceMatID  $ elements[i] i
 )

For loop: Change Material ID for every array of faces (i) in “elements” array.

1 Reply
(@ravihara)
Joined: 11 months ago

Posts: 0

Thanks a lot for your time!!