I need some help.

Hallo.

The script writen below creates layers by a base name via sub-names defined in script. To create layers at least one checkbox should be checked to enter a word in edittext line.I add a function to the script to block edittext line until a checkbox was checked but only last checkbox doing what I need.

I need to your help to fix this issue.
Thanks

--- LayerCreator 1.0 ---
 
--- Globals for script ---
 
global lyrDefNames  
global lyrNames
 
--- Define globals---
 
lyrDefNames=#() 
lyrNames=#()
 
---The function to create layers---
 
fn crtNewLayer =
(  
	for n = 1 to lyrNames.count do
		(  
		   i= n
		   x= lyrNames 
		   y= layermanager.getlayerfromname  x [i]
		   z= layermanager.newlayerfromname x [i]
		   if  y != undefined then  
			   z	
		)
)
 
---Rollout for interface of script---
 
rollout LayerCreator "LayerCreator 1.0" width:280 height:208
(
	GroupBox Layers "Select Layers for Scene Objects" pos:[8,40] width:264 height:112
	checkbox lyrCameras "Cameras" pos:[144,88] width:120 height:24
	checkbox lyrController "Controller Objects" pos:[16,88] width:120 height:24
	checkbox lyrHiden "Hiden Objects" pos:[16,120] width:120 height:24
	checkbox lyrLights "Light Objects" pos:[144,56] width:120 height:24
	checkbox lyrMesh "Mesh Objects" pos:[16,56] width:120 height:24
	checkbox lyrParticles "Particles" pos:[144,120] width:120 height:24
	edittext lyrBsName " Base Name of Layers" pos:[13,7] width:254 height:17 enabled:false
	button crtLayers "Create New Layers" pos:[8,160] width:264 height:37 enabled:true toolTip:""
 
 
--- The function to enable edittext because at least one checkbox should be checked before enter a word in edittext line ----
 
    fn txtEnbl=
	(
		cb=#( lyrCameras.triState, lyrController.triState, lyrHiden.triState, lyrLights.triState, lyrMesh.triState, lyrParticles.triState)
		for i= 1 to cb.count collect
		if cb [i] != 1 then
			(  
					lyrBsName.enabled= false
			)
 
		else
			(
				if cb [i] == 1 then
					(
						lyrBsName.enabled= true
					)
			)
	) 
 
---Adding a string by each checkbos to the  global  lyrDefNames  ----
 
	on lyrCameras changed theState do
	(   
	    txtEnbl ()
		if lyrCameras.checked == true then 
		(
			objCameras= "_Cameras"
		    append lyrDefNames objCameras
 
		)
 
		else 
		(
			lyrDefNames [1] = undefined
		)
	)
 
	on lyrController changed theState do
	(
		txtEnbl ()
		if lyrController.checked == true then 
		(
			objController= "_Controller"
		   append lyrDefNames objController
		)
 
		else 
		(
			lyrDefNames [2] = undefined
		)
	)
 
	on lyrHiden changed theState do
	(
		txtEnbl ()
		if lyrHiden.checked == true then 
		(
			objHiden= "_Hiden"
			append lyrDefNames objHiden
		)
 
		else 
		(
			lyrDefNames [4] = undefined
		)
	)
 
	on lyrLights changed theState do
	(   
	    txtEnbl ()
		if lyrLights.checked == true then 
		(
			objLights= "_Lights"
			append lyrDefNames objLights	
		)
 
		else 
		(
			lyrDefNames [5] = undefined
		)
	)
 
	on lyrMesh changed theState do
	(
		txtEnbl ()
		if lyrMesh.checked == true then 
		(
			objMesh= "_Mesh"
			append lyrDefNames objMesh
		)
 
		else 
		(
			lyrDefNames [3] = undefined
		)
	)
 
	on lyrParticles changed theState do
	(
		txtEnbl ()
		if lyrParticles.checked == true then 
		(
			objParticles= "_Particles"
			append lyrDefNames objParticles
		)
 
		else 
		(
			lyrDefNames [6] = undefined
		)
	)
 
	--- Adding a sting when text entered to the text line ---
 
	on lyrBsName entered txt do
	(   
 
		bsName= lyrBsName.text as string
		cmbNames= 
		(
			if bsName != ""  then 
				( 
					if lyrDefNames != undefined then 
					(
						for i= 1 to lyrDefNames.count  collect
						append lyrNames (bsName + lyrDefNames [i])
					)
				)
 
				else 
				(
					if bsName =="" then
					(
						lyrNames= #()
					)
				)
			)
	)
 
	--- When button pressed creating layers---
	on crtLayers pressed do
		crtNewLayer ()
)
 
createdialog LayerCreator

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

BTW

@Deman3D
I not tested this tool and I leave it to you to check that.
Cheers!

bga

fajar's picture

lyrDefNames=#()

lyrDefNames=#() 
lyrNames=#()
 
---The function to create layers---
 
fn crtNewLayer =
(  
	for n = 1 to lyrNames.count do
		(  
		   i= n
		   x= lyrNames 
		   y= layermanager.getlayerfromname  x [i]
		   z= layermanager.newlayerfromname x [i]
		   if  y != undefined then  
			   z	
		)
)
 
fn mustbeEnableControl Controle edtText =
(
	oneEnable = false
	for i=4 to 9 do
	(
		if Controle[i].checked==true then oneEnable=true
	)
 
	if oneEnable==true then edtText.enabled=true else edtText.enabled=false
 
)
 
---Rollout for interface of script---
 
rollout LayerCreator "LayerCreator 1.0" width:280 height:208
(
	GroupBox Layers "Select Layers for Scene Objects" pos:[8,40] width:264 height:112
	edittext lyrBsName " Base Name of Layers" pos:[13,7] width:254 height:17 enabled:false
	button crtLayers "Create New Layers" pos:[8,160] width:264 height:37 enabled:true toolTip:""
 
	checkbox lyrCameras "Cameras" pos:[144,88] width:120 height:24
	checkbox lyrController "Controller Objects" pos:[16,88] width:120 height:24
	checkbox lyrHiden "Hiden Objects" pos:[16,120] width:120 height:24
	checkbox lyrLights "Light Objects" pos:[144,56] width:120 height:24
	checkbox lyrMesh "Mesh Objects" pos:[16,56] width:120 height:24
	checkbox lyrParticles "Particles" pos:[144,120] width:120 height:24
 
	on lyrController changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
 
	on lyrCameras changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
 
	on lyrHiden changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
 
	on lyrLights changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
 
	on lyrMesh changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
 
	on lyrParticles changed state do
	(
		mustBeEnableControl LayerCreator.controls lyrBsName 
	)
)
 
createdialog LayerCreator

I arrange the code a little, check it, hope it helps

Deman3D's picture

Thanks

Your script codes are very helpful to understand how I should create a loop for my purpose.

Thank you very much.

barigazy's picture

...

I arranged a bit more ei. I clean up the mess

;)

Just joking...
Anyway it's more convinient this way. You can see all names in the list before layers creation

try (DestroyDialog ::LayerCreator) catch()
rollout LayerCreator "LayerCreator v1.0"
(
	local prxList = #("_Cameras","_Controller","_Hidden","_Lights","_Meshes","_Particles","_Helpers","_Proxies")
	fn createLayer layname = (layermanager.newlayerfromname layname)
	fn isLayerExist layname = (layermanager.getlayerfromname layname != null) 
	fn collectPrefixes arr:prxList roll:LayerCreator = (for c = 4 to 11 where roll.controls[c].checked collect prxList[c-3])
 
	label titles "Base Name of Layers:                                  Layer Prefix:" pos:[5,5]
	edittext lyrBsName "" pos:[1,20] fieldwidth:200 height:17 enabled:off
	multilistbox layNames "" pos:[5,40] width:200 height:8
	checkbox lyrCameras "Cameras" pos:[210,20]
	checkbox lyrController "Controllers" pos:[210,40]
	checkbox lyrHidden "Hidden Objs" pos:[210,60]
	checkbox lyrLights "Lights" pos:[210,80]
	checkbox lyrMesh "Meshes" pos:[210,100]
	checkbox lyrParticles "Particles" pos:[210,120]
	checkbox lyrHelpers "Helpers" pos:[210,140]
	checkbox lyrProxy "Proxies" pos:[210,160]
	button clearSel "Clear Selected" pos:[5,152] width:100
	button clearAll "Clear All" pos:[105,152] width:100
	button crtLayers "Create New Layers From List" pos:[5,175] width:200 height:30
	button openLM "Open LM" pos:[210,175] width:75 height:30 tooltip:"Open Layer Manager"
 
	fn enableTextBox roll:LayerCreator tb:lyrBsName =
	(
		local state = off
		for c = 4 to 11 where roll.controls[c].checked do exit with state = on
		tb.enabled = state ; if state then setFocus tb else tb.text = ""
	)
	on openLM pressed do (if not (LayerManager.isDialogOpen()) do LayerManager.editLayerByName "")
	on clearAll pressed do layNames.items = #()
	on clearSel pressed do 
	(
		if not (layNames.selection).isEmpty do
		(
			local idxs = layNames.selection as array
			local items = layNames.items
			for i = idxs.count to 1 by -1 do deleteItem items idxs[i]
			layNames.items = items	
		)
	)
	on lyrCameras changed state do enableTextBox()
	on lyrController changed state do enableTextBox()
	on lyrHidden changed state do enableTextBox()
	on lyrLights changed state do enableTextBox()
	on lyrMesh changed state do enableTextBox()
	on lyrParticles changed state do enableTextBox()
        on lyrHelpers changed state do enableTextBox()
	on lyrProxy changed state do enableTextBox()
	on lyrBsName entered txt do if txt != "" do
	(
		local prxArr = collectPrefixes(), listItems = layNames.items
		local newnames = for p in prxArr collect
		(
			if findItem listItems (name = txt+p) == 0 then name else dontCollect
		)
		if newnames.count != 0 do layNames.items = join newnames listItems
		lyrBsName.text = ""
	)
	on crtLayers pressed do if (listItems = layNames.items).count > 0 do
	(
		local toDelete = #()
		for i = 1 to listItems.count do (if isLayerExist listItems[i] then append toDelete[i] else createLayer listItems[i])
		if toDelete.count > 0 do 
		(
			for i = toDelete.count to 1 by -1 do deleteItem listItems i
			layNames.items = listItems	
		)
	)
)
createdialog LayerCreator 290 208 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

bga

Deman3D's picture

Thanks.

Thank you very much for your script you created to me. Yes your codes are much better than mine and properly work but as you can understand I am trying to learn maxscript to support my workflow on 3ds max. I will examine your script detailed and they are very precious to me while I try to learn something more.

Regards.

barigazy's picture

...

My pleasure. If you not understand something in my code just ask, but before that try to find answers in maxscript help document. It's better that way if you want to learn and understand why or how things works. We all started that way.
If you not already watched this video training just take a look http://vimeo.com/album/1514565

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.