Hello guys,
How can I use a string as a way to call for a block name?
What I want is call for command TST
TST asks for a String value and calls it tst1
Steal looks into .dwg and finds a block name with tst1 value
Inserts block with block name tst1 value.
Here is a lisp I have and I dont know how to make it work.
(defun c:TST (/ cde cmd oldlayer pt) (setq tst1 (getstring "enter test string:")); (Steal "../path/path1.dwg" '(("Blocks" tst1))); (setq pt (getpoint "\nSpecify insertion point: ")); (command "-insert" tst1 pt "" "");
Solved! Go to Solution.
Solved by dlanorh. Go to Solution.
Solved by dlanorh. Go to Solution.
Solved by dlanorh. Go to Solution.
Your routine is fine, but you are using a quoted expression which means evaluate this verbatim.
(defun c:TST (/ cde cmd oldlayer pt) (setq tst1 (getstring "enter test string:")); (Steal "../path/path1.dwg" (list (list "Blocks" tst1))); (setq pt (getpoint "\nSpecify insertion point: ")); (command "-insert" tst1 pt "" "");
Remove the quoted string and build the list using the list function I used two lists as your original argument was a list lists.
Good luck
Thanks for the response however I am getting this error
Command: TST enter test string:test123 Error: bad argument type: listp "test123"
Try it this way
(defun c:TST (/ tst1 cde cmd oldlayer pt) (setq tst1 (getstring "enter test string:")); (if (not (tblsearch "block" tst1)) (steal "../path/path1.dwg" (list (list "Blocks" (list tst1))))); (setq pt (getpoint "\nSpecify insertion point: ")); (command "-insert" tst1 pt); (while (= (logand (getvar 'cmdactive) 1) 1)(command "")) )
Note the last two lines for inserting a block with "command" and you are never sure how many accept defaults you need.
I am not one of the robots you're looking for
One additional request, if the lisp couldnt find the string in the .dwg, how can I communicate that as "no block found"?
Thanks
I am not one of the robots you're looking for
The steal lisp doesn't return anything so you would have to test again, and also ensure that the "insert" code doesn't run as this will error.
Try this. Brief testing, it works on my system.
(defun c:TST (/ tst1 s_path blk_b pt) (setq tst1 (getstring "enter test string:") s_path "../path/path1.dwg" blk_b T );end_setq (cond ( (not (tblsearch "block" tst1)) (steal s_path (list (list "Blocks" (list tst1)))) (cond ( (not (tblsearch "block" tst1)) (alert (strcat "Block : " tst1 " not found in " s_path)) (setq blk_b nil) ) );end_cond ) );end_cond (cond (blk_b (setq pt (getpoint "\nSpecify insertion point: ")); (command "-insert" tst1 pt); (while (= (logand (getvar 'cmdactive) 1) 1)(command "")) ) );end_cond );end_defun
I am not one of the robots you're looking for
@pmercader wrote:I hope I didnt take too much of your time.
Thanks again, works perfectly.
No problem, glad I could help. 👍
I am not one of the robots you're looking for
Can't find what you're looking for? Ask the community or share your knowledge.