[Closed] try to learn maxscript
Hello.
i learn maxscript.
I try to make a script that generate a simple stand plane.
the creation style is: i click on the grid in perpective view that determine the first vertex then (while maintaining the first click) i displace my mouse to trace the width of the plane. i release the button and i move my mouse to determine the height of the plane.
I try this code but i don’t work like i want:
Plugin simpleobject XXXXX
name:“XXXXX”
category:“XXXXXXXX”
classID:#(XXXXXXX, XXXXXXXX)
(
parameters main rollout:params
(
num_plane type:#worldunits ui:num_plane default:1
plane_length type:#worldunits ui:plane_length default:20
plane_width type:#worldunits ui:plane_width default:10
)
rollout params "TreeMap"
(
spinner num_plane "Plane Number" range:[1,20,1] type:#worldunits
spinner plane_length "Length" range:[0,10000,20] type:#worldunits
spinner plane_width "Width" range:[0,10000,10] type:#worldunits
)
on buildmesh do
(
setmesh mesh \
verts:#([0,0,0],[plane_width,0,0],[plane_width,plane_length,0],[0,plane_length,0]) \
faces:#([1,2,4], [2,3,4])
)--end buildmesh
tool create
(
on mousePoint click do
case click of
(
1: nodeTM.translation = gridPoint
)
on mousemove click do
case click of
(
2: (plane_length=abs(gridDist.y))
3: (plane_width=abs(gridDist.x))
4: (#stop)
)
) --end create
) –end plugin
Somebdoy have a solution for that;
I learn in “maxscript reference help” in max but this help is not very simple to use. A lot of informations in a lot of places. it’s speleology not learning
Thanks a lot for your help guys !
Not sure this is what you want, but
Plugin simpleobject StandPlane
name:"StandPlane"
category:"Forum Help"
classID:#(0x20d13a72, 0x423acb77)
(
parameters main rollout:params
(
num_plane type:#worldunits ui:num_plane default:1
plane_length type:#worldunits ui:plane_length default:20
plane_width type:#worldunits ui:plane_width default:10
)
rollout params "TreeMap"
(
spinner num_plane "Plane Number" range:[1,20,1] type:#worldunits
spinner plane_length "Length" range:[0,10000,20] type:#worldunits
spinner plane_width "Width" range:[0,10000,10] type:#worldunits
)
on buildmesh do
(
setmesh mesh \
verts:#([0,0,0],[plane_width,0,0],[plane_width,0,plane_length],[0,0,plane_length]) \
faces:#([1,2,4], [2,3,4])
)--end buildmesh
tool create
(
on mousePoint click do
case click of
(
1: nodeTM.translation = gridPoint
)
on mousemove click do
case click of
(
2: (plane_width=abs(gridDist.x))
3: (plane_length=abs(gridDist.y))
4: (#stop)
)
) --end create
) --end plugin
The help file is a MAXScript REFERENCE. A Reference is for finding information that you know you are looking for, not for learning. Still, it contains an introduction tutorials section, a How To section containing a large number of tutorials with explanations of each line of code, and a FAQ containing even more examples and answers.
You could of course buy the MAXScript DVDs from CG-Academy.net or take a look at the Courseware that Autodesk is selling.
Or just learn the way we all have – experiment, dissect other people’s scripts, ask questions here…
No post ?? 🙁
I found a lot of tutorials about maxscript.
I want to know what is the difference between script and macroscript in maxscript ?
I want to do a utility apply on an object to automatize some functions, but i want the utility stay modifiable even i restart max and reload the scene. Do you know what form of scripting use to do it ?
Thanks a lot for your help guys :buttrock:
MCR is short for MacroRecorder file.
MacroScripts were designed to package the output of the MacroRecorder.
You say you want to create a utility to automate some functions, I would suggest you dont dive straight into the deepend but break it up into some simple tests/experiments releated to the utility you ultimatly want to write.
Dan
Hello Dan.
Thanks a lot for your advice.
In fact, i want to make a script to animate a rubik’s cube. It’s not a simple way due to the fact that we aren’t able to modify a link, of a link constraint, of several selected objects in the same time. if i make a movement and i try to modify it. I must selected all cube, that compose the rubik’s cube, one by one to modify the link offset of the link constraint. That’ huge.
there’s only 26 cubes. but after the third modifying, you’ll go crazy. :banghead:
I understand how to do it with maxscript but now i’ve got to script it.
But i begin to learn maxscript 3days ago without book because i don’t find any to buy.
I’am damned
I find some tutorials and try to learn by blending all of it.
I make an interface to animate my rubix. I have a button that generate a system of dummies.
if you can answer me.
I want to create a link between link_constraint and my interface. When i animate i see the link of the link_constraint directly in my interface and i can edit them interactively.
Or i must recreate a link_constraint system inside my code to do it.
I’am lost
Someone can help meeee !
Thank a lot for your help
Ohhh, i can believe it 😮
BORISLAV PETROV !!!
That’s a great surprise !
I do the tutorial you make on scriptspot.com with the bitmap image makes boxes as pixels.
Very interesting.
I don’t very understand the role of array and the for loop in maxscript. they seem very important.
I dare to ask you a question.
I try to make a script:when i press a button a circle become parent of all dummies are in the same X value than it. Do you have an idea to do that ?
Thanks a lot for your help
macroScript DummyParentCircle category:"Forum Help"
(
on isEnabled return selection.count == 1 and classof selection[1] == Circle
on execute do
(
theCircle = selection[1]
theDummies = for o in helpers where classof o == Dummy and (in coordsys theCircle o.pos.z < 0.01) collect o
theDummies.parent = theCircle
)
)
The MacroScript should be placed on a toolbar, menu or quadMenu.
Create some dummies in the XY ground plane.
Create a Circle in the same plane.
Select the Circle – the button should become enabled.
Press the button – all objects of class dummy that have a Z axis value < 0.01 in the local space of the Circle will be parented to it.
Now rotate the circle about its X axis – the dummies will rotate, too.
Select all dummies and unlink them using the Unlink button in the Main Toolbar.
Select the Curcle and press again – the dummies will be re-linked to the Circle, because their Z are still close to 0 in its local coordinate space.
(The reason for not using o.pos.z == 0 is that matrix operations can cause slight errors, so the Z value could be 0.0000001 instead of 0.0 and the dummy would not be linked).
For Loops and Arrays are indeed very useful.
You will get the idea over time.
For example, in this script, a for loop is used to go through all Helper objects, ask them whether they are dummies and COLLECT those that match all criteria into a new array called theDummies. The array is a COLLECTION of values you can keep in memory and access quickly by index or through a for loop. Also, many MAXScript operations are MAPPABLE, meaning that they can be applied to a collection in addition to a single object. This is why the line theDummies.parent = theCircle works – every dummy in the array gets the same parent – it is a shorthand form of saying
for o in theDummies do o.parent = theCircle
The loop is performed internally when using a Mapped function and tends to be faster.
Hello Borislav.
Thank a lot for your help.:)
I try to put the macroscript on a toolbar i create but it don't want to put it on.
It return me a messagebox :
------------------------------------------------------------------------
-- Compile error:nested macroscript definitions are not permitted
-- in line: macroscript D
------------------------------------------------------------------------
I want to make a type of modifier. I explain: A script i launch and animate some functions but if i close max, restart it and reload the scene, i can edit the animation.
What do you suggest me to use to do this?
Thank a lot for your help.
It's a real pleasure.:)
Don’t drag&drop my script to a toolbar, it IS a macroScript ALREADY.
Just press Ctrl+E or File>Evaluate All, then right-click a toolbar>Customize etc. and you will find my script on the list under “Forum Help” category.
Dragging code to a toolbar adds the line MacroScript BlaBla category:“Drag&Drop”() around the selected code, and in your case you get a nested MacroScript definition.
As for the animation, please explain IN DETAIL what you want and how you would do it without a script. (scripting enhances what Max can already do, if you cannot do it with Max, chances are you might not be able to do it with scripting either).
You can create scripted Modifiers, you can create controllers and animation keys, you can add animation tracks to TrackView, so the question is – what does it mean to “animate some functions”… ?
Cheers,
Bobo
Hello Borislav.
I find the way to put it on a toolbar it’s work perfectly. I analyse it to understand how you make your code and what is the psychology of the code.
Oh yes. I think it's not very easy to understand my will.
in fact in try to make a tool to animate a rubik's cube.
I wrote a bunch of script to generate a system of dummies (that you can attach cubes on them to make the rendering of the rubik’s) with circles to manipulate the dummies.
My interface
[img] http://img420.imageshack.us/img420/7940/interface8xp.jpg [/img]
My reflexion is :
-
size spinner is to define the size of dummies but in this case it’s unuseful. it just determine the distance between two dummies.
-
When i click on the create button: the system is created. all dummies get a link_constraint_controller. I want to create a bigger dummy to control the entire system (called dummyall)
- click on delete:after a querybox, the system is deleted.
-
if i click on horizontal or vertical or tranversal: all circle_controlers are unfreeze and the dummies that are on the same X or Y or Z value (depends of the clicked button) of a circle are link to it (where link_constraint fonctions are used)
- After i animate the circles (keyframes of circles animation are create by max)
-
Each time i click on a button (H,V or T) the frame number of link_change is store in link_contraint link list and displayed in the list box “Axes swaps”.
- If i click on a swaps in list box “axes swaps”, i can modify it with “modify” spinner under it.
The change affect link_constraint link value too (to make the link change operate). And the value change in the list box. - I can delete a swaps by clicking on “delete swap”
The link_change is apply to all dummies (not on dummyall) in the same time.
To finish, if i close my scene and reload it. I want that my scene keep the same state.
in this case, i can modify my work and resave the file.I hope that will be more understandable (my english in very poor :p)
Thank a lot for your help. :)
- If i click on a swaps in list box “axes swaps”, i can modify it with “modify” spinner under it.
Hello Borislav.
I find some lines of code to interact with link constraint and a way to keep data in scene file:
“Parameters”.
I work on it.
I wait for your answer
Thanks a lot