ScriptSpot

Forum topic · General Scripting

Append 2D array

By PIXandDOTS · 2015-06-18

Description

In a editSpline i would like to be able to select segments by the materialId.

This is where i am so fare:

rollout selectSeg "select seg id"
(

spinner spn_selectID "select seg" type:#integer range:[1,3,1]

on spn_selectID entered do(

id = spn_selectID.value
obj = selection[1]
newSegSel = #()

for i=1 to (numSplines $) do if getMaterialID obj i j== id do
(
append newSegSel i
for j=1 to (numSegments $ i) do if getMaterialID obj i j== id do
(
append newSegSel j
)
setSegSelection obj i newSegSel
)
updateShape $
)

)
createDialog test 300 200

I am stuck at this point on how to make my array (newSegSel) a 2D array, and how to append the right numSplines and numSegments.

Is there anyone who might have the time to help me understand how this is done.

Best regards
David

Comments (1)

`

pixamoon · 2015-06-19

oki, try this:


rollout selectSeg "select seg id"
(
	spinner spn_selectID "select seg" type:#integer range:[1,3,1]

	on spn_selectID entered do (
		
		subobjectLevel = 2
		id = spn_selectID.value
		obj = selection[1]
		newSegSel = #()
		
		for i=1 to (numSplines obj) do (
			for j=1 to (numSegments obj i) where getMaterialID obj i j == id do append newSegSel j
			setSegSelection obj i newSegSel
		)
		updateShape obj
	)

)
createDialog selectSeg 300 200

Or this one if you want to first collect 2d array and later use it to select segments:


rollout selectSeg2 "select seg id"
(
	spinner spn_selectID "select seg" type:#integer range:[1,3,1]

	on spn_selectID entered do (
		
		subobjectLevel = 2
		id = spn_selectID.value
		obj = selection[1]
		newSegSel = #()
		
		for i=1 to (numSplines obj) do (
			segments = for j=1 to (numSegments obj i) where getMaterialID obj i j == id collect j
			append newSegSel #(i,segments)
		)	
		for o in newSegSel do setSegSelection obj o[1] o[2]
		updateShape obj
	)

)
createDialog selectSeg2 300 200

also if you include code you can use < code > your code < /code > (but without spaces between <> and word "code" :)

Hope it helps.
Pixamoon