Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Generating parse function

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
407 Views, 4 Replies

Generating parse function

For the last few days, I've been working on labelling macro that I need for my workplace. The program is now complete, but I just wanted to clean the program so that I can have a better understanding next time I come back to add more.

Here are part of my code that is related to this topic. The section commented out shows my previous approach compared to new approach with "parse" function that I want to finish.

When I executed, as expected, the change in "var" wasn't transferred to "*pnlLim" since invocating "parse" function copies the value of  "*pnlLim" instead of the variable itself (or pointer).

 

Are there any way to pass the variable "by reference"? (in the sense of OOP)

I'm not really familiar with the memory of AutoCAD 😕

 

 

(defun parse (var msg / tmp)
  (setq tmp
	 (getint
	   (strcat "\n" msg " <"
		   (cond (var (itoa var)) ("1"))
		   ; offer previous value if present; otherwise 1
		   ">: "
	   ); strcat
	 ); getint
  ); setq
  (setq var
	 (cond (tmp) (var) (1))
  ); setq
)

(defun C:Label(/ term txt tmpsl tmppl tmpsc tmppc entName entType entInfo)
  ; initialize
  (parse *pnlLim "Enter number of panels per string")
;  (setq tmppl
;	 (getint
;	   (strcat "\nEnter number of panels per string <"
;		   (cond (*strLim (itoa *strLim)) ("1"))
;		   ; offer previous value if present; otherwise 1
;		   ">: "
;	   ); strcat
;	 ); getint
;  ); setq
;  (setq *pnlLim
;	 (cond (tmppl) (*pnlLim) (1))
;  ); setq
  (setq tmpsl
	 (getint
	   (strcat "\nEnter number of strings existing <"
		   (cond (*strLim (itoa *strLim)) ("1"))
		   ; offer previous value if present; otherwise 1
		   ">: "
	   ); strcat
	 ); getint
  ); setq
  (setq *strLim
	 (cond (tmpsl) (*strLim) (1))
  ); setq
  (while
    (> (setq tmppc
	      (getint
		(strcat "\nEnter current panel number <"
			(cond (*pnlCur (itoa *pnlCur)) ("1"))
			; offer previous value if present; otherwise 1
			">: "
		); strcat
	      ); getint
	    ); setq
       *pnlLim
    ); if current panel number is bigger than the limit
    (princ (strcat " must be less than " (itoa *pnlLim)))
  ); while
  (setq *pnlCur
	 (cond (tmppc) (*pnlCur) (1))
  ); setq
  (while
    (> (setq tmpsc
	      (getint
		(strcat "\nEnter current string number <"
			(cond (*strCur (itoa *strCur)) ("1"))
			; offer previous value if present; otherwise 1
			">: "
		); strcat
	      ); getint
	    ); setq
       *strLim
    ); if current string number is bigger than the limit
    (princ (strcat " must be less than " (itoa *strLim)))
  ); while
  (setq *strCur
	 (cond (tmpsc) (*strCur) (1))
  ); setq

 

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: Anonymous

I think [but haven't tested that] this will do what you're after:

....

  (parse (eval *pnlLim) "Enter number of panels per string")

....

Kent Cooper, AIA
Message 3 of 5
martti.halminen
in reply to: Anonymous



When I executed, as expected, the change in "var" wasn't transferred to "*pnlLim" since invocating "parse" function copies the value of  "*pnlLim" instead of the variable itself (or pointer).

 

Are there any way to pass the variable "by reference"? (in the sense of OOP)

I'm not really familiar with the memory of AutoCAD 😕

 

 

(defun parse (var msg / tmp)
  (setq tmp
	 (getint
	   (strcat "\n" msg " <"
		   (cond (var (itoa var)) ("1"))
		   ; offer previous value if present; otherwise 1
		   ">: "
	   ); strcat
	 ); getint
  ); setq
  (setq var
	 (cond (tmp) (var) (1))
  ); setq
)

Your choice of name is somewhat confusing, as usually parsing means something rather more involved:

http://en.wikipedia.org/wiki/Parsing

 

- Actually in Lisp pretty much all variables are passed by reference: everything is done by pointers behind the scene.

 

What you are attempting would probably be something like this:

(defun ask-int (varname msg / tmp varvalue)
  ;; Asks for an integer value to set into the variable, defaulting to the previous value
  (setq varvalue (vl-symbol-value varname))
  (setq tmp
        (getint
         (strcat "\n" msg " <"
                 (cond (varvalue (itoa varvalue))
                       ("1")) ; offer previous value if present; otherwise 1
                 ">: ")))
  (set varname
       (cond (tmp) (varvalue) (1))))

 Usage:  (ask-int '*pnlLim "Enter number of panels per string")

- note the variable name is quoted in the call

 

-- 

 

Message 4 of 5
Anonymous
in reply to: Anonymous

Neither of them worked. Solely getting the name of the variable using ' didn't work neither.
Message 5 of 5
Lee_Mac
in reply to: Anonymous

If I've understood correctly, the following should suffice:

 

(defun parse ( var msg )
    (set var (cond ((getint (strcat "\n" msg " <" (if (eval var) (itoa (eval var)) "1") ">: "))) ((eval var)) (1)))
)

 

Call with quoted symbol, e.g.:

 

(parse '*pnlLim "Enter number of panels per string")

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost