Announcement

Collapse
No announcement yet.

Helping a hopeless maxscripting guy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by mmrender View Post
    Hi Jrandom, I try the first piece of code that you sent, following your instructions and it is working for me perfectly. I was applying it to a cilinders with no problem. Only, I would need to apply to several objects at the same time, could you help me on that? I suposse it is a matter of add a line in the code but I'm very poor with this issue. Many thanks, you make my day.
    Code:
    try(destroyDialog AlignBboxToObject)Catch()
    --arrays
    Obj_arr = #()
    list_arr = #()
    --functions
    fn AlignBBoxToFirstNormalfn1 theObject = --Function written by Borislav Petrov
          (
              theCurrentTM = theObject.transform --this is the current transformation
              theMesh = snapshotasmesh theObject --get the world space TriMesh
              theTM = matrixFromNormal (getFaceNormal theMesh 1) --build a matrix from normal
              delete theMesh --delete the TriMesh from memory
               theTM.row4 = theCurrentTM.row4 --set the position of the new matrix to the old pos
              theObject.transform *= inverse theTM --transform out of world space 
              resetXForm theObject --reset the XForm
              convertToMesh theObject --collapse the stack
              theObject.transform = theTM --transform back into world space
          )
     fn AlignBBoxToFirstNormalfn2 theObject = --Function written by Borislav Petrov
         (
             theCurrentTM = theObject.transform
             theMesh = snapshotasmesh theObject
             theZ = normalize (getFaceNormal theMesh 1)
             theFace = getFace theMesh 1
             theY = normalize ((getVert theMesh theFace.y)-(getVert theMesh theFace.x))
             theX = normalize (cross theY theZ)
             theTM = matrix3 theX theY theZ theCurrentTM.row4
             theObject.transform *= inverse theTM
             resetXForm theObject
             convertToMesh theObject
             theObject.transform = theTM
          ) 
      
    fn Obj_filt obj = isKindOf obj GeometryClass 
    fn objList =
        (
            list_arr = for o in Obj_arr where isValidNode (obj = getNodeByName o) collect obj
        )
    --rollouts
    rollout AlignBboxToObject "Align Bounding Box" width:200 height:200
    (
        button btn_Load "load"
        ListBox lst_objs
        button btn_doFn1 "Function 1" across:2
        button btn_doFn2 "Function 2"
        
        on btn_Load pressed do
            (
                Obj_arr = #()
                SelObj = selectByName title:"List Objects" filter:Obj_filt()
                if SelObj != undefined do
                    (
                        for i in SelObj do
                            (    
                                append Obj_arr i.name
                                
                                objList()
                            )
                    )
                if Obj_arr.count != 0 then
                    (
                    lst_objs.items = Obj_arr
                    )
            )
        on btn_doFn1 pressed do
            ( 
                deselect
                for o in list_arr do
                (
                    AlignBBoxToFirstNormalfn1 o
                )
            )
        on btn_doFn2 pressed do
            ( 
                deselect
                for o in list_arr do
                (
                    AlignBBoxToFirstNormalfn2 o
                )
            )
        on AlignBboxToObject closed do
            (
                Obj_arr = #()
                list_arr = #()
            )
    )
    CreateDialog  AlignBboxToObject  width:200 height:200
    Both functions are included. So if one doesn't work use the other.
    particle makes perfect

    Comment


    • #17
      Thank you man!! I test it in my scene with cylinders and the Function 2 works perfect.
      Once again the people of this forum is amazing! I hope to be able to help back someday.

      Manuel

      Comment

      Working...