Jump to content

Recommended Posts

Posted

I've got a lisp file that has been used here a few years and I'm not sure who created it. This is a routine to create a cloud on a specific layer which is made by the routine. I.E. I am working on revision 3, so I enter 3 when prompted and it creates the PE_Rev3-Cloud layer if it does not exist and puts the cloud on it.

 

The two complaints I get about it is that it:

 

  • doesn't use the previous default if you just hit enter instead of re-entering the rev number (3 in this case) or the "R" for rectangle or "P" for pline.
  • doesn't take into account if it is being drawn in paper space or model space, so when it is going off a dimscale of 96 and you are in paperspace where the dimscale should idealy be 1 the cloud is huge.

I am not a programer, so anyone have any suggestions?

Thanks

 

(defun c:RC ()
(INITERR)
(setvar "cmdecho" 1)
;********************Obtain Revision number portion************************;
   (if     (null *GLOBALRN*)
       (setq *GLOBALRN* "1")
   )
   (initget 6)
   (SETQ RN (GETSTRING
           (STRCAT "Enter Revision number: <" *GLOBALRN* ">: ")
        )
   )
   (if (NOT RN)
       (setq RN *GLOBALRN*)
       (SETQ *GLOBALRN* RN)
   )
;***********************Revision cloud portion*****************************;
; create revision layer then cloud
(Setq LNC (strcat "PE_Rev" RN "-Cloud"))
; (if (null (tblsearch "layer" LNC))
(COMMAND "-LAYER" "M" LNC "C" "40" LNC "S" LNC "")
;--------------------------------------------------------------------------
; INITGET function sets options that GETKWORD function allows
;--------------------------------------------------------------------------
(initget 1 "Rectangle Polyline")

;--------------------------------------------------------------------------
; Get user's choice
;--------------------------------------------------------------------------
(setq choice (getkword "Polyline or Rectangle? <Rectangle>"))

;--------------------------------------------------------------------------
; Create the polyline or rectangle based on user input,
; CREATEPOLY and CREATERECT
;--------------------------------------------------------------------------
(if (= choice "Polyline") 
   (createpoly)
   (createrect)
)
(setq aleng (* (getvar "dimscale") 0.13))
(command "_revcloud" "_A" aleng aleng "" "" "_Last" "")
(while (> (getvar "CmdActive") 0) (command pause))
;
(RESET)
(princ)
)
(defun initerr () ;init error
(setq oldlayer (getvar "clayer")) ;save settings
(setq oldpick (getvar "pickbox"))
(setq temperr *error*) ;save *error*
(setq *error* trap) ;reassign *error*
(princ)
);defun
;;;*===========================================================
(defun trap (errmsg) ;define trap
(command nil nil nil)
(if (not (member errmsg '("console break" "Function Cancelled"))
)
(princ (strcat "\nError: " errmsg)) ;print message
)
; (command "undo" "b") ;undo back (THIS IS OPTIONAL BY RON)
(setvar "clayer" oldlayer) ;reset settings
(setvar "blipmode" 0)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" 0)
(setvar "pickbox" oldpick)
(princ "\nError Resetting Enviroment ") ;inform user
(terpri)
(setq *error* temperr) ;restore *error*
(princ)
) ;defun
;;;*===========================================================
(defun reset () ;define reset
(setq *error* temperr) ;restore *error*
(setvar "clayer" oldlayer) ;reset settings
(setvar "blipmode" 0)
(setvar "menuecho" 0)
(setvar "highlight" 1)
(setvar "osmode" 759)
(setvar "pickbox" oldpick)
(princ)
) ;defun
;--------------------------------------------------------------------------
; New function - allows the user to create a polyline
;--------------------------------------------------------------------------
(defun createpoly()
 (command "_.PLINE")
 (while (= (getvar "CMDNAMES") "PLINE")
   (command pause)
 )
 (princ (entlast))
)

;--------------------------------------------------------------------------
; New function - allows the user to create a rectangle
;--------------------------------------------------------------------------
(defun createrect()
 (setq p1 (getpoint "\nPick first corner of rectangle: \n"))
 (setq p2 (getcorner p1 "\nPick opposite corner: \n"))
 (command "_.rectangle" p1 p2)

 (princ (entlast))
)

Posted

Doesn't take into account if it is being drawn in paper space or model space, check what space your in and wether your in "model" or a layout tab start with (getvar "Ctab") then check which space _.pspace or _.mspace now wheres that Vl code.

Posted

(GETSTRING  (STRCAT "Enter [b][color=darkolivegreen]Revision number[/color][/b]: <" *GLOBALRN* ">: "))

 

Better to use GetINT instead of Getstring since you're asking for a number that way you can control it with your (initget 6)

control bits 2 & 4 is not applicable with getstring

 

 
(if (not rn)
           (setq rn 1))
     (initget 6) 
     (setq rn (cond ((getint
                             (strcat "\nRevision number <"
                                     (itoa rn)
                                     ">: ")))
                      (rn)))

 

and as for wether the where the polyline will be created, take bigals suggestion and test for "ctab" or "tilemode" value

Posted

To anwer your problem:

 

"doesn't use the previous default if you just hit enter instead of re-entering the rev number (3 in this case)"

Examine your code here:

 

(initget 6)
(SETQ RN (GETSTRING
       (STRCAT "Enter Revision number: <" *GLOBALRN* ">: ")
    )
)
(if (NOT RN)
   (setq RN *GLOBALRN*)
   (SETQ *GLOBALRN* RN)
)

 

Note that the getstring function will return an empty string ( "" ) should the user press Enter at the prompt, not nil.

 

You can test this at the command-line by typing:

(getstring "\nPrompt: ")

Then Enter at the prompt to see what is returned.

 

Since getstring returns an empty string, this is an non-nil value, hence:

 

(not RN)  ==>  nil

 

So the 'then' statement of the if function is not evaluated.

 

As a quick fix, change:

 

(not RN)

 

to:

 

(eq "" RN)

 

Or, use getint if you are prompting for an integer, as pBe suggests.

 

You may also be interested in my tutorial on the subject found here.

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...