How to check for selected segments i splineShape

Hi there, i am a noob at maxscript, so hopefully someone can help me with my problem.

I am trying to assign materialID to a selection af segments, and this is where i am so fare:

on spn_segmentsId entered do -- set the material ID for the selected segment
(

num=spn_segmentsId.value

for i=1 to (numSplines $) do (

for j=1 to (numSegments $ i) do (
?- NEED TO TEST IF THE SEGMENT IS SELECTED -? setMaterialID $ i j num
)

)
updateShape $

)

Pleace help me am i on the right track, i cant seem to find any method for checking for selected segments.

Best regards
David

Comments

Comment viewing options

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

2D array

I´m back

This time it is the "reverse order". I need to grap segments by the materialId.

This is where i am so fare:

rollout test "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 will help me understand how this is done.

Best regards
David

barigazy's picture

...

Run this function first

fn splineMtlID shape mode: id: = if isKindOf shape splineshape or isKindOf shape line do
(
	for i = 1 to numsplines shape do
	(
		case mode of
		(
			#selected: 
			(
				if (array = getSegSelection shape i).count > 0 do
				(
					for j in array do setMaterialID shape i j id
				)					
			)
			#random:
			(
				for j = 1 to numSegments shape i do setMaterialID shape i j (random 1 id)
			)
			#randselected:
			(
				if (array = getSegSelection shape i).count > 0 do
				(
					for j in array do setMaterialID shape i j (random 1 id)
				)	
			)
 
		)
	)
)

Then to execute this function run separately line by line of code.
For example:
-- example
Select some spline first.
Run next line of code if you want to assigne id 2 (for example) to selected segments.

splineMtlID selection[1] mode:#selected id:2

Run next line if you want to assigne random id's to any segments.
In this case you not need to select segments.
If you add id 5 then you will assigne random number from 1 to 5

splineMtlID selection[1] mode:#random id:5

Run next line if you want to assigne random id's to selected segments segments
Same rule, if you asigne id 10 you will assigne rundom numbers as id from 1 to 10

splineMtlID selection[1] mode:#randselected id:10

barigazy

PIXandDOTS's picture

So cool Branko Živković, i

So cool Branko Živković, i need to learn how to build functions :)

Thanks for your help.

I´m working on a couple of other small script´s, so i might be back for some more help :)

Best regards
David

Comment viewing options

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