Jump to content

Recommended Posts

Posted

Just found out that 'my program' refuses transparent use of a variable saved.

This happens only when trying to use a saved variable when it's 'my program'.

The variable is unrecognized: Example..

 

Command: c2

 2.Point Circle (M) <'CT for.tan !pp>
 Specify 1st Point of 2P.Circle: !pp

Invalid 2D point.                         /\ <- keyed variable call

---------------------------------------

 

Here's the original reply..

 

Command: c
CIRCLE Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: 2p
Specify first end point of circle's diameter: !pp
"39.5838,25.6142,0"         <--------------- call /\ works

the /\ contents are actually without parenthesis but appear as shown.

           Command: (princ (getenv "pp"))
             39.5838,25.6142,0"39.5838,25.6142,0"

 

How can the code be changed to allow [ !pp ]?

 

Also tested this by making a base command (no extras) and the results are the same.

(defun c:c2 ( / *error* p oldsnap 1st) ;just 2 point.. //wasCIRCLE TANGENT RE: 19SEPT17
  (princ "\n 2.Point Circle (M) <'CT for.tan !pp> ")

  (setq pp "")
     (setq oldsnap (getvar 'osmode))
       (setvar 'osmode (boole 7 (getvar 'osmode) 512)) ;; added 'nea for 1st point
   
   (defun *error* ( msg )
      (setvar 'cmdecho 0) ;; 5.28.24
     (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
        (setvar 'osmode oldsnap)
     (if msg (prompt (strcat "\n" msg)))
      (if (eq pp "") (setq pp (getenv "pp"))) ;; restores stored <!pp> from "pp" if crash
     (setvar 'cmdecho 1)    
     (princ)
   )
  (initget 103)

(princ "\n Specify 1st Point of 2P.Circle: ") ;; (rtos (getvar 'circlerad))">" ;; <- not needed
    (setvar 'cmdecho 0)
    
   (while T ;;                                  'M' loop..
   (setq 1st (getpoint)) ;; get 1st edge of '2p.cir
       (command ".circle" "2p" 1st)
       (setvar 'cmdecho 1)
          (while (= 1 (logand 1 (getvar 'cmdactive)))
          (setvar 'osmode (boole 7 (getvar 'osmode) 128))         ;(setvar 'osmode 128) ;; added 'perp
            (command "\\")
           )
           (setq p2 (getvar 'lastpoint))
       (setq p (trans (cdr (assoc 10 (entget (entlast)))) (cdr (assoc 210 (entget (entlast)))) 1)) ;; 210 for 'z' direction
     (vl-cmdf "_copybase" '(0 0 0) "_L" "" "_erase"  "_L" "") ;; same as in: cut-... [ `` ]
    (setvar 'osmode oldsnap)	
    (setvar 'cmdecho 0)

        ; (princ
          ; (setq pp                               ;;  make/prints coords & paste usable
            ; (strcat
               ; (rtos (car p2) 2 4) ","        ;; 'p' -- vertex from pgm /\ getpoint,...
               ; (rtos (cadr p2) 2 4) ","
               ; (rtos (caddr p2) 2 4) 
              ; )
           ; )
          ; )
(princ "\n")
        (princ
          (setq pp                               ;;  make/prints coords & paste usable
            (strcat
               (rtos (car p) 2 4) ","        ;; 'p' -- vertex from pgm /\ getpoint,...
               (rtos (cadr p) 2 4) ","
               (rtos (caddr p) 2 4) 
              )
           )
          )
 
          (princ (strcat " | Ø: " (rtos (* (getvar 'circlerad) 2) 2 4)" | R: " (rtos (getvar 'circlerad) 2 4)))

       (entmakex (list (cons 0 "POINT") (cons 10 p))) ;; clean point 
       (entmakex (list (cons 0 "POINT") (cons 10 p2))) ;; clean point 

         (command "_pasteclip" '(0 0 0)) ;; restore circle [now 'last.obj]
         (princ "\n Specify 1st Point of 2P.Circle: ") ;;  (rtos (getvar 'circlerad))">"
        (setenv "pp" pp)
        (setvar 'osmode oldsnap)
       ) ;; end of while
    (setvar 'cmdecho 1)
   (*error* nil)
  (princ)
)

 

Same function but not from a home.made cmd.

 

Posted

So these were the results that I got from the command line

 

Command: C
CIRCLE
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: 2P
Specify first end point of circle's diameter: !pp
"50,60,0"            <--------------- CALLING THE VARIABLE WORKS LIKE YOURS

Specify second end point of circle's diameter:
Command: C2

 2.Point Circle (M) <'CT for.tan !pp>
 Specify 1st Point of 2P.Circle: !pp

Can't reenter LISP. 

Invalid point.           <--------------- CALLING THE VARIABLE DOESN'T WORKS LIKE YOURS
*Cancel*

 

Above the line that says invalid point you'll see it mentioned how you can't re-enter lisp. This means that if you wish to feed an autolisp variable into a custom autolisp coded command you can't feed it in like a regular command. I would hazard a guess the other issue is (if i'm reading it correctly) is that the variable is actually a string but the autolisp interpreter is expecting a list. I'm working on a few solutions in between work breaks (I am also in the Asia Pacific as well so its nearly bed time). But to proceed further if I may ask why are you writing the variable to the windows registry with the SETENV function?

Posted (edited)

@ScottMC

 

I don't see the purpose of why you are cutting the circle, printing the coordinates to the command line, then pasting the circle in the same loop?

- You don't need to initialize the pp variable as "" 

- There is not apparent reason to cut and paste the circle.

- You do not need to put a Global variable into the registry to recall it again in the same session, even if the program stops.

 

Try out the following code:

(defun c:C2 (/ cr el *error* fp oe os p p2)

   (defun *error* (msg)
      (if oe (setvar "cmdecho" oe))
      (if os (setvar "osmode"  os))
      (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
      (princ (strcat "\n" msg))
   )

   (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
   (setq oe (getvar "cmdecho")
         os (getvar "osmode")
   )
   (setvar "cmdecho" 0)
   (while (and
            (setvar 'osmode (boole 7 os 512))
            (setq fp (getpoint "\nSpecify 1st Point of 2P.Circle: "))
          )
      (command "._Circle" "_2P" "_non" fp)
      (setvar "osmode" OS)
      (princ "\nSecond Point: ")
      (while (= (logand (getvar "cmdactive") 1) 1)
		   (command pause)
	   )
      (setq el (entget (entlast))
            p  (trans (cdr (assoc 10 el)) (cdr (assoc 210 el)) 1)
            p2 (getvar "lastpoint")
            cr (getvar "circlerad")
      )
      (princ
         (strcat
            "\n Coordinates: "
            (setq C2:pp ;; Global Variable "C2:pp"
               (strcat 
                  (rtos (car   p) 2 4) "," 
                  (rtos (cadr  p) 2 4) ","
                  (rtos (caddr p) 2 4)    
               )
            )
            "\n Diameter: "
            (rtos (* cr 2) 2 4)
            "| Radius: "
            (rtos cr 2 4)
            "\n"
         )
      )
      (entmakex (list (cons 0 "POINT") (cons 10 p))) 
      (entmakex (list (cons 0 "POINT") (cons 10 p2)))
   )
   (setvar "cmdecho" oe)
   (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
   (princ)
)

 

Edited by pkenewell
Added Undo Start Mark and Better prompting to code.
  • Agree 1
Posted
3 hours ago, pkenewell said:

- You do not need to put a Global variable into the registry to recall it again in the same session, even if the program stops.

 

100% setenv is writing strings to your windows registry. not good if you are doing that for all variables.  might want to check to see what else you have been writing there.

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R##.#\ACAD-####:###\Profiles\<<Unnamed Profile>>\Variables

 

tho setenv will persist even after reboot. overkill for most variables need in lisp. like @pkenewell said you should be good with just global variables. that holds while the drawing is open but make them unique. if you need to hold a variable in the drawing itself. use ldata that will persist in the drawing. so you can close and reopen it.

 

  • Like 1

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