PDA

View Full Version : select all


FreakyDude
01-05-2005, 10:26 AM
Hi there, I'm new to scripting, so this is probably a very noobish question, but here goes:

I want to create a macro where at a certain time you convert everything to an editpoly, then go to subobject element or polygon/faces then select ALL the elements/polygons/faces.
If I use the macro recorcer, and create a cube it gives me this
actionMan.executeAction 0 "40021"-- Edit: Select All

$.EditablePoly.SetSelection #Face #{1..6}

Obviously if I had a sphere for instance, the face count would go much higher than 6. My question is, how do I make it select anything? Can I just leave it blank? I tried just leaving the #{1..6} out, and it works for some brushes, but not all.


And here's what I want to do and which actions I currently have to do it:

First I lay out a certain blueprint by drawing splines. (no macro scripting needed)
then comes the stuff I want to automate:
-extrude the spline a certain amount (72)
-add uwv modifier and set to box mapping/maptype4
-collapse to editpoly
-go to subobject element or polygon/faces
-select EVERYTHING
-Set the material ID of everything to a certain value(1)
-flip all the normals, so they all point inwards
-apply an unreal brush modifier (this is from jamlander)
-set the brush type to subtract(the macro recorder doesn't record this action)

Here's what I have so far, but it doesn't work flawlessly on all objects:


macroScript Macro6
category:"DragAndDrop"
toolTip:" make rooms?"

(
modPanel.addModToSelection (Extrude ()) ui:on
$.modifiers[#Extrude].amount = 72
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].maptype = 4
macros.run "Modifier Stack" "Convert_to_Poly"
subobjectLevel = 5
actionMan.executeAction 0 "40021"
$.EditablePoly.SetSelection #Face #{..}
macros.run "Editable Polygon Object" "EPoly_Flip"
subobjectLevel = 0
modPanel.addModToSelection (Unreal_Brush ()) ui:on
)



Another small question, can I leave the UI:on out? It doesn't seem to have any use.
Also: maybe I should do all the setmaterial and flip the normals before collapsing everything to epoly, even before applying an UVW mod. By means of an edit mesh modifier. I doubt it has any concequenses if I leave it like this, but well, you guys are the experts, so I thought I'd ask you :P
Instead of the splineplan, I might also simply allready have geometry, that doesn't need extruding, but still needs to have its ID's set to the same, and an uvw mod set to it etc... So then I could just leave the extrude out. Or is there a simple way to put it in one nifty button? So it auto detects if it's base object is a spline or emesh/epoly?

galagast
01-05-2005, 10:57 AM
hi, u cud try and expand from this code


rollout test "test"
(
checkbox ext "" checked:true across:2
spinner ext_val "Extrude" range:[-9999,9999,72] type:#integer
button apply "Apply"
on ext changed val do
(
ext_val.enabled = not ext_val.enabled
)
on apply pressed do
(
case ext_val.enabled of
(
true: print "true"
false: print "false"
)
)
)
createdialog test


and in somtimes, it is much better to use "addmodifier" instead of "modPanel.addModToSelection"

and if u accidentally checked the extrude option, then pressed apply on a non-spline, u can add something like:

if classof $ != line then print "non-spline" else print "spline!"


these are just some quick tips, and mind u, im no expert in this, im just fond of doing stuff in maxscript. :D i hope this helps!

Rivendale
01-05-2005, 01:00 PM
Hi, here some code that would do what you need:

addmod extrude ; $.modifiers[#extrude].amount = 72
addmod Uvwmap ; $.modifiers[#UVW_Mapping].maptype = 4
addmod Normalmodifier ; $.modifiers[#Normal].flip = on
convertTo $ Editable_Poly


This code uses the Normal modifier instead of selecting faces to do the flipping. After that you could add the Unreal_brush thingy. If you wanted to select all faces you could write:
polyop.setFaceSelection $.baseobject #all

FreakyDude
01-05-2005, 08:47 PM
Thank you. Both of you.

I find the solution Rivendale mentioned the easiest to currently implement, and I'm making several variations of it, to see if I can get the same result with different versions.
Rivendale, thank you for your suggestion of the normalmodifier, since it also has an unify normals option I can implement. I think with the information you two gave, i'll get it to work just the way I want it to. :)

Rivendale
01-05-2005, 09:17 PM
Hey for the checking if it's a spline object or not you could use this on the extrude part of the script:

if superclassof $ == shape do (addmod extrude ; $.modifiers[#extrude].amount = 72)

So if it's not a splineshape that part will be skipped.

CML

FreakyDude
01-06-2005, 12:49 AM
He that's quite convenient, this way it'll work regardless of it being a shape or an emesh or epoly, i'll get it implemented in the macro.

Next thing I was thinking of, right now I may have skipped about 6 steps for every object, but I still have to do one object at a time. what if I wanted to select a group of objects and wanted them to automatically do these steps to the individual object? Currently, you apply one modifier, per selection, not per object, then later you collapse to poly. I tried it, it doesn't work. Gives some modifier errors.
I did get it to work flawlessly without looking at the facecount, and the normal and mapping options also work. Thanks to your comments Rivendale. Thank you. :) Yay, maybe I'll actually get into scripting. It's terribly annoying when things don't work, but when they do, it's twice as ammusing :D

galagast
01-06-2005, 01:21 AM
this is where the "FOR" loops comes in...

e.g.

for i in selection do
(
if superclassof i == shape do (addmod extrude ; i.modifiers[#extrude].amount = 72)
)

*** note that we replaced the "$" with "i"... and "i" can be any keyword u want, and it contains ur current selection.

another one...

for i in 1 to $.count do
(
if superclassof $[i] == shape do (addmod extrude ; $[i].modifiers[#extrude].amount = 72)
)

*** in this part, we replaced "i" with "$[i]"... where "i" would contain an index number. which will start from 1 to your selection count.

u cud try this very quickly, make multiple selection of objects, then type in the listener:
$[1]
then
$[2]
and so on...
it will let u dig through individual objects even if you hav multiple object selections..

i hope this helps!

FreakyDude
01-06-2005, 01:58 PM
Well right now I got one version that works only if the base object is a spline,

and 2 variations that don't work the way I expect them to.

This one works for one object, regardless of it being a shape or an emesh/epoly:

macroScript Macro7
category:"DragAndDrop"
toolTip:""
(
if superclassof $ == shape do
(
addmod extrude ;
$.modifiers[#Extrude].amount = 128
$.modifiers[#Extrude].mapCoords = on
$.modifiers[#Extrude].matIDs = on
$.modifiers[#Extrude].smooth = on
$.modifiers[#Extrude].capType = 0
$.modifiers[#Extrude].capStart = on
$.modifiers[#Extrude].capEnd = on
)
addmod Uvwmap ;
$.modifiers[#UVW_Mapping].maptype = 4
addmod Normalmodifier ;
$.modifiers[#Normal].unify = on
$.modifiers[#Normal].flip = on
convertTo $ Editable_Poly
addMod Unreal_Brush ui:on
)


I'd expect the following to work also, and for a selection, but it doesn't:

macroScript Macrotest
category:"DragAndDrop"
toolTip:""

for i in selection do
(
ifsuperclassof $ == shape do
(
addmod extrude ;
i.modifiers[#Extrude].amount = 128
i.modifiers[#Extrude].mapCoords = on
i.modifiers[#Extrude].matIDs = on
i.modifiers[#Extrude].smooth = on
i.modifiers[#Extrude].capType = 0
i.modifiers[#Extrude].capStart = on
i.modifiers[#Extrude].capEnd = on
)
addmod Uvwmap ;
i.modifiers[#UVW_Mapping].maptype = 4
addmod Normalmodifier ;
i.modifiers[#Normal].unify = on
i.modifiers[#Normal].flip = on
convertTo $ Editable_Poly
addMod Unreal_Brush ui:on
)

It gives the following error:
-- Unknown property: "modifiers" in $selection

If I try this one on a single spline object, it gives me the following material error:
-- Argument count error: setMaterialIndex wanted 2, got 1


I also tried this version:

macroScript Macro8
category:"DragAndDrop"
toolTip:"test?"

for i in 1 to $.count do
(
ifsuperclassof $ == shape do (addmod extrude ;
$[i].modifiers[#Extrude].amount = 128
$[i].modifiers[#Extrude].mapCoords = on
$[i].modifiers[#Extrude].matIDs = on
$[i].modifiers[#Extrude].smooth = on
$[i].modifiers[#Extrude].capType = 0
$[i].modifiers[#Extrude].capStart = on
$[i].modifiers[#Extrude].capEnd = on
)
addmod Uvwmap ;
$[i].modifiers[#UVW_Mapping].maptype = 4
addmod Normalmodifier ;
$[i].modifiers[#Normal].unify = on
$[i].modifiers[#Normal].flip = on
convertTo $ Editable_Poly
addMod Unreal_Brush ui:on
)
It also gives me the following error:
-- Unknown property: "modifiers" in $selection

If I try this one on a single spline it does convert to editable poly and add an unrealbrush modifier, but it didn't flip the normals first.
If I type $[i] in the listener and replace i with a number, it does indeed display the properties of the corresponding object.

Basically I want to get the effect the first script gives me, only on a selection. Maybe even a mixed shape&epoly selection. But it just keeps giving me these errors....

Once I'get this working, and figure out how to implement the properties from the unrealbrush modifier, I might try to make a version that first gives you a floating toolbar with 4 buttons. One button for every type of unrealbrush....

But if anyone knew how to get the multiple selection thing working, I'd allready be very gratefull :) :P

galagast
01-06-2005, 04:04 PM
here are the fixed versions..
try to see the difference between the previous codes.
there were just some minor problems, but u were close.



for i in selection do
(
if superclassof i == shape do
(
addmodifier i (extrude())
i.modifiers[#Extrude].amount = 128
i.modifiers[#Extrude].mapCoords = on
i.modifiers[#Extrude].matIDs = on
i.modifiers[#Extrude].smooth = on
i.modifiers[#Extrude].capType = 0
i.modifiers[#Extrude].capStart = on
i.modifiers[#Extrude].capEnd = on
)
addmodifier i (Uvwmap())
i.modifiers[#UVW_Mapping].maptype = 4
addmodifier i (Normalmodifier())
i.modifiers[#Normal].unify = on
i.modifiers[#Normal].flip = on
convertTo $ Editable_Poly
addmodifier i (Unreal_Brush ui:on)
)

when using this method, u must remember that the "i" in selection is where your obects (any variable), so for this instance, the stored values are your selection of objects, whereas the method below stores the ".count" values to "i". To summarize it, method A got an array (collection) of objects, while method B got an array of numbers.



for i in 1 to $.count do
(
if superclassof $ == shape do
(
addmodifier $[i] (extrude())
$[i].modifiers[#Extrude].amount = 128
$[i].modifiers[#Extrude].mapCoords = on
$[i].modifiers[#Extrude].matIDs = on
$[i].modifiers[#Extrude].smooth = on
$[i].modifiers[#Extrude].capType = 0
$[i].modifiers[#Extrude].capStart = on
$[i].modifiers[#Extrude].capEnd = on
)
addmodifier $[i] (Uvwmap())
$[i].modifiers[#UVW_Mapping].maptype = 4
addmodifier $[i] (Normalmodifier())
$[i].modifiers[#Normal].unify = on
$[i].modifiers[#Normal].flip = on
convertTo $[i] Editable_Poly
addmodifier $[i] (Unreal_Brush ui:on)
)


although i'd recommend using the "selection" method (A) bcoz the latter method wont work on single selections. an alternative wud be something like this:

objsel = selection
for i in 1 to objsel.count do print objsel[i].name

thus it will work even of you only hav a single selection.

i hope this helps! im still open to some other alternative routes. :)

---here are some tips on posting for easier readabilty here @ at cgtalk forums (im using CODE on this)
http://www.cgtalk.com/misc.php?do=bbcode
and click here for a cool tool from Rens Heeren

FreakyDude
01-06-2005, 09:06 PM
thank you for your suggestions, especially the vb code, I was unaware of this.

Unfortunately, none of the code works, I've tried all three your suggestions, and mixed a few variations, and the results are definitly not what I want to get.

If I select multiple splines and use any of these three scripts on them, one spline gets extruded an maybe the normals flipped, one spline gets an unrealbrush modifier, and all splines are converted to epoly.
That was not quite what I had in mind, I got home about half an hour ago, and I'm fed up for now, I'm going to get something to eat and drink....

I have a version that works on single objects, regardless of it being spline or epoly... Just have to figure out how to get that working for all the objects at once...

Either way, thanks for your suggestions, they got me in the right direction...

galagast
01-06-2005, 09:46 PM
hmm.. that was really weird, i got that working a while ago... i guess i mustve copied and pasted the wrong codeor sumthing...and i tend to press CTRL+Z alot eheh, although maxscript only has 1 undo. well anyway, im really sory if i hav dissapointed u ...(well, im a lil dissapointed at myself for not double cheking the script) ... but this time its for real, i hav screen grabs of the b4 and after evaluation below.

well... i really hope this helps...

galagast
01-06-2005, 09:53 PM
attachments are limited to 2 posts so... heres the remainder of the grabs...

in the two previous scripts, on the first method "selection", i forgot to change this:
convertTo $ Editable_Poly
to this
convertTo i Editable_Poly

and on the next one...
this line:
if superclassof $ == shape do
to
if superclassof $[i] == shape do

and since i dont hav the Unreal plugin, i disabled them temporarily :)

thus, i ran the 3rd script with all those objects selected, here's the result in the listener...

objsel = selection
for i in 1 to objsel.count do print objsel[i].name
"Rectangle01"
"Line03"
"Circle01"
"Line02"
"Line01"
OK

FreakyDude
01-07-2005, 09:48 AM
Hey, thank you, at least the first one is allready working flawlessy, which was the one I think I'll be using most.

Another idea though, what if I wanted to have the last action (add a certain modifier) to add instances of that modifier to all the selected objects.
So if I change one property on one of these objects, I change properties on all previously selected object. That way, I wouldn't have to make several macro's for each operation, I'd just change one parameter afterwards...
So do you know how to code th last action to make instanced modifiers by any chance?

galagast
01-07-2005, 10:48 AM
yup, that I know of. :thumbsup:

to instance mods

mymod = bend()
addmodifier selection mymod


for non-instance mods

mymod2 = copy mymod
addmodifier selection mymod2


glad to hear something is finally working! hehe.

a very good resource of maxscripts (in case u didnt know yet :) ).
www.scriptspot.com (http://www.scriptspot.com)
u can learn by looking at how they did some scripts from there.

FreakyDude
01-07-2005, 11:21 AM
Nope, doesn't work.

well, at least, it does give the selection a shared modifier, but it also piles up the amount of modifiers.
So the first line has 1 mod, the second 2 etc...
Regardless of where I place the new lines of code, inside, before, or after the for loop, it just ends up piling up the modifiers. I suppose I'm merely making yet another mistake, either way, here's the latest script, the one that logically seems best for this task

macroScript JamlanderMacro2
category:"JamlanderHelper"
toolTip:""
(
for i in selection do
(
if superclassof i == shape do
(
addmodifier i (extrude())
i.modifiers[#Extrude].amount = 128
i.modifiers[#Extrude].mapCoords = on
i.modifiers[#Extrude].matIDs = on
i.modifiers[#Extrude].smooth = on
i.modifiers[#Extrude].capType = 0
i.modifiers[#Extrude].capStart = on
i.modifiers[#Extrude].capEnd = on
)
addmodifier i (Uvwmap())
i.modifiers[#UVW_Mapping].maptype = 4
addmodifier i (Normalmodifier())
i.modifiers[#Normal].unify = on
i.modifiers[#Normal].flip = on
convertTo i Editable_Poly
)
mymod = (Unreal_Brush())
addmodifier selection mymod
)


Placing the mymod line before the loop and the addmodifier line after the loop didn't work either. I tried placing them both before(although that can't be the way, since it first applies the ubrush then...) the loop, but it seems to me it's logical to place them after the loop? right? Still doesn't work :P :( But hey, I'm getting there.

galagast
01-07-2005, 01:03 PM
mymod = (bend())
for i in selection do
(
if superclassof i == shape do
(
addmodifier i (extrude())
i.modifiers[#Extrude].amount = 128
i.modifiers[#Extrude].mapCoords = on
i.modifiers[#Extrude].matIDs = on
i.modifiers[#Extrude].smooth = on
i.modifiers[#Extrude].capType = 0
i.modifiers[#Extrude].capStart = on
i.modifiers[#Extrude].capEnd = on
)
addmodifier i (Uvwmap())
i.modifiers[#UVW_Mapping].maptype = 4
addmodifier i (Normalmodifier())
i.modifiers[#Normal].unify = on
i.modifiers[#Normal].flip = on
convertTo i Editable_Poly
addmodifier i mymod
)

I placed the "mymod = (bend())" at the top, not within the script. If we place it within the loop, the value of mymod will get defined each time the loop iterates, we just need to define it once so the value (even though its still the same modifier) will remain constant.
The "addmodifier i mymod" was placed within the script, so that we could assign the value "mymod" (which was defined once) to each object in the loop.
In latter example, we used "selection" and if we place that within the loop, it will assgin a modifier to all of our selection for every loop pass. thats why you have piled up modifiers.
You were getting close, "Placing the mymod line before the loop and the addmodifier line after the loop didn't work either", the addmofier line must be inside the loop. :thumbsup:

FreakyDude
01-07-2005, 11:57 PM
Works like a charm :D

Thank you.

CGTalk Moderation
01-20-2006, 08:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.