Notifications
Clear all

[Closed] using string tab

Whats the best way to list the nodes names in the multilist within the rollout, after a node/nodes are added?


plugin modifier birthListModifier
name:"BithList"
classID:#(0x54ad45ca, 0x44af2a99)
replaceUI:off
silentErrors:off
version:1
(
	fn geoFilter obj = isKindOf obj GeometryClass
	fn PopulateBithListName =
	(
		for n in this.objectList do print n
	)
	
	parameters creation rollout:creation
	(
		objectList type:#nodeTab tabSize:0 tabSizeVariable:true -- changed the parameter name also changed tabsize to 0 so it would not add an undefined item to the array		
	)
	rollout creation "Birth Object List"
	(
		multilistbox ui_ObjectList items:#() height:8
		pickbutton ui_AddObject "+" width:26 height:25 across:5 
		button ui_RemoveObject "-" width:26 height:25 offset:[-1,0]
		button ui_MoveUp "^" width:26 height:25 offset:[-2,0]
		button ui_MoveDown "v" width:26 height:25 offset:[-3,0]
		button ui_ClearAll "Clear" width:30 height:25 offset:[3,0]
		
		on ui_AddObject rightclick do
		(
			selNodes = selectByName title:"Select Shapes" buttonText:"Add" showHidden:true single:false filter:geoFilter
			for node in selNodes do appendIfUnique objectList node
				PopulateBithListName()
		)
		on ui_AddObject picked node do
		(
			if node != undefined do appendIfUnique objectList node
		)
	)
)

/* Test Object Setup */
clearlistener()
delete objects
sp = box name:"BithList"
addmodifier sp (birthListModifier())
select sp
box height:10 width:10 length:10 pos:[40,0,0]
box height:10 width:10 length:10 pos:[0,30,0]

14 Replies

You can use the tabChanged handler for that: http://forums.cgsociety.org/showpost.php?p=4439700&postcount=10

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

true… but have you test it for undo/redo?

As far as I can tell, no undo record gets created. Is that desirable or are there any potential problems I might be overlooking?

plugin modifier birthListModifier
name:"BirthList"
classID:#(0x54ad45ca, 0x44af2a99)
replaceUI:off
silentErrors:off
version:1
(
	parameters creation rollout:creation
	(
		objectList type:#nodeTab tabSize:0 tabSizeVariable:true

		on objectList tabChanged change tabIndex tabCount do
			if change == #refDeleted then
				deleteItem objectList tabIndex
			else this.creation.updateList()
	)

	rollout creation "Birth Object List"
	(
		multiListBox ui_ObjectList items:#() height:8 selection:0
		button ui_AddObject "+" width:26 height:25 across:5 
		button ui_RemoveObject "-" width:26 height:25 offset:[-1,0]
		button ui_MoveUp "^" width:26 height:25 offset:[-2,0]
		button ui_MoveDown "v" width:26 height:25 offset:[-3,0]
		button ui_ClearAll "Clear" width:30 height:25 offset:[3,0]

		fn updateList =
			ui_ObjectList.items = for obj in objectList collect obj.name
	
		fn getOffsetIndex arr pos offset =
			if pos + offset > arr.count then
				mod (pos + offset) arr.count
			else pos + offset

		fn geoFilter obj = isKindOf obj GeometryClass

		fn pickObjects =
			selectByName title:"Select Shapes" buttonText:"Add" \
				showHidden:true single:false filter:geoFilter
 
		fn addSingleItem item:(pickObject()) =
			appendIfUnique objectList item
 
		fn addMultipleItems items:(pickObjects()) =
			for item in items do
				appendIfUnique objectList item

		 fn removeItems listUnselected:(-ui_ObjectList.selection) =
			objectList = for i in listUnselected collect objectList[i]

		fn moveItems arr dir listSelected:ui_ObjectList.selection =
		(
			for i in listSelected do swap arr[i] arr[getOffsetIndex arr i dir]
			ui_ObjectList.selection = #{}
			updateList()
		)
 
		on creation open do updateList() 
		on ui_AddObject pressed do addSingleItem()
		on ui_AddObject rightclick do addMultipleItems()
		on ui_RemoveObject pressed do removeItems()
		on ui_MoveUp pressed do moveItems objectList -1
		on ui_MoveDown pressed do moveItems objectList 1
		on ui_ClearAll pressed do objectList = #()
	)
)

/* Test Object Setup */
clearListener()
delete objects
sp = Box name:"BirthList" isSelected:true
addModifier sp (birthListModifier())
box height:10 width:10 length:10 pos:[40,0,0]
box height:10 width:10 length:10 pos:[0,30,0]
gc()

Swordslayer you code is cleaned up quite a fair bit from mine. It needs a few fixes. It doesn’t remove multiple selected items from the list and then doesn’t retain the selection of the items when moving up or down.

