Jump to content

Controlled Viewport Pan Lisp Problem


KRBeckman

Recommended Posts

Can anybody see why I'm getting a bad function: 0 error?

 

(defun c:rf (/ vp dir dis vpn pdr dms vc1 vx1 vy1 vz1 vc2 vx2 vy2 vz2)
 (command "zoom" "w" "-0.5,-0.5" "11,8.5")
 (setq vp  (getstring "\nWhich Viewport would you like to pan?<Top(T), Front(F), Right(R)>: "))
 (setq dir (getstring "\nWhich direction would you like to pan the viewport?<Up(U), Down(D), Left(L), Right(R)>: "))
 (setq dis (getreal   "\nHow far would you like to pan the viewport? "))
 (setq vpn (if (= vp "Top") (2)
      (if (= vp "T") (2)
 (if (= vp "Front") (5)
   (if (= vp "F") (5)
     (if (= vp "Right") (4)
       (if (= vp "R") (4)
  (0))))))))
 (setq pdr (if (= dir "Up") ("Up")
      (if (= dir "U") ("Up")
 (if (= dir "Down") ("Do")
   (if (= dir "D") ("Do")
     (if (= dir "Left") ("Le")
       (if (= dir "L") ("Le")
  (if (= dir "Right") ("Ri")
    (if (= dir "R") ("Ri"))))))))))
 (setq dms (getvar "dimlfac"))
 (if (= vpn 2) (if (= dir "Up")
   (progn
     (command "_.mspace")
     (setvar "cvport" vpn)
     (command "ucs" "top")
     (setq vc1 (getvar "viewctr"))
     (setq vx1 (car vc1))
     (setq vy1 (cadr vc1))
     (setq vz1 (caddr vc1))
     (setq vy2 (+ vy1 (* dis dms)))
     (setq vc2 '(vx1 vy2 vz1))
     (setvar "viewctr" vc2))
   )
   )
 )

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • KRBeckman

    9

  • Lee Mac

    8

  • David Bethel

    4

  • lpseifert

    2

Top Posters In This Topic

Autolisp expects a function after a (

An integer after a ( isn't acceptable, hence the error

You may want to look at your other post.

Link to comment
Share on other sites

Well, I got rid of that error and now I'm getting "nil" and the command line and when I type "!vp" into the command line to see if it assigned anything to the "vp" variable in get nil. Any ideas?

Link to comment
Share on other sites

Well, I got rid of that error and now I'm getting "nil" and the command line and when I type "!vp" into the command line to see if it assigned anything to the "vp" variable in get nil. Any ideas?

Since you declared all the variables as local, when you exit the routine the variables are reset to what they were prior. While debugging a routine you may want to not declare your variables. You may also want to look into using Vlide and the Watch tool.

Link to comment
Share on other sites

lol, don't like all my if-then functions? I'll look into it.

 

Well, you'd be better off using the IF statements where they matter - allowing for a null user input :thumbsup:

Link to comment
Share on other sites

David - good call, thanks.

 

Lee - I'm having a problem with the initget/getkword functions. Can you have two of them in a row like:

 

(initget "Top Front Right")

(setq wvp (getkword "\nWhich Viewport would you like to pan?: "))

(initget "Up Down Left Right")

(setq drc (getkword "\nWhich direction would you like to pan the viewport?: "))

Link to comment
Share on other sites

Yes, this shouldn't cause a problem.

 

But, also be aware of the bit-codes that initget can use. Currently with your setup, if the user hits enter, getkword will return nil. So you may want to use:

 

(initget 1 "Top Front Right")
 (setq wvp (getkword "\nWhich Viewport would you like to pan?<Top(T), Front(F), Right(R)>: "))

 

PS> Are you writing your code in a code editing program (for example the Visual LISP Editor) or just in plain Notepad?

Link to comment
Share on other sites

I so close... Why is it not using vc2 as the center in the zoom command?

 

(defun c:rf ()
 (command "zoom" "w" '(-0.5 -0.5 0.0) '(11.0 8.5 0.0))
 (initget 1 "Top Front Right")
 (setq wvp (getkword "\nWhich Viewport would you like to pan?<Top(T), Front(F), Right(R)>: "))
 (initget 1 "Up Down Left Right")
 (setq drc (getkword "\nWhich direction would you like to pan the viewport?<Up(U), Down(D), Left(L), Right(R)>: "))
 (setq dis (getreal   "\nHow far would you like to pan the viewport? "))
 (setq vpn (if (= wvp "Top") 2
 (if (= wvp "Front") 5
     (if (= wvp "Right") 4
  ))))
 (setq dms (getvar "dimlfac"))
 (if (= vpn 2) (if (= drc "Up")
   (progn
     (command "_.mspace")
     (setvar "cvport" vpn)
     (command "ucs" "top")
     (setq vc1 (getvar "viewctr"))
     (setq vx1 (car vc1))
     (setq vy1 (cadr vc1))
     (setq vz1 (caddr vc1))
     (setq vy2 (+ vy1 (* dis dms)))
     (setq vc2 '(vx1 vy2 vz1))
     (command "zoom" "c" vc2 "")
     )
   )
   )
 )
 

Link to comment
Share on other sites

Try this:

 

(defun c:rf (/ DIS DMS DRC VC1 VPN VX1 VY1 VY2 VZ1 WVP)
 
 (command "_.zoom" "_w" '(-0.5 -0.5 0.0) '(11.0 8.5 0.0))
 
 (initget 1 "Top Front Right")
 (setq wvp (getkword "\nWhich Viewport would you like to pan?<Top(T), Front(F), Right(R)>: "))
 
 (initget 1 "Up Down Left Right")
 (setq drc (getkword "\nWhich direction would you like to pan the viewport?<Up(U), Down(D), Left(L), Right(R)>: "))

 (initget 7) ;; Might want to disallow -ve's also
 (setq dis (getreal "\nHow far would you like to pan the viewport? "))

 (setq vpn
   (cond ( (eq wvp "Top")   2)
         ( (eq wvp "Front") 5)
         ( (eq wvp "Right") 4)))
 
 (setq dms (getvar "dimlfac"))
 
 (if (= vpn 2)
   (if (= drc "Up")
     (progn
       (command "_.mspace")
       (setvar "cvport" vpn)
       (command "_.ucs" "_top")
       
       (setq vc1 (getvar "viewctr"))
       (setq vx1 (car vc1))
       (setq vy1 (cadr vc1))
       (setq vz1 (caddr vc1))
       (setq vy2 (+ vy1 (* dis dms)))

       (command "_.zoom" "_c" (list vx1 vy2 vz1) ""))))

 (princ))

 

The error was the use of the apostrophe, to explain the error, read this:

 

http://www.cadtutor.net/forum/showpost.php?p=258390&postcount=20

Link to comment
Share on other sites

I had mose of it right. Thanks again. I'll get there soon enough.

 

True, it wasn't bad - I would encourage you to make use of COND where multiple IF statements can be replaced.

Link to comment
Share on other sites

Is there a reason you used "eq" in the cond function or can "=" be used too?

 

I would recommend using 'eq' to compare strings/expressions. '=' (and 'equal' for that matter) is normally used for numerical comparison.

Link to comment
Share on other sites

I'm not a big fan ( eq )

 

Just look at the example of the help files:

 

(setq f1 '(a b c))

(setq f2 '(a b c))

 

(setq f3 f2)

 

Compare f1 and f3:

 

Command: (eq f1 f3)

 

nil

 

For that matter:

 

(eq f1 f2) returns nil

 

It's just not that intuitive for me.

 

I do use it for comparing ENAMEs in that are they are bound to symbols.

 

(=) converts strings to their ASCII numbers and compares them that way.

 

(= "Z" "z") returns nil

 

-David

Link to comment
Share on other sites

Well, it pretty much only works for me, cause my titleblock viewports are numbered the way i need them to, but here's the "final" draft:

 

(defun c:rf (/ DIS DMS DRC MDS VC1 VPN VX1 VY1 VY2 VZ1 WVP)
 
 (command "_.pspace")
 (command "_.zoom" "_w" '(-0.5 -0.5 0.0) '(11.0 8.5 0.0))
 
 (initget 1 "Top Front Right")
 (setq wvp (getkword "\nWhich Viewport would you like to pan?<Top(T), Front(F), Right(R)>: "))
 
 (initget 1 "Up Down Left Right")
 (setq drc (getkword "\nWhich direction would you like to pan the viewport?<Up(U), Down(D), Left(L), Right(R)>: "))
 (initget 7)
 (setq dis (getreal "\nHow far would you like to pan the viewport? "))
 (setq vpn
   (cond ( (eq wvp "Top")   2)
         ( (eq wvp "Front") 5)
         ( (eq wvp "Right") 4)))
 
 (setq dms (getvar "dimlfac"))
 (command "_.mspace")
 (setvar "cvport" vpn)
 (command "_.ucs" "_top")
 (setq vc1 (getvar "viewctr"))
 (setq vx1 (car vc1))
 (setq vy1 (cadr vc1))
 (setq vz1 (caddr vc1))
 (setq mds (* dis dms))
 (setq vx2 (cond ( (eq wvp "Top")   (cond ( (eq drc "Up")    vx1)
       ( (eq drc "Down")  vx1)
       ( (eq drc "Left")  (+ vx1 mds))
       ( (eq drc "Right") (- vx1 mds))))
   ( (eq wvp "Front") (cond ( (eq drc "Up")    vx1)
       ( (eq drc "Down")  vx1)
       ( (eq drc "Left")  (+ vx1 mds))
       ( (eq drc "Right") (- vx1 mds))))
   ( (eq wvp "Right") (cond ( (eq drc "Up")    vx1)
       ( (eq drc "Down")  vx1)
       ( (eq drc "Left")  vx1)
       ( (eq drc "Right") vx1)))))
 (setq vy2 (cond ( (eq wvp "Top")   (cond ( (eq drc "Up")    (- vy1 mds))
       ( (eq drc "Down")  (+ vy1 mds))
       ( (eq drc "Left")  vy1)
       ( (eq drc "Right") vy1)))
   ( (eq wvp "Front") (cond ( (eq drc "Up")    vy1)
       ( (eq drc "Down")  vy1)
       ( (eq drc "Left")  vy1)
       ( (eq drc "Right") vy1)))
   ( (eq wvp "Right") (cond ( (eq drc "Up")    vy1)
       ( (eq drc "Left")  (+ vy1 mds))
       ( (eq drc "Right") (- vy1 mds))))))
 (setq vz2 (cond ( (eq wvp "Top")   (cond ( (eq drc "Up")    vz1)
       ( (eq drc "Down")  vz1)
       ( (eq drc "Left")  vz1)
       ( (eq drc "Right") vz1)))
   ( (eq wvp "Front") (cond ( (eq drc "Up")    (- vz1 mds))
       ( (eq drc "Down")  (+ vz1 mds))
       ( (eq drc "Left")  vz1)
       ( (eq drc "Right") vz1)))
   ( (eq wvp "Right") (cond ( (eq drc "Up")    (- vz1 mds))
       ( (eq drc "Down")  (+ vz1 mds))
       ( (eq drc "Left")  vz1)
       ( (eq drc "Right") vz1)))))
 
 (command "_.zoom" "_c" (list vx2 vy2 vz2) "")
 (command "_.pspace")
 (princ))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...