Home Technical Talk

MaxScript Help needed.

polycounter lvl 14
Offline / Send Message
SpeCter polycounter lvl 14
I need help with mascript.

I want to to be able to get the height of an object and one that places the pivot point at the bottom center of my model and place it at 0,0,0.

Help would be very much appreciated.

Replies

  • Mark Dygert
    Options
    Offline / Send Message
    I have a script I wrote that has a function that does that.
    "Pivot to World Zero"
    VigToolsSceneClean.jpg
    http://dl.dropbox.com/u/2336353/SceneClean.ms

    Feel free to rip the code out and purpose it however you need, or run the script once from anywhere and then you'll find it under Customize UI > Category: "VigTools"
  • Yozora
    Options
    Offline / Send Message
    Yozora polycounter lvl 11
    (
    ResetPivot $
    for i in selection do
    (
    i.pivot = [i.pivot.x, i.pivot.y, i.min.z]
    )
    $.pos = [0,0,0]
    )
  • SpeCter
    Options
    Offline / Send Message
    SpeCter polycounter lvl 14
    This works perfect, now i just need to know how to get the height of an object(or resources to look it up)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
  • SpeCter
    Options
    Offline / Send Message
    SpeCter polycounter lvl 14
    @r_fletch_r: Needed to change it to node.max.z - node.min.z otherwise it must stand on the ground for it to get it´s real height.

    I finally got some things working on my own, but there are some things i don´t understand and i can´t find a solution for it.

    Is it possible to determine if something was selected or not?
    And is it possible to change a value of a label if something is selected?(and if it´s possible to change that value in realtime in case the selected object changes?)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Define 'Something' there are lots of things you can select in max. for nodes which i guess your talking about.

    To work on selected objects you use the 'selection' collection

    so
    for obj in selection do
    (
    --extract a Node from the selection and store it in the variable obj.
    print obj.name -- print the objects name
    )

    That code will loop through the whole selection, pulling out a node at a time and letting you work with it.

    If you want to tell if a node is in the selection collection then I use findItem which returns the nodes index in the selection or 0 if its not in it.
    nIndex = findItem (selection as array) nodeToCheckFor

    if nIndex != 0 then
    (
    -- if the index is not Zero then the node is in the selection.
    )




    I think the property you want for labels is .text
  • SpeCter
    Options
    Offline / Send Message
    SpeCter polycounter lvl 14
    it´s not that i can´t change the text of a label(and the property is caption).
    The problem is, that i have to click on a button to update the value, but i want it to change if i select an object, change it for example.

    this "for obj in selection do" what happens if i run the script and nothing is selected?
    My problem is, that i don´t want to have a error message saying something like "xyz only works if something is selected"
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    the selection is empty so nothing happens. selection allways exists so it wont throw and error.

    So far as updating a label when the selection changes, You can add a timer to your rollout. in its tick event put the update code. it helps to check for a change before updating the UI. if you dont you get some flicker
  • SpeCter
    Options
    Offline / Send Message
    SpeCter polycounter lvl 14
    Ok works good so far :)
    But i used callbacks for it, unfortunately i couldn´t find a callback for changing the mesh, but atm the one for selecting is enough.

    Now i need to look into selection/recursion and stuff and i can do some fancy stuff(hopefully, if not I have to look into the C++ Api which i want to avoid if possible :D)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    search for nodeEventCallbacks.

    Have you looked into Epheres C# SDK for max, its a bit of an easy path to go down than the C++ route, especially considering the plugins refresh with max without any need to restart the app.
  • SpeCter
    Options
    Offline / Send Message
    SpeCter polycounter lvl 14
    I have coded in C++ but never in C# before, but i will look into it if I can´t do what i want in maxscript.
Sign In or Register to comment.