select just one instance

hello
I look for a script to select just one instance of an object :
- select all objects I want to work with
- run the script
- just one instance of each object is selected.
Thanks

Comments

Comment viewing options

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

???

So regarding Your code, I'm not maxscript master, I making my first baby steps in maxscript so I would need more explanation regarding this script:

fn reassignModifier mode: modyClass: =
(
local tsArr = getClassInstances modyClass
local objs = case mode of
(
#all:
(
if tsArr.count == 0 then #() else
(
for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 collect nodes[1]
)
)
#selection:
(
if selection.count == 0 then #() else
(
local firstInstances = #()
for o in selection where o.modifiers.count != 0 do
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 then append firstInstances firstOnly[firstOnly.count-1] else append firstInstances o
)
firstInstances
)
)
)
if objs.count != 0 and tsArr.count != 0 do
(
max create mode
with redraw off
(
for o in objs do
(
for m = o.modifiers.count to 1 by -1 where isKindOf o.modifiers[m] TurboSmooth do
(
bulb = o.modifiers[m].enabled
mody = copy o.modifiers[m] ; mody.enabled = bulb ; deleteModifier o m ; addModifier o mody before:(m-1)
)
)
)
)
)

I created some objects with active turbosmooth, fired it up and I noticed script do preety much nothing:) I eresed
"addModifier o mody before:(m-1)" line 37 so cript should only delete modyfiers(it's only way for me to check if script work, because modyfier look identical before and after execution) but it seems script dont erase modyfiers. I have also impression that max don't touched this modyfiers - last script make it blink - there was some reaction on max modyfi interface . I don't even know is it working at all or it's work and I use it in wrong way? Next thing is, you gave to line for action on selection and action for all scene elements but how to use it, exactly, how to create two different script for this using this command. Next thing is script copy and paste this same turbosmooth. When there is skin glitch cased by turbosmooth - turbosmooth must be deleted and added new because contain glitch so if I copy and paste this same turbosmoothit is useless.So settings from oryginal turbosmooth mus be taken, old turbosmooth must be removed, new added and settings from oryginal must be set also check if turbosmmoth is active or not and set it identical.

I know my understanding of maxscript leave a lot to be desired but I'm beginner:)
Can You explane this script, please, maybe I just don't get it.

Don't retired, people need help:)

barigazy's picture

...

this solution works for any modifier class and both (selection and all scene)

fn reassignModifier mode: modyClass: = 
(
	local tsArr = getClassInstances modyClass
	local objs = case mode of
	(
		#all: 
		(
			if tsArr.count == 0 then #() else
			(
				for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 collect nodes[1]
			)
		)
		#selection:
		(
			if selection.count == 0 then #() else
			(
				local firstInstances = #()
				for o in selection where o.modifiers.count != 0 do 
				(
					InstanceMgr.GetInstances o &firstOnly
					if firstOnly.count > 1 then append firstInstances firstOnly[firstOnly.count-1] else append firstInstances o
				)
				firstInstances
			)
		)
	)
	if objs.count != 0 and tsArr.count != 0 do
	(
		max create mode
		with redraw off 
		(
			for o in objs do
			(
				for m = o.modifiers.count to 1 by -1 where isKindOf o.modifiers[m] TurboSmooth do
				(
					bulb = o.modifiers[m].enabled
					mody = copy o.modifiers[m] ; mody.enabled = bulb ; deleteModifier o m ; addModifier o mody before:(m-1)
				)	
			)
		)			
	)
)

You have two fn arguments: "mode" and "modyClass"
This will works only on selected objects

reassignModifier mode:#selection modyClass:TurboSmooth

and this will take to acount all scene modifiers of specified class

reassignModifier mode:#all modyClass:TurboSmooth

BTW... This is my 15000 point on this forum (see "users by points").
Maybe it's time to retire. Why do you think?

:)

bga

miauu's picture

.

Make your 15 001 post and post the code above in the right thread. :)

barigazy's picture

...

:) Yes. You are right! :)
This is the right thread:

http://www.scriptspot.com/forums/3ds-max/general-scripting/replacing-mod...

bga

roamn's picture

Or you can use instance

Or you can use instance trimmer from neil blevins script pack (which everyone should have installed already :-) )

barigazy's picture

...

Try this

if selection.count != 0 do
(
	local firstInstances = #()
	for o in selection do 
	(
		InstanceMgr.GetInstances o &firstOnly
		if firstOnly.count > 1 do 
			append firstInstances firstOnly[firstOnly.count-1]
	)
	if firstInstances.count != 0 do select firstInstances
)

bga

eyepiz's picture

Very Nice!

Could it me made to select all the objects that are not instances too?
so if I wanted to apply a modifier in all selected objects, that it would select the one instanced object like in the script and the objects that are not instances as well.

I could really use something like this.

Thanks!

Eric

barigazy's picture

...

Yup. Script select all non-instances object and first instace

bga

eyepiz's picture

Cool...how do I add this to

Cool...how do I add this to the script below?

(
if selection.count != 0 do
(
local firstInstances = #()
for o in selection do
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 do
append firstInstances firstOnly[firstOnly.count-1]
)
if firstInstances.count != 0 do select firstInstances
)
)

barigazy's picture

...

Which script below?

bga

Comment viewing options

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