Notifications
Clear all

[Closed] newbie question about selecting objects

hello there!
I am trying to make some of my first scriptjob and having trouble on something.

i have already do something using the listener and working fine. i now need to use that script for selected objects.
so, i need to have a selection and by clicking the script, to select one obj at a time and run the previous script on each one.

thank you in advance

22 Replies
 em3

--select your objects first
objs = for o in selection collect o
for o = 1 to objs.count do
(
select objs[o]
--do something
)

There are very few cases where you need to select a scene object in order to make changes to it. You should try to avoid it if you can as it will slow your script down and usually case the UI to flicker.

If you have already selected some objects in your scene and you want to cycle through them a simple way would be something like:

(
	for obj in (getCurrentSelection()) do
	(
		--your code here
	)
)

OR a better way would be to write a mapped function:

(
	mapped fn yourFn obj =
	(
		--your code here
	)
	
	yourFn (getCurrentSelection())
)

I would be easier to answer your question if you posted your code and said what you would like it to do.

maybe same thing…

on btn2 pressed do
(
for i in selection do
(
–code here is for changing wirecolor
i.wirecolor = black

)
)

so u where more than useful and i am really thankful! :applause:
The thing is that i do furniture modeling for existing designs and for a box , that is the main part of any furniture, i need to do some fillet in the corners.
I use the chamfer, with 3 segments and smoothing to all faces in one smoothing group.
The problem with this was that because of the smoothing groups, i got some “spherifying” effect.
For that, i use insert face with half the amount of chamfer and 2 iterations.
That way, the effect is limited between these 2 faces and my obj looks totally boxy.
For a complete kitchen cabinet or a kids room, i need to run that “script” over and over for more than 20-40 obj and beside the time, it is painful!
Forgot to tell that i do the main model on rhino (mcneels) and importing it as .3ds so it has to be a weld and remove edges before chamfering.
All that are clear on the code :deal:
I ll someday maybe try to make it with menus and stuff… but not today!
Thank you again for all of ur time spend!

script explained

(
macros.run “Modifier Stack” “Convert_to_Poly” –convert obj to ed. poly
subobjectLevel = 2
actionMan.executeAction 0 “40021”
$.EditablePoly.SetSelection #Edge #{1…20000} –select all edges and remove
$.EditablePoly.Remove ()
subobjectLevel = 1
actionMan.executeAction 0 “40021”
$.EditablePoly.SetSelection #Vertex #{1…10000} –select all vert and weld
$.weldThreshold = 0.01
$.EditablePoly.weldFlaggedVertices ()
subobjectLevel = 2
actionMan.executeAction 0 “40021”
$.EditablePoly.SetSelection #Edge #{1…12} –select all edges and chamfer
$.edgeChamfer = 0.1
$.edgeChamferSegments = 3
$.EditablePoly.buttonOp #Chamfer
subobjectLevel = 4
$.EditablePoly.SetSelection #Face #{1…6} –select some faces and insert
$.insetAmount = 0.05
$.EditablePoly.buttonOp #Inset
$.EditablePoly.buttonOp #Inset
$.EditablePoly.SetSelection #Face #{1…162} –select all faces and autosmooth
$.EditablePoly.autosmooth ()
subobjectLevel = 0
clearSelection()
)

nothing worked… and i can t understand why…
it finds error in some random line…
do anyone now how i can do it… regardless the “script” i have already…
if anyone know a way to help me out, would be appreciated! :bounce:

Hi spad. Are you doing all these complicated steps just to get more control over the smoothing of your model? If so, maybe this will be of use to you: http://mariussilaghi.com/products/turbosmooth-pro .I don’t own it yet (I’m not modelling currently) but it looks extremely promising.

Regarding your script. I haven’t tested it but just from looking at the code I’d guess it fails because you’re defining the vertices and edges by number instead of just affecting all. So if a model has more or less edges the script will probably crash. So out of my head, the code should look something like this:

$.EditablePoly.SetSelection #Edge #{1..($.EditablePoly.getnumedges())}

or even simpler:

max select all

hello Wheiraucher and thank you for your answer!
the point of all this is to make a totally str8 box, without that rounding effect of smoothing groups but the most important thing is to keep the polygons as low as possible.
With the way i currently working, a perfect quality box, counts 162 polygons.
with a scene of 400-1000 objts like that, i got total of 65000-162000 polygons.
the problem i come against is the 400-1000 obj need to be one-by-one -_- or sometimes i attach them all together and make it step by step… this is hard too…
i need a way to run that script over each obj of the selected.
i am really really bad at coding… and i don t know more than the basics of scripting…
i do that kind of work professionally, meaning that there will be up to 10 scenes a day and the most of them are going to be animated, so every polygon counts! still can t understand why the code provided above is not working… :banghead:

Hey Spad, I made a few video tutorials that will cover the questions you have, and show you how to clean up you scripts a little bit, and show you how to script a little faster, using native tools in 3dsMax.

Rule of 3: Neve do something a third time (9 min)
http://youtu.be/3Z1iGHwpsrk

Simple Maxscript tool creation: how to develop your scripts into tools (18 min)
http://youtu.be/HTk8Rh0a5ys

These are absolute beginner crash course videos I wish I had when I was starting out, and should help get you off in the right direction.

Page 1 / 3