Bugs out if items are moved to top and you try to move up another time.

my suggestion is to use #nodeTab with a fixed size… because of undo/redo support

2 Replies
(@jokermartini)
Joined: 11 months ago

Posts: 0

NodeTab but to have a fixed size is hard because the number of items in the list can always change.

How would you suggest I use it?
Make the tab size like 100 or something like that?

(@denist)
Joined: 11 months ago

Posts: 0

make a size that you need in advance.

and of course continue playing with variable sized tab… try to make it undoable, delete any node in scene, rename… if you will not be able to make everything works, use my suggestion.

Fixed some of the code and added a few error checks. Just need to make improvements on the Move button functions.


plugin modifier birthListModifier
name:"BithList"
classID:#(0x54ad45ca, 0x44af2a99)
replaceUI:off
silentErrors:off
version:1
(
	fn geoFilter obj = isKindOf obj GeometryClass AND obj != selection[1] AND findItem this.objectList obj == 0

	parameters creation rollout:creation
	(
		objectList type:#nodeTab tabSize:0 tabSizeVariable:true -- changed the parameter name also changed tabsize to 0 so it would not add an undefined item to the array		
			
		on objectList tabChanged change tabIndex tabCount do
		(
			if change == #refDeleted then
				deleteItem objectList tabIndex
			else this.creation.PopulateBithList()
		)
	)
	rollout creation "Birth Object List"
	(
		multilistbox ui_ObjectList items:#() height:8
		button ui_AddObject "+" width:26 height:25 across:5
		button ui_RemoveObjects "-" width:26 height:25 offset:[-1,0]
		button ui_MoveUp "^" width:26 height:25 offset:[-2,0]
		button ui_MoveDown "v" width:26 height:25 offset:[-3,0]
		button ui_ClearAll "Clear" width:30 height:25 offset:[3,0]
		
		fn PopulateBithList =(
			ui_ObjectList.items = for n in objectList where isValidNode n collect n.name
			ui_ObjectList.selection = #{}
		)
		
		fn removeItems listUnselected:(-ui_ObjectList.selection) = (
			objectList = for i in listUnselected collect objectList[i]
			PopulateBithList()
		)
		
		fn addSingleItem item:(pickObject prompt:"Pick Geometry Node" filter:geoFilter ) = (
			if item != undefined do appendIfUnique objectList item
		)
		
		fn pickObjects = selectByName title:"Select Objects" buttonText:"Add" showHidden:true single:false filter:geoFilter
				
		fn addMultipleItems items:(pickObjects()) = (
			if items != undefined do (for item in items do appendIfUnique objectList item)
		)
		
		fn fnMoveItmUpLst lst arr = ( -- moves objects up list
			local itm = lst.selection 
			for t = 2 to itm.count do
			(
				if (itm[t] and not itm[t - 1]) then
				(
					swap arr[t] arr[t - 1]
					deleteItem itm t
					append itm (t - 1)
				)
			)
			lst.items = for i in arr collect i.name -- update list with array
			lst.selection = itm	
		)
		fn fnMoveItmDownLst lst arr = ( -- moves objects down list
			local itm = lst.selection 
			for t = itm.count - 1  to 1 by -1 do
			(
				if (itm[t] and not itm[t + 1]) then
				(
					swap arr[t] arr[t + 1]
					deleteItem itm t
					append itm (t + 1)
				)
			)
			lst.items = for i in arr collect i.name -- update list with array
			lst.selection = itm	
		)
		
		on ui_AddObject pressed do addSingleItem()
		on ui_AddObject rightclick do addMultipleItems()
		on ui_MoveUp pressed do (fnMoveItmUpLst ui_ObjectList objectList)
 		on ui_MoveDown pressed do 	(fnMoveItmDownLst ui_ObjectList objectList)
		on ui_RemoveObjects pressed do removeItems()
		on ui_ClearAll pressed do objectList = #()
		on creation open do (PopulateBithList())
	)
)

/* Test Object Setup */
clearlistener()
delete objects
sp = box name:"BithList" pos:[50,50,0]
addmodifier sp (birthListModifier())
select sp
for i = 1 to 10 do
(
	box height:10 width:10 length:10 pos:[(random -30 30),(random -30 30),0] wirecolor:(random white black)
)	
	
	
	
	
	

I cleaned up the moveItems function a bit more. If anyone has suggestions on a way to improve it even more I’d be more than glad to hear.


plugin modifier birthListModifier
name:"BithList"
classID:#(0x54ad45ca, 0x44af2a99)
replaceUI:off
silentErrors:off
version:1
(
	fn geoFilter obj = isKindOf obj GeometryClass AND obj != selection[1] AND findItem this.objectList obj == 0

	parameters creation rollout:creation
	(
		objectList type:#nodeTab tabSize:0 tabSizeVariable:true -- changed the parameter name also changed tabsize to 0 so it would not add an undefined item to the array		
			
		on objectList tabChanged change tabIndex tabCount do
		(
			if change == #refDeleted then
				deleteItem objectList tabIndex
			else this.creation.PopulateBithList()
		)
	)
	rollout creation "Birth Object List"
	(
		multilistbox ui_ObjectList items:#() height:8
		button ui_AddObject "+" width:26 height:25 across:5
		button ui_RemoveObjects "-" width:26 height:25 offset:[-1,0]
		button ui_MoveUp "^" width:26 height:25 offset:[-2,0]
		button ui_MoveDown "v" width:26 height:25 offset:[-3,0]
		button ui_ClearAll "Clear" width:30 height:25 offset:[3,0]
		
		fn PopulateBithList =(
			ui_ObjectList.items = for n in objectList where isValidNode n collect n.name
			ui_ObjectList.selection = #{}
		)
		
		fn removeItems listUnselected:(-ui_ObjectList.selection) = (
			objectList = for i in listUnselected collect objectList[i]
			PopulateBithList()
		)
		
		fn addSingleItem item:(pickObject prompt:"Pick Geometry Node" filter:geoFilter ) = (
			if item != undefined do appendIfUnique objectList item
		)
		
		fn pickObjects = selectByName title:"Select Objects" buttonText:"Add" showHidden:true single:false filter:geoFilter
				
		fn addMultipleItems items:(pickObjects()) = (
			if items != undefined do (for item in items do appendIfUnique objectList item)
		)
		
		fn moveItems lst arr dir = ( -- moves objects down list
			local itm = lst.selection 
			start = if dir == 1 then (itm.count - 1) else 2
			end = if dir == 1 then 1 else (itm.count)
			for t = start  to end by (dir*-1) do
			(
				if (itm[t] and not itm[t + dir]) then
				(
					swap arr[t] arr[t + dir]
					deleteItem itm t
					append itm (t + dir)
				)
			)
			lst.items = for i in arr collect i.name -- update list with array
			lst.selection = itm	
		)
		
		on ui_AddObject pressed do addSingleItem()
		on ui_AddObject rightclick do addMultipleItems()
		
		on ui_MoveUp pressed do (moveItems ui_ObjectList objectList -1)
 		on ui_MoveDown pressed do 	(moveItems ui_ObjectList objectList 1)
		on ui_RemoveObjects pressed do removeItems()
		on ui_ClearAll pressed do objectList = #()
		on creation open do (PopulateBithList())
	)
)

/* Test Object Setup */
clearlistener()
delete objects
sp = box name:"BithList" pos:[50,50,0]
addmodifier sp (birthListModifier())
select sp
for i = 1 to 10 do
(
	box height:10 width:10 length:10 pos:[(random -30 30),(random -30 30),0] wirecolor:(random white black)
)	
	
	
	
	
	

What is the best method for storing/saving an array containing structs on a custom mod?

example:


struct data (value,height,group)

allData = #(data value:1 height:10.0 group:1,data value:2 height:20.0 group:1)


?

1 Reply
(@lonerobot)
Joined: 11 months ago

Posts: 0

You can save an xml document of the array/struct into a string tab too. That works nicely.

#stringTab, or #maxobjectTab where instead of struct a CA attribute with the same properties is used.

How do I modify this to work when I hit the add button that the struct get stored with the node/modifier and at the same time populate the multilist with the ‘index name’ of each item.

The problem in using a string tab is that it bugs out after 20 items it just adds ‘…’
Seems like the way of the CA might be easier in that case. Does anyone have example of how to do this or the stringTab method?


plugin simpleObject Info 
name:"Info"
category:"Standard Primitives"
classID:#(0x14efefc5, 0x1769dde9)
(
	struct data (index,count,number)
	
	parameters main rollout:sets
	(
		setList type:#maxObjectTab tabSize:0 tabSizeVariable:true -- changed the parameter name also changed tabsize to 0 so it would not add an undefined item to the array		
		
		on setList tabChanged change tabIndex tabCount do
		(
			if change == #refDeleted then
				deleteItem setList tabIndex
			else this.sets.PopulateList
		)
	)
	
	rollout sets "Sets"
	(
		multilistbox ui_SetList items:#() height:8
		button ui_AddObject "Add New" width:140 height:25
		
		fn PopulateList =(
			ui_SetList.items = for n in setList collect n.index
			ui_SetList.selection = #{}
		)
		
		on ui_AddObject pressed do 
		(
			id = (setList.count + 1) as string
			item = (data index:id count:(random 0.0 1.0) number:(random 0 100))
			append setList item
		)
	)
	
	tool create
	(
		local first_pos
		
		on mousePoint click do case click of
		(
			1: (coordSys grid (nodeTM.translation = first_pos = gridPoint))
			2: #stop
		)
	)
)


Page 1 / 2