Announcement

Collapse
No announcement yet.

looking for a script !!! Please help...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • looking for a script !!! Please help...

    Hello Guys,

    I'm looking for a script...

    I want to select objects and create a multisub material (without attaching the objects...).


    Best regards...
    My Flickr

  • #2
    Code:
    myobjs = $
    combined_material = Multimaterial count:myobjs.count name:"combined_material"
    for i = 1 to myobjs.count do
    (
    mymodifier = (Materialmodifier ())
    mymodifier.materialID = i
    addmodifier myobjs[i] mymodifier
    combined_material.mapenabled[i] = on
    combined_material.materialIDList[i] = i
    combined_material.names[i] = myobjs[i].material.name
    combined_material.material[i] = myobjs[i].material
    myobjs[i].material = combined_material
    )
    better save your scene first... it adds a material modifier to your selected objects (no errorchecking if anything else than geometry is selected) and creates a multisub with instances of the original material in it. did not put that to the medit, gotta pick it yourself

    regards,
    michael
    This signature is only a temporary solution

    Comment


    • #3
      Originally posted by Sushidelic

      better save your scene first... it adds a material modifier to your selected objects (no errorchecking if anything else than geometry is selected) and creates a multisub with instances of the original material in it. did not put that to the medit, gotta pick it yourself

      regards,
      michael
      Ok, thank you very much but I'm looking for a script able to do this enevn if there is an existing multi/sub on selected object...

      I don't know if I'm very clear...

      Best regards...
      My Flickr

      Comment


      • #4
        Ok here is a quick one. No checking for invalid selection:

        Code:
        (
        	sel = selection as array
        	mat = multimaterial numsubs:(sel.count)
        	for i=1 to sel.count do
        	(
        		m = materialmodifier()
        		m.materialID = i
        		addmodifier sel[i] m
        		mat.names[i] = sel[i].name
        		sel[i].material = mat
        	)
        )
        Just select your objects and it will create the multisub and apply it.

        Best regards,
        Daniel
        Daniel Santana | Co-Founder / Technical Director
        You can do it! VFX
        Lisbon/Porto - Portugal
        http://www.ycdivfx.com

        Comment


        • #5
          I'm assuming you want to create a multi-sub material that contains all of the materials in your selection AND changes the face ID of your objects to match.

          As a warning - I am rubbish at scripting, so I simply don't know how to do what you want without collapsing the objects to a mesh (to change the ID). It could probably be done by adding an edit mesh modifier & making the changes to the face ID's in that, but again... I am rubbish.

          So, here's my quick script that *might* do what you want... (But will most likely just crash).

          Hope it's of any help!

          Code:
          matstore = #()
          matnum = selection.count
          mm = multimaterial numsubs:matnum
          for i in selection do (append matstore i.material)
          converttomesh selection
          for i = 1 to matnum do 
          	(
          	for s = 1 to selection[i].numfaces do 
          		(
          		setfacematID selection[i] s i
          		)
          	mm[i] = matstore[i]
          	)
          selection.material = mm
          MDI Digital
          moonjam

          Comment


          • #6
            Originally posted by stilgarna

            Ok, thank you very much but I'm looking for a script able to do this enevn if there is an existing multi/sub on selected object...
            Hihi,

            this makes things more complicated
            But let's accelerate development a little bit...
            I bet Sushidelic can't do this in under 30 minutes....
            Time runs...

            Best regards,

            Dieter
            --------
            visit my developer blog

            Comment


            • #7
              gimme some more minutes, gotta output a fusion comp first
              This signature is only a temporary solution

              Comment


              • #8
                Originally posted by dgsantana
                Ok here is a quick one. No checking for invalid selection:

                Just select your objects and it will create the multisub and apply it.

                Best regards,
                Daniel


                Sorry it doesn't work, wath I want to do is creating an only one multi/sub with selected object... And some of this object have a Multi/Sub assigned...
                My Flickr

                Comment


                • #9
                  Originally posted by AJ_23
                  I'm assuming you want to create a multi-sub material that contains all of the materials in your selection AND changes the face ID of your objects to match.

                  As a warning - I am rubbish at scripting, so I simply don't know how to do what you want without collapsing the objects to a mesh (to change the ID). It could probably be done by adding an edit mesh modifier & making the changes to the face ID's in that, but again... I am rubbish.

                  So, here's my quick script that *might* do what you want... (But will most likely just crash).

                  Hope it's of any help!

                  Sorry it doen't work... He create a multisub with multisub inside...

                  Best regards...
                  My Flickr

                  Comment


                  • #10
                    try this
                    Code:
                    (
                    	maxindex = 0
                    	sel = selection as array
                    	mat = multimaterial numsubs:(sel.count) 
                    	-- first pass
                    	for i=1 to sel.count do
                    	(
                    		m = edit_mesh()
                    		m.name = "TmpModifi"
                    		addmodifier sel[i] m
                    		for j=1 to sel[i].numfaces  do
                    		(
                    			mtindex = getFaceMatID sel[i] j
                    			if mtindex > maxindex then maxindex = mtindex
                    		)
                    	)
                    	-- second pass
                       for i=1 to sel.count do
                       (
                          m = materialmodifier()
                          m.materialID = maxindex + i
                          addmodifier sel[i] m
                          mat.names[i] = sel[i].name
                    	  mat.materialIDList[i] = maxindex + i
                    	  mat.materialList[i] = sel[i].material
                          sel[i].material = mat
                       ) 
                    )
                    Daniel Santana | Co-Founder / Technical Director
                    You can do it! VFX
                    Lisbon/Porto - Portugal
                    http://www.ycdivfx.com

                    Comment


                    • #11
                      Originally posted by dgsantana
                      try this
                      Hello Thanks...

                      But I'm sorry the script put all the multisud of each object into a new multisub...

                      On each ID of the new multisub I found others multiSub...


                      Best Regards....
                      My Flickr

                      Comment


                      • #12
                        Yes only after putting the last script did i had an idea on how to make this work. it will take a while to make the necessary changes.

                        best regards,
                        daniel
                        Daniel Santana | Co-Founder / Technical Director
                        You can do it! VFX
                        Lisbon/Porto - Portugal
                        http://www.ycdivfx.com

                        Comment


                        • #13
                          Originally posted by dgsantana
                          Yes only after putting the last script did i had an idea on how to make this work. it will take a while to make the necessary changes.

                          best regards,
                          daniel

                          Ok i'll wait...

                          For now I'll do it with my hands... but I hope you can find the answer...


                          Best regards and thank you to all of you guys...



                          PS : Sorry my english sucks !!!
                          My Flickr

                          Comment


                          • #14
                            Sorry for the delay, but this one should work. The only side effect is collapsing the modifier stack for objects with multisubs.

                            Code:
                            ( 
                               mtlindex = 0
                               mtllist = #()
                               mtlname = #()
                               mtlcount = #()
                               sel = selection as array
                               mat = multimaterial numsubs:10
                               -- first pass 
                               for i=1 to sel.count do 
                               ( 
                               		if (classof sel[i].material) == multimaterial then
                               		(
                            	   		selmtlcount = 0
                            			selindex = #()
                            	   		tindex = mtlindex
                            	   		md = edit_mesh() 
                            		    md.name = "MultMat" 
                            		    addmodifier sel[i] md
                            			addmodifier sel[i] (mesh_select())
                            			collapseStack sel[i]
                            		    for j=1 to sel[i].numfaces  do 
                            		    ( 
                            		       facindex = getFaceMatID sel[i] j
                            		       found = finditem selindex facindex
                            		       if found != 0 then (setFaceMatID sel[i] j (tindex + found))
                            		       else
                            		       (
                            		       		mtlindex += 1
                            		       		append selindex facindex
                            		       		setFaceMatID sel[i] j mtlindex
                            		       )
                            		    )
                            		    append mtlcount (selindex.count)
                            		    for j=1 to selindex.count do
                            		    (
                            		    	found = finditem (sel[i].material.materialIDList) selindex[j]
                            				if found == 0 then append mtllist (NoMaterial())
                            		      	else append mtllist (sel[i].material.materialList[found])
                            				append mtlname (sel[i].name + "_" + (j as string))
                            		    )
                               		)
                               		else
                               		(
                               			mtlindex += 1
                               			append mtllist (sel[i].material)
                               			append mtlcount 1
                            	      	md = materialmodifier() 
                            	      	md.name = "MultMat"
                            	      	md.materialID = mtlindex
                            	      	addmodifier sel[i] m
                            			append mtlname (sel[i].name)
                                	)
                                	sel[i].material = mat
                               )
                               mat.numsubs = (mtllist.count)
                               -- second pass 
                               for i=1 to mtllist.count do 
                               (
                                    mat.names[i] = mtlname[i] 
                                 	mat.materialIDList[i] = i 
                                	mat.materialList[i] = mtllist[i]
                               ) 
                            )
                            Best regards,
                            Daniel
                            Daniel Santana | Co-Founder / Technical Director
                            You can do it! VFX
                            Lisbon/Porto - Portugal
                            http://www.ycdivfx.com

                            Comment


                            • #15
                              Originally posted by dgsantana
                              Sorry for the delay, but this one should work. The only side effect is collapsing the modifier stack for objects with multisubs.



                              Best regards,
                              Daniel


                              YYYYEEEEEEAAAAAAAAA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


                              It's working !!!!
                              Very nice...



                              Many many thanks....
                              I put your name on my "wonderful guy's list" !!!!


                              Just one more think... Is it possible to keep instances ???

                              Best regards and a big thank you !!!!
                              My Flickr

                              Comment

                              Working...
                              X