thebiglebowski Posted August 7, 2019 Share Posted August 7, 2019 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 7, 2019 Share Posted August 7, 2019 : (command comvar) : _LINE Start of line:nil Start of line: Worked ? Quote Link to comment Share on other sites More sharing options...
thebiglebowski Posted August 7, 2019 Author Share Posted August 7, 2019 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. Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted April 27, 2021 Share Posted April 27, 2021 (edited) 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 April 27, 2021 by jonathann3891 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 29, 2021 Share Posted April 29, 2021 (c:pschformat_metric) (c:pschformat_imperial) much easier. Quote Link to comment Share on other sites More sharing options...
Jonathan Handojo Posted April 29, 2021 Share Posted April 29, 2021 (edited) 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 April 29, 2021 by Jonathan Handojo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.