Jump to content

Call Command based on a String Var


thebiglebowski

Recommended Posts

Is it possible to run a Command based on a value taken from a String Variable?

 

Something like this for example.

 

(setq comvar "_LINE")

 

and then later in the routine.

 

(Command (comvar))       to launch the line command?

 

I would like to launch the command directly from the String without using any corresponding "if" statement.

 

The purpose of this would be to run a command based off of the name of the block.

 

Ive been playing with this but I cannot get it to work.

Link to comment
Share on other sites

5 hours ago, BIGAL said:

: (command comvar)
: _LINE
Start of line:nil

Start of line:

 

Worked ?

 

Thanks,

I have no idea why I couldn't get this to work. Must have been tired.

Link to comment
Share on other sites

  • 1 year later...

I have a similar issue, but I cannot get it to work.

 

I'm setting the variable which is also the command name like this:

(setq Comvar (strcat "pschformat_" usel))

 

usel is set by selection using initget.

(initget 1 "Imperial Metric")
  (setq Usel (getkword (strcat "\nSpecify Units [Imperial/Metric]:")))
  (cond
    ((= Usel "Imperial")(setvar 'insunits 1))
    ((= Usel "Metric")(setvar 'insunits 4))
    );cond

 

!Comvar will either equal "pschformat_imperial" or "pschformat_metric", which is a command in my lisp

;; Format table column width for Imperial
(defun c:pschformat_imperial (/ tbl)
  (vl-load-com)
  (setq tbl (vlax-ename->vla-object(car(entsel)))) 
  (vla-setcolumnwidth tbl 0 0.805) ;Set Column 0 Width to 0.805
  (vla-setcolumnwidth tbl 1 0.736) ;Set Column 1 Width to 0.375
  (vla-setcolumnwidth tbl 2 0.735) ;Set Column 2 Width to 0.590
  (vla-setcolumnwidth tbl 3 1) ;Set Column 3 Width to 1
  (vla-setcolumnwidth tbl 4 1) ;Set Column 4 Width to 1
  (vla-setcolumnwidth tbl 5 1) ;Set Column 5 Width to 1
  (vla-setcolumnwidth tbl 6 0.805) ;Set Column 6 Width to 0.805
  (vla-setrowheight tbl 0 0.3)
    (StripMtext (ssget "x") "*^L") ;Run StripMText ~ Remove All Formatting
  )

;; Format table column width for metric
(defun c:pschformat_metric (/ tbl)
  (vl-load-com)
  (setq tbl (vlax-ename->vla-object(car(entsel))))
  (vla-setcolumnwidth tbl 0 20.4470) ;Set Column 0 Width to 0.805
  (vla-setcolumnwidth tbl 1 18.6944) ;Set Column 1 Width to 0.375
  (vla-setcolumnwidth tbl 2 18.6690) ;Set Column 2 Width to 0.590
  (vla-setcolumnwidth tbl 3 25.4000) ;Set Column 3 Width to 1
  (vla-setcolumnwidth tbl 4 25.4000) ;Set Column 4 Width to 1
  (vla-setcolumnwidth tbl 5 25.4000) ;Set Column 5 Width to 1
  (vla-setcolumnwidth tbl 6 20.4470) ;Set Column 6 Width to 0.805
  (StripMtext (ssget "x") "*^L") ;Run StripMText ~ Remove All Formatting
  )

 

When I try 
: (Command Comvar)

 

I get the following error:

pschformat_Imperial Unknown command "PSCHFORMAT_IMPERIAL".

Edited by jonathann3891
Link to comment
Share on other sites

You are attempting to launch an AutoLISP function, not an AutoCAD command. Therefore you end up with that error. Having a function with a prefix "c:" only makes it so that the function can be called from the command line. To launch it, you'll need to go for a different approach.

 

((eval (read comvar)))

 

Edited by Jonathan Handojo
Link to comment
Share on other sites

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