Home Technical Talk

Joltya's MAXscripting adventures!

polycounter lvl 10
Offline / Send Message
Joltya polycounter lvl 10
Hey everyone! I just got into scripting a couple of days ago and I want to start tracking my progress and potentially get some pointers and some feedback from more advanced scripters. I'm still very new and my stuff is super simple, so don't get your hopes up for anything awesome.

Here's the first script that I made. I got it by chopping up Perna's SmartCreate script and making it into something else that I could use. In vertex mode, it enters cut mode; in edge mode, it spins the edge; and in face mode, it will flip the face. It works pretty well.
--Cut verts
    if (subobjectlevel==1) then
        macros.run "Editable Polygon Object" "EPoly_Cut"
--Spin edge
    else if (subobjectlevel==2) then
        macros.run "PolyTools" "SpinEdge"
-- Flip face
    else if (subobjectlevel==4) then    
        macros.run "Ribbon - Modeling" "FaceFlip"
---

I'm trying to work on a script that will consolidate all my views to 4 buttons (Pers/Orth, Top/Bottom, Front/Back, Left/Right). The idea is to be able to go from one view to another by toggling into another one. For example, in this script, I can go from any view to Top view, and if I want to enter Bottom view, I hit the button again.

if viewport.getType() != #view_top then 
        (viewport.setType #view_top)
    else if viewport.getType() == #view_top then 
        (viewport.setType #view_bottom)
Although that code works, I'm having a problem with getting it to work with Pers/Orth. Here's the code I have so far:
if viewport.getType() != #view_pers_user then 
        (viewport.setType #view_persp_user)
    else if viewport.getType() == #view_persp_user then 
        (viewport.setType #view_iso_user)
While this one does go from any orthographic view to Perspective, it doesn't seem to go back to an orthographic view when I run it again. I did make an alternative that works somewhat better (change in blue):
if viewport.getType() [COLOR=RoyalBlue][B]== #view_iso_user[/B][/COLOR] then 
        (viewport.setType #view_persp_user)
    else if viewport.getType() == #view_persp_user then 
        (viewport.setType #view_iso_user)
While this does go back and forth between Orthographic and Perspective, obviously it doesn't go into Perspective if I'm in top/bottom/left/right view. I can't for the life of me figure out why the first one doesnt' works but this one does. If anyone has a solution for me, please let me know! :D

Replies

  • Surfa
    Options
    Offline / Send Message
    Surfa polycounter lvl 12
    You have a small spelling mistake in the first block of code for swapping between perspective and orthographic. This obviously will cause it to not swap back from perspective.
    if viewport.getType() != #view_pers[COLOR="Red"]p[/COLOR]_user then 
            (viewport.setType #view_persp_user)
        else if viewport.getType() == #view_persp_user then 
            (viewport.setType #view_iso_user)
    
  • Joltya
    Options
    Offline / Send Message
    Joltya polycounter lvl 10
    Surfa wrote: »
    You have a small spelling mistake in the first block of code for swapping between perspective and orthographic. This obviously will cause it to not swap back from perspective.

    BAHAHAHA wow I'm an idiot. Well that does work! Thanks a lot! :thumbup:
  • Joltya
    Options
    Offline / Send Message
    Joltya polycounter lvl 10
    I did assemble the entire script now and it's working exactly how I want it to. I know it's super simple stuff, but I figure I can go ahead and share it incase anyone else wants it.
    macroScript ViewToggle_PersOrth category:"Joltya Tools" toolTip:"View - Pers/Orth Toggle"
    
    (
        if viewport.getType() != #view_persp_user then 
            (viewport.setType #view_persp_user)
        else if viewport.getType() == #view_persp_user then 
            (viewport.setType #view_iso_user)
    )
    
    macroScript ViewToggle_TopBot category:"Joltya Tools" toolTip:"View - Top/Bottom Toggle"
    
    (
        if viewport.getType() != #view_top then 
            (viewport.setType #view_top)
        else if viewport.getType() == #view_top then 
            (viewport.setType #view_bottom)
    )
    
    macroScript ViewToggle_FroBak category:"Joltya Tools" toolTip:"View - Front/Back Toggle"
    
    (
        if viewport.getType() != #view_front then 
            (viewport.setType #view_front)
        else if viewport.getType() == #view_front then 
            (viewport.setType #view_back)
    )
    
    macroScript ViewToggle_RitLef category:"Joltya Tools" toolTip:"View - Right/Left Toggle"
    
    (
        if viewport.getType() != #view_right then 
            (viewport.setType #view_right)
        else if viewport.getType() == #view_right then 
            (viewport.setType #view_left)
    )
    
Sign In or Register to comment.