Author Topic: Stored variable ?  (Read 10183 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« on: February 20, 2004, 09:53:13 AM »
I have a question. I have a variable that hold the value of a command that you can type in at the command prompt. How can I initiate the command from the stored variable?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
Stored variable ?
« Reply #1 on: February 20, 2004, 09:57:30 AM »
I dont understand what your saying so im just going to start stabbin' in the dark.

See the value of a var from the command line with the " ! " symbol. Like this:
(setq a 1)
!a
1

Or store a "command" in a varaible.
(setq a (princ "\nHave a nice day!"))
(eval a)
Have a nice day!


any of those answer you?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Stored variable ?
« Reply #2 on: February 20, 2004, 09:57:46 AM »
I don't follow you, can you post some code to look at?
TheSwamp.org  (serving the CAD community since 2003)

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #3 on: February 20, 2004, 10:09:09 AM »
I have a custom command called DOWORK

For example...

Command: (Setq test "line")
"line"

Command: !test
"line"

now in my lisp the "test" is holding the value of DOWORK.

Can I start the command from the variable?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

daron

  • Guest
Stored variable ?
« Reply #4 on: February 20, 2004, 10:14:39 AM »
According to what you are showing, "test" is holding the value of "line". I don't see where DOWORK is being held anywhere. As far as the last question goes, I don't think so.

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
Stored variable ?
« Reply #5 on: February 20, 2004, 10:18:45 AM »
Like this?
Quote
Command: (defun dowork () (+ 5 2))
DOWORK

Command: (setq test '(dowork))
(DOWORK)

Command: (eval test)
7
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Stored variable ?
« Reply #6 on: February 20, 2004, 10:27:28 AM »
What about this:
Code: [Select]
(command test)
TheSwamp.org  (serving the CAD community since 2003)

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #7 on: February 20, 2004, 10:30:39 AM »
Code: [Select]

(defun C:samp5 ();( / REGION# DWGTYPE RNAMES DCL_ID) ;define function
  (setq REGION# "R3") ;*preset Region
  (setq DWGTYPE "FP") ;*preset FP
  (setq RNAMES '("R1" "R3" "R4" "R7" "R8" "R9" "R10" "R11"))
  (setq dcl_id (load_dialog "samp5.dcl")) ;load dialog
  (if (not (new_dialog "samp5" dcl_id))
    (exit) ;exit if no dialog
  )
  (start_list "selections") ;*start the list box
  (mapcar 'add_list RNAMES) ;*fill the list box
  (end_list) ;*end list
  (action_tile "rb1" "(setq DWGTYPE \"FP\")") ;store DWGTYPE type
  (action_tile "rb2" "(setq DWGTYPE \"SR\")") ;store DWGTYPE type
    (action_tile
    "cancel" ;if cancel button pressed
    "(done_dialog) (setq userclick nil)" ;close dialog, set flag
    );action_tile
  (action_tile
    "accept" ;if O.K. pressed
    (strcat ;string 'em together
      "(progn
       (setq REGION# (atof (get_tile \"selections\")))" ;*get list selection
      " (done_dialog)(setq userclick T))" ;close dialog, set flag
    );strcat
  );action tile
  (start_dialog) ;start dialog
  (unload_dialog dcl_id) ;unload
   (if userclick ;*check O.K. was selected
    (progn
      (setq REGION# (fix REGION#)) ;*convert to integer
      (setq REGION# (nth REGION# RNAMES)) ;*get the REGION#
    );progn
  );if userclick
  (DO_WORK5)
(princ)
)
(princ)

  (defun DO_WORK5()
     (if (= DWGTYPE "FP") (FP-DWG))
     (if (= DWGTYPE "SR") (SR-DWG)
     )
    (while (equal 8 (logand 8 (getvar "undoctl")))
         (command "_.undo" "_end")
    );while        
    (while (not (equal 8 (logand 8 (getvar "undoctl"))))
         (command "_.undo" "_begin")                
    );while
)

(defun FP-DWG ()
(C:INSERTDIM)
(setq RLAYER (strcat REGION# DWGTYPE))  <---This is where I'm combining 2 items to make up the command that is in another lisp. I want to be able to call the RLAYER so that it will initiate the command from the 2nd lisp file. In this case it is DOWORK
(command "limmax" "10000,10000")
(command ".regen")
(princ)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #8 on: February 20, 2004, 10:42:19 AM »
(command test)

The above comes up with

LISP command is not available.[/quote]
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

SMadsen

  • Guest
Stored variable ?
« Reply #9 on: February 20, 2004, 10:44:43 AM »
If RLAYER will hold the string "DOWORK" and your function is defined as (defun DOWORK ... then you can convert RLAYER to a symbol and run it like this:

(eval (list (read rlayer)))

If your function is defined as a command like (defun C:DOWORK ... and RLAYER is still holding the string "DOWORK" then you can merely put a "C:" in front and run it like this:

(eval (list (read (strcat "C:" rlayer))))

I don't see RLAYER holding anything but "R1FP" or such, though

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #10 on: February 20, 2004, 10:47:09 AM »
That's it you goy it. That what I was trying to accomplish.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
Stored variable ?
« Reply #11 on: February 20, 2004, 10:52:16 AM »
Ive written down some terms.

Expression: 10

Primitive procedure: +, -, * etc. (These are ofter refered to as "functions")

Combination: (+ 1 2)

Procedure:
Code: [Select]
(defun MyProcedure ()
  (princ "\nThis is my first procedure My name is ")
  (princ (+ (+ 1 2) 4))
 (princ)
)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Stored variable ?
« Reply #12 on: February 20, 2004, 10:53:51 AM »
Good :)

Quote from: dvarino
now in my lisp the "test" is holding the value of DOWORK.


Just to make it easier on yourself, please be more specific when showing something like the above. Most here would read the value of the variable test as a quoted symbol where it, in fact, was meant as a string.
No big deal - just an observation.

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
Stored variable ?
« Reply #13 on: February 20, 2004, 10:54:11 AM »
Oh, good, i see stig got it. Good job!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #14 on: February 20, 2004, 10:55:20 AM »
Thanks for the help and advice. Much appreciated.

Don
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023