ScriptSpot

Forum topic · General Scripting

Wirecolor script hep needed.

By amitananddey@gmail.com · 2011-08-25

Description

Hi friends,I am trying to do a script that toggles from a required color to previously assigned color .
For example

for i in geometry do
(
if i.wirecolor != black then
(
i.wirecolor = color 0 0 0
)else
(
--this should get the same wirecolor applied before running the script.
)
)

I am a neewbie in this field.And have got very limited knowledge.Hope to get help for my problem.

Comments (2)

br0t · 2011-08-26

I've written something similar for materials once, so it was easy to adjust. You have to store the original wirecolors in an array. I wrote some comments into the script, hope it helps:


try(DestroyDialog ro_toggleWirecolors)catch()
rollout ro_toggleWirecolors "Wirecolors" width:151 height:34
(
	local theSel = #() --will hold the unique node handle of the selected objects and their original wirecolor
	
	checkButton ckb_toggle "Toggle Wirecolors" pos:[31,2] width:118 height:30
	colorPicker cp_targetColor "" pos:[-3,2] width:32 height:30 color:black
	
	on ckb_toggle changed state do 
	(
		if state then --if button is checked...
		(
			theSel = for s in selection collect (#(s.inode.handle, s.wirecolor)) --fill the array with the handles and colors
			selection.wirecolor = cp_targetColor.color --apply one color to all selected objects
		)--end if
		else --if button is unchecked...
		(
			for i in theSel do
			(
				theNode = maxOps.getNodeByHandle i[1] --get the originally selected nodes by using their unique node handle
				if theNode != undefined do theNode.wirecolor = i[2] --make sure to check if the node still exists, to avoid a crash if it has been deleted; reassign original wirecolor
			)
			theSel = #() --reset the array
		)--end else
	)--end on
)
CreateDialog ro_toggleWirecolors

amitananddey@gmail.com · 2011-08-30

Thanks a lot for spending your valuable time.I appreciate your effort in explaning it very clearly.Thanks a lot again.