Notifications
Clear all

[Closed] select all

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
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?

16 Replies

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. i hope this helps!

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:
[size=2][color=white]polyop.setFaceSelection $.baseobject #all
[/color][/size]

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.

Hey for the checking if it’s a spline object or not you could use this on the extrude part of the script:

[size=2][color=white]if [/color]superclassof $ == shape do (addmod extrude ; $.modifiers[#extrude].amount = 72)[/size]
[size=2][/size]
[size=2]So if it’s not a splineshape that part will be skipped.[/size]

[size=2]CML
[/size]

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

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!

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

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 $[i] == shape do [/i]
[i]([/i]
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 [thread=185272]here[/thread] for a cool tool from Rens Heeren

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…

Page 1 / 2