LISP - CIRCLE

LISP - CIRCLE

Anonymous
Not applicable
6,481 Views
14 Replies
Message 1 of 15

LISP - CIRCLE

Anonymous
Not applicable

Hy,

 

im new in the forum and a rookie with lisp. Im trying to create a lisp, but it doesnt work. If somebody could help me, i will apreciate a lot.

 

I need a lisp with a conditional, were i write a key word and the lisp associate a number to the key. i was writing something like this:

 

 

(DEFUN c:HMMM (CNT DIAM)
(SETQ CNT (GETPOINT "\nselect circle center"))
;click the center of the circle

(INITGET "1Pul 2Pul")
(SETQ PUL (GETKWORD "\n1Pul, 2Pul:"))
;do not write the real diameter number

(cond
((= PUL "1Pul")
(SETQ DIAM 0.033401)
(command "circle" CNT "D" DIAM)
)
((= PUL "2Pul")
(SETQ DIAM 0.060325)
(command "circle" CNT "D" DIAM)
)
) ;End conditional

(PRINC)
)

 

 

0 Likes
Accepted solutions (1)
6,482 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

Welcome to these Forums!

 

The thing I noticed first is that the localized variables in parentheses after the command name need to be after a slash:

(DEFUN c:HMMM (/ CNT DIAM)

 

After that, assuming that fixes it, there are other things you could do to streamline it.  For instance, since you are doing exactly the same Circle command no matter which option the User chooses, that can be in there only once, as can the (setq) function for the 'DIAM' variable if you put the (cond) function inside it:


(SETQ CNT (GETPOINT "\nselect circle center"))
;click the center of the circle

(INITGET "1Pul 2Pul")
(SETQ PUL (GETKWORD "\n1Pul, 2Pul:"))
;do not write the real diameter number

(setq DIAM

  (cond
    ((= PUL "1Pul") 0.033401)
    ((= PUL "2Pul") 0.060325)

  ); cond

); setq
(command "circle" CNT "D" DIAM)
(PRINC)
)

 

BUT, I'm finding a curiosity related to numbers as initial characters in (initget) string arguments.  I was thinking that if you don't capitalize the P, the User can type just the 1 or 2, instead of needing to also type the P, to get the option they want.  But oddly, even if you leave it capitalized, I find I still need to type only the 1 or 2.  So you might consider not capitalizing the P in the (getkword) prompt, and people [who know how these things work] will know they don't have to type more than the 1 or 2.

Kent Cooper, AIA
0 Likes
Message 3 of 15

Anonymous
Not applicable

first, thanks a lot.

 

I was just writing the lisp as you are saying. The problem was that...im a rookie! i wrote the macro in 10 ways and i didnt notice that i forgot the "/"

 

About the names, they are an idea. My real names are:

 

(SETQ PUL (GETKWORD "\n1/2" 5/8" 1" 11/2":"))

 

or:

 

(SETQ PUL (GETKWORD "\n1/2 5/8 1 11/2:"))

 

can i put inside a text the double quotes and a slash?

0 Likes
Message 4 of 15

john.uhden
Mentor
Mentor

The problem is that you named your local variables as input arguments

 

Make that...
(DEFUN c:HMMM ( / CNT DIAM)
                ^
          Add the slash (and spaces)

John F. Uhden

0 Likes
Message 5 of 15

john.uhden
Mentor
Mentor
How about adding a DCL dialog with the various choices from which to select?

John F. Uhden

0 Likes
Message 6 of 15

Anonymous
Not applicable

John, how can i do to add a DCL?

0 Likes
Message 7 of 15

scot-65
Advisor
Advisor
...I was about to mention this very same thing as numbers/fractions
are difficult to make a selection from.

a) He is a rookie.
b) Some users might have DYNMODE on (and command line off),
and the available popup for the dynprompt will not accept the
inch (") symbol (thru R2014) if the choices are enclosed by brackets
"[ ]", in order to assist in the selection.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

The problem is that you named your local variables as input arguments

 

Make that...
(DEFUN c:HMMM ( / CNT DIAM)
                ^
          Add the slash (and spaces)

[Just to get overly picky about it....  You do need that space between the slash and the localized variable names, but in this case not the one before the slash.  If you define a function [without the C: to make it a command name], and if that function has both arguments before the slash and localized variables after it, then you need a space between the last argument and the slash, but when there are no arguments, you don't need it before the slash.]

Kent Cooper, AIA
0 Likes
Message 9 of 15

john.uhden
Mentor
Mentor
Picky,,, you!? Do you bake your turkey at 345°, 350°, or 355°?

Seriously, that is a very good point. The reason why the space is needed
between the last argument and the slash is that otherwise the slash would
be just part of the last argument's name.

(defun test (arg1 arg2/ a b)(print arg1)(print arg2)(print arg2/)(princ))

Command: (test "A" "X")
; error: too few arguments

Command: (test "A" "X" 1 2)
"A"
nil
"X"

John F. Uhden

0 Likes
Message 10 of 15

Kent1Cooper
Consultant
Consultant

@scot-65 wrote:
.... numbers/fractions are difficult to make a selection from.
....

Another way to go about that kind of thing is with stand-in letters for different numerical values.  Here's an excerpt from a routine of mine that offers choices for some standard insulation thicknesses [US sizes, Imperial units], setting a global *ibthick* variable [the "ib" part is for Insulation Batting].  It also allows entering a numerical value that isn't one of its built-in choices, if that's something you might need.

      (initget (if *ibthk* 6 7) "A B C D"); no Enter on first use, no 0, no negative
      (setq
        thktemp
          (getdist
            (strcat
              "\nThickness of insulation batting, or [A=3.5/B=5.5/C=9.5/D=12]"
              (if *ibthk* (strcat " <" (rtos *ibthk* 2 2) ">") ""); default only if not first use
              ": "
            ); end strcat
          ); end getdist & thktemp
        *ibthk*
          (cond
            ((= thktemp "A") 3.5)
            ((= thktemp "B") 5.5)
            ((= thktemp "C") 9.5)
            ((= thktemp "D") 12.0)
            ((numberp thktemp) thktemp); user entered number or picked distance
            (T *ibthk*); otherwise, user hit Enter - keep value
          ); end cond & *ibthk*
      ); end setq
Kent Cooper, AIA
Message 11 of 15

gustavobernardi
Advocate
Advocate

An additional tip, You can change (SETQ PUL (GETKWORD "\n1Pul, 2Pul:")) to this  (SETQ PUL (GETKWORD "\n1Pul / 2Pul:")) - This allow a Keyword  capture with directly click on the option in commandline. You can still put the option default (SETQ PUL (GETKWORD "\nOption [1Pul / 2Pul]<1Pul>:")) and get it if the PUL is nil.

0 Likes
Message 12 of 15

Anonymous
Not applicable

I was update the lisp with yours recommendations and tips in this way:

 

(DEFUN c:CPU ( / CNT DIAM INCH)

  (setq CNT (getpoint "\nselect circle center"));click the center of the circle
  
  	(initget 1 "2 2.5 3 3.5 4 6 8 10 12 14 16 18 20")
  	(setq INCH (getkword "\nSelect Diameter: [2 / 2.5 / 3 / 3.5 / 4 / 6 / 8 / 10 / 12 / 14 / 16 / 18 / 20]"))
  	;To do not write the real diameter number

  	(setq DIAM (cond ((= INCH "2") 0.060325)
			 ((= INCH "2.5") 0.073025)
			 ((= INCH "3") 0.0889)
			 ((= INCH "3.5") 0.1016)
			 ((= INCH "4") 0.1143)			 
			 ((= INCH "6") 0.1683)
			 ((= INCH "8") 0.2191)
			 ((= INCH "10") 0.2730)
			 ((= INCH "12") 0.3238)
			 ((= INCH "14") 0.3556)
			 ((= INCH "16") 0.4064)
			 ((= INCH "18") 0.4572)
			 ((= INCH "20") 0.5080)			 
		    );End conditional
  	) ;End setq

   		(command "circle" "_non" CNT "D" DIAM);draw the circle
		
  (PRIN1)
  )

 

and the lisp works as i was needing. After that i was thinking to put the circle in a layer different of the current (selecting an object) and then return in my original layer. So i wrote this new lisp:

 

(DEFUN c:CPU2 ( / CNT DIAM INCH P1)

  		(setq P1 (entsel "\nSelect an object to create the circle in the same layer: "))
  		(setq CNT (getpoint "\nselect circle center"));click the center of the circle
  
  		(initget 1 "2 2.5 3 3.5 4 6 8 10 12 14 16 18 20")
  		(setq INCH (getkword "\nSelect Diameter: [2 / 2.5 / 3 / 3.5 / 4 / 6 / 8 / 10 / 12 / 14 / 16 / 18 / 20]"))
  		;To do not write the real diameter number

  		(setq DIAM (cond ((= INCH "2") 0.060325)
			 ((= INCH "2.5") 0.073025)
			 ((= INCH "3") 0.0889)
			 ((= INCH "3.5") 0.1016)
			 ((= INCH "4") 0.1143)			 
			 ((= INCH "6") 0.1683)
			 ((= INCH "8") 0.2191)
			 ((= INCH "10") 0.2730)
			 ((= INCH "12") 0.3238)
			 ((= INCH "14") 0.3556)
			 ((= INCH "16") 0.4064)
			 ((= INCH "18") 0.4572)
			 ((= INCH "20") 0.5080)			 
		    	   );End conditional
  		) ;End setq DIAM

   		(command "laymcur" P1; to move in other layer with a select
  		(command "circle" "_non" CNT "D" DIAM);draw the circle
		(command "layerp"); return in the original layer
				 
  (PRINC)
  )

As usual i was going in the load application of autocad. The program is saying that the lisp is successfully loaded, but when im writing the lisp name in autocad later, the program didnt find the lisp.
If i write CPU, autocad find the first lisp, but if i write CPU2 it doesnt find the second lisp (it finds only the first one. I was trying to load it in another computer, but i was with the same problem. Is it because the new lisp is not correct or what?

0 Likes
Message 13 of 15

marko_ribar
Advisor
Advisor

http://www.cadtutor.net/forum/showthread.php?98546-Lisp-circle&p=672056#post672056

 

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 14 of 15

Kent1Cooper
Consultant
Consultant

Could it be the missing right parenthesis?

 

    (command "laymcur" P1); to move in other layer with a select

Kent Cooper, AIA
0 Likes
Message 15 of 15

Anonymous
Not applicable

Another Rookie mistake! 

0 Likes