Use user Input as Value?

Use user Input as Value?

pmercader
Advocate Advocate
2,049 Views
11 Replies
Message 1 of 12

Use user Input as Value?

pmercader
Advocate
Advocate

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 "" "");
0 Likes
Accepted solutions (3)
2,050 Views
11 Replies
Replies (11)
Message 2 of 12

SeeMSixty7
Advisor
Advisor

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

Message 3 of 12

pmercader
Advocate
Advocate

 

Thanks for the response however I am getting this error

Command: TST enter test string:test123
Error: bad argument type: listp "test123"
0 Likes
Message 4 of 12

dlanorh
Advisor
Advisor
Accepted solution

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

Message 5 of 12

dlanorh
Advisor
Advisor
Accepted solution

Sorry, amended above as I missed a list out.

I am not one of the robots you're looking for

Message 6 of 12

pmercader
Advocate
Advocate

Thanks you Very much. Works like magic!

0 Likes
Message 7 of 12

pmercader
Advocate
Advocate

One additional request, if the lisp couldnt find the string in the .dwg, how can I communicate that as "no block found"?

 

Thanks

0 Likes
Message 8 of 12

dlanorh
Advisor
Advisor
Which drawing? The one you are running the code in or the remote drawing you are stealing from?

I am not one of the robots you're looking for

0 Likes
Message 9 of 12

pmercader
Advocate
Advocate

If the lisp could not find the block in the remote drawing.

0 Likes
Message 10 of 12

dlanorh
Advisor
Advisor
Accepted solution

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

0 Likes
Message 11 of 12

pmercader
Advocate
Advocate

I hope I didnt take too much of your time.

 

Thanks again, works perfectly.

0 Likes
Message 12 of 12

dlanorh
Advisor
Advisor

@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