Author Topic: Passing variables to outside routine inside another routine =P  (Read 2742 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
Passing variables to outside routine inside another routine =P
« on: October 04, 2007, 06:09:02 PM »
Inside my lisp routine I call another lisp routine (c:MyRoutine) I already have.
But I am trying to pass variables to it for the purpose of this routine.
Such as when the outside routine calls to select objects for the selection set, I just want to pass the "All" statement and an enter " " to it to make it proceed.
What is the best format to run this way from inside the code below?

Code: [Select]
(DEFUN c:infofix()
    (setvar "cmdecho" 1); debug - turn cmd echo on
    (command "TILEMODE" 1)
    (command "Zoom" "Extents")
    (c:MyRoutine)
    (command "qsave")
    (command "close")
(princ)
)

FengK

  • Guest
Re: Passing variables to outside routine inside another routine =P
« Reply #1 on: October 04, 2007, 07:09:25 PM »
maybe use vla-sendcommand?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Passing variables to outside routine inside another routine =P
« Reply #2 on: October 04, 2007, 07:19:25 PM »
Can't be done with lisp.  You would have to write a script file if you want to supply command line arguments to a function that doesn't call for any.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Passing variables to outside routine inside another routine =P
« Reply #3 on: October 04, 2007, 08:09:04 PM »
Can't be done with lisp.  You would have to write a script file if you want to supply command line arguments to a function that doesn't call for any.
What about VL-BB-SET and VL-BB-REF functions.  I have not tried it yet but I read about them in the Lee Ambrosius's Article Accessing Values: Now or Later" in the Sept/Oct 207 issue of AUGI World.  Theses function (according to the article) ".... uses the Blackboard namespace to pass values to all open drawings in the current Autocad session."  I very inexperience with VL- functions so I don't know if this will work.  I have use for them in a few routines and I have had the time to play with them.  When billable projects quiet down, I will.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Passing variables to outside routine inside another routine =P
« Reply #4 on: October 04, 2007, 09:20:15 PM »
You can pass variable values but you can not respond to prompts. As Tim said yo need a script to do that.

You need to create a lisp that can run in auto mode as well as user mode.
Something like this:
Code: [Select]
(defun c:myroutine()
  (myroutine <var1> <var2> etc.)
  (princ)
)

(myroutine (v1 v2 v3 / lv1 lv2 ...)
  (if v1 skip prompt & use v1)
  .....
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Passing variables to outside routine inside another routine =P
« Reply #5 on: October 08, 2007, 04:07:34 PM »
Maybe it would be better then if I created a copy of the routine customized to select all objects then.
How do I set
(setq ss (ssget))

to select all instead of waiting for user input then?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Passing variables to outside routine inside another routine =P
« Reply #6 on: October 08, 2007, 04:27:15 PM »
Not sure what you are trying to do.
Maybe this will help.
Code: [Select]
(defun c:Myss1 (/ ss)
  (prompt "\nSelect anything.")
  (if (setq ss (ssget))
    (MyssRoutine ss)
  )
  (princ)
)

(defun c:Myss2 (/ ss)
  (prompt "\nSelect lines only.")
  (if (setq ss (ssget '((0 . "line"))))
    (MyssRoutine ss)
  )
  (princ)
)

(defun c:Myssnil (/ ss)
  (MyssRoutine ss)
  (princ)
)


(defun MyssRoutine (myss)
  (if (null myss)
    (progn
      (prompt "\nDefault Prompt, Select anything.")
      (setq ss (ssget))
    )
  )

  (if myss
    (progn
      ;;  do your stuff
      (print (strcat "ss contains " (itoa (sslength myss)) " items"))
      (print "***  My stuff is done.  ***")
    )
      (print "***  Selection Set was empty.  ***")
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Passing variables to outside routine inside another routine =P
« Reply #7 on: October 08, 2007, 04:37:50 PM »
Mainly I'm trying to get a routine run against a selection set of all items in a given drawing without prompting them to select the objects. So I'm trying to shortcut the routine itself to basically select all and continue without the user having to enter anything.
I'm essentially trying to build a single routine to run against client files used as backgrounds.
Once the file has been -exporttoautocad with a suffix on it, run a command against the new file to flatten everything without prompting the user.
Code: [Select]
(defun c:z-zero (/ a ss len e o10 l10 n10 f o11 l11 n11 o39 n39)
  ;(setup)
  (setq a 0)
  (princ
    "\nChanges entities' z-coordinate to 0 (2D from 3D)."
  )
  (setq ss (ssget))
  (setq len (sslength ss))
  (repeat len
    (setq e (entget (ssname ss a)))
    (setq o10 (assoc 10 e))
    (setq l10 (list (cadr (assoc 10 e)) (caddr (assoc 10 e)) 0.0))
    (setq n10 (cons 10 l10))
    (setq f (subst n10 o10 e))
    (entmod f)
    (setq a (1+ a))
  ) ;end repeat
  (setq a 0)
  (repeat len
    (setq e (entget (ssname ss a)))
    (setq o11 (assoc 11 e))
    (setq l11 (list (cadr (assoc 11 e)) (caddr (assoc 11 e)) 0.0))
    (setq n11 (cons 11 l11))
    (setq f (subst n11 o11 e))
    (entmod f)
    (setq a (1+ a))
  ) ;end repeat
  (setq a 0)
  (repeat len
    (setq e (entget (ssname ss a)))
    (setq o39 (assoc 39 e))
    (setq n39 (cons 39 0))
    (setq f (subst n39 o39 e))
    (entmod f)
    (setq a (1+ a))
  ) ;end repeat
  ;(end)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Passing variables to outside routine inside another routine =P
« Reply #8 on: October 08, 2007, 04:48:06 PM »
No user input required.

Code: [Select]
(setq ss (ssget "_all" ))  ; selects all non frozen in a drawing
(setq ss (ssget "_all" (list (cons 410 (getvar "ctab")))))  ; selects all non frozen objects in current space
(setq ss (ssget "_X" ))  ; selects all objects in a drawing
(setq ss (ssget "_X" (list (cons 410 (getvar "ctab")))))  ; selects all objects in current space
« Last Edit: October 08, 2007, 05:09:37 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Passing variables to outside routine inside another routine =P
« Reply #9 on: October 08, 2007, 04:51:44 PM »
Awsome! Thanks CAB!