See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: Error handling

  1. #1
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Error handling

    Hello everyone!

    I got some really great help from the folks here, the other day, and now unfortunately I am back.

    I got some code from one of the members here, and it does what I would like it to do. It does not however, have any built-in error handling abilities.

    What I would like, is for this routine to prompt me for a viewport, and allow me to rotate what I am seeing. It does that now. Here is the code I have so far:

    Code:
    (defun c:rvp (/ ss VpId ss1)
    	(SETVAR "CMDECHO" 0)
    	(SETQ SCMDE (GETVAR "CMDECHO"))
    	(setq ss (car (entsel "\nSelect viewport to rotate view: ")))
            (setq VpId (cdr (assoc 69 (entget ss))))
    	(setq ss1 (entget ss))
    	(command "_.MSPACE")
            (setvar "cvport" VpId)
    	(command "_.dview" "" "tw" (getreal "\n Enter angle desired: ") "")
    	(command "_.regenall")
    	(command "_.PSPACE")
    	(princ))
    I would like it to tell me:

    (alert "ERROR -- Command unavailable in view-locked viewport!")

    If the viewport I select has the display properties locked. Likewise, if I select any other type of entity, I would like it to go something like this:

    (alert "ERROR -- Entity selected is not a viewport!")

    I have been trying for the past couple of days toget this to work, without sucess. Would any of you be willing to help me out?

    Don
    Last edited by Opie; 2007-09-21 at 05:53 PM. Reason: [CODE] tags added

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Default Re: Error handling

    Here is one way. It doesn't do *exactly* what you asked. Those "alert" dialogs will get annoying very quick IMO... If you really want the "alert" boxes, it will take a bit more code.

    This version stays in a loop until you select an unlocked viewport object -or- you press ESC.

    Code:
    
    (defun c:rvp (/ w VpId)
      (SETVAR "CMDECHO" 0)
      (setq w T)
      (while w
        (setq sel (entsel "\nSelect viewport to rotate view: "))    
        (if	(and sel
    	     (setq ent (entget (car sel)))
    	     (eq (cdr (assoc 0 ent)) "VIEWPORT")
    	     (zerop (logand 16384 (cdr (assoc 90 ent))))
    	)
          (setq w nil)
          (princ "\n The selected object is not an UNLOCKED VIEWPORT!")
        )
      )
    
      (setq VpId (cdr (assoc 69 ent)))
      (command "_.MSPACE")
      (setvar "cvport" VpId)
      (command "_.dview"
    	   ""
    	   "tw"
    	   (getreal "\n Enter angle desired: ")
    	   ""
      )
      (command "_.regenall")
      (command "_.PSPACE")
      (princ)
    )
    I erased a couple of (setq) functions that were not used also.
    R.K. McSwain | CAD Panacea |

  3. #3
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    1

    Default Re: Error handling

    Here is a slightly different take, with the annoying alert boxes.

    Code:
    (defun c:rvp  (/ thisDwg ss vpObj twist)
     (vl-load-com)
     (setq thisDwg (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
     (prompt "\nSelect viewport to rotate view: ")
     (cond ((= (getvar "CVPort") 1)                                                 ; in a layout, w/o active viewport
            (setvar "ErrNo" 0)                                                      ; clear any current errors
            (while (and (not (setq ss (ssget ":S+." '((0 . "VIEWPORT")))))          ; get filtered single-pick select					
                        (/= 52 (getvar "ErrNo")))                                   ; or <Enter> 
             (alert "Selected object is not a viewport."))
            (cond ((and ss
                        (setq vpObj (vlax-EName->vla-Object (ssname ss 0)))
                        (= (vla-Get-DisplayLocked vpObj) :vlax-False))
                   (vla-Display vpObj :vlax-True)
                   (vla-Put-MSpace thisDwg :vlax-True)
                   (vla-Put-ActivePViewport thisDwg vpObj)
                   (cond ((setq twist (getangle "\nSpecify desired angle: "))
                          (vla-Put-TwistAngle vpObj twist)
                          (vla-Regen thisDwg acActiveViewport)
                          (vla-Put-MSpace thisDwg :vlax-False))))
                  (ss (alert "Selected viewport is locked.")))))
     (princ))
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  4. #4
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Talking Re: Error handling

    Thanks guys! either one seems to do what I want, but Robert's code seems a bit more elegant somehow. This was EXACTLY what I was looking for!

    Thank you!

    Don

  5. #5
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Lightbulb Re: Error handling

    Quote Originally Posted by dfuehrer View Post
    Thanks guys! either one seems to do what I want, but Robert's code seems a bit more elegant somehow. This was EXACTLY what I was looking for!

    Thank you!

    Don
    Sorry, I didn't know we had the liberty to rewrite the whole thing....
    Last edited by rkmcswain; 2007-09-21 at 06:53 PM. Reason: remove comment
    R.K. McSwain | CAD Panacea |

  6. #6
    100 Club dfuehrer's Avatar
    Join Date
    2004-11
    Posts
    130
    Login to Give a bone
    0

    Default Re: Error handling

    Hey, you guys are just fantastic!

  7. #7
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Error handling

    Thanks. I almost didn't post, since R.K. beat me to it, but I'm glad I offered it anyway. I enjoyed writing it.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  8. #8
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,803
    Login to Give a bone
    0

    Default Re: Error handling

    Quote Originally Posted by RobertB View Post
    Thanks. I almost didn't post, since R.K. beat me to it, but I'm glad I offered it anyway. I enjoyed writing it.
    Looking forward to your CP215-2 class at AU....
    R.K. McSwain | CAD Panacea |

  9. #9
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Error handling

    Quote Originally Posted by rkmcswain View Post
    Looking forward to your CP215-2 class at AU....
    No heckling! I look forward to seeing you. Be sure to talk to me before/after.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Similar Threads

  1. Error Handling
    By ticad02 in forum AutoLISP
    Replies: 16
    Last Post: 2009-12-21, 03:39 PM
  2. Error Handling
    By whattaz13 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-16, 01:03 PM
  3. Error Handling:
    By spencer.67965 in forum AutoLISP
    Replies: 4
    Last Post: 2004-09-15, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •