Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use user Input as Value?

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
pmercader
1638 Views, 11 Replies

Use user Input as Value?

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 "" "");
11 REPLIES 11
Message 2 of 12
SeeMSixty7
in reply to: pmercader

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
in reply to: SeeMSixty7

 

Thanks for the response however I am getting this error

Command: TST enter test string:test123
Error: bad argument type: listp "test123"
Message 4 of 12
dlanorh
in reply to: pmercader

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
in reply to: dlanorh

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
in reply to: dlanorh

Thanks you Very much. Works like magic!

Message 7 of 12
pmercader
in reply to: dlanorh

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

 

Thanks

Message 8 of 12
dlanorh
in reply to: pmercader

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

Message 9 of 12
pmercader
in reply to: dlanorh

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

Message 10 of 12
dlanorh
in reply to: pmercader

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

Message 11 of 12
pmercader
in reply to: dlanorh

I hope I didnt take too much of your time.

 

Thanks again, works perfectly.

Message 12 of 12
dlanorh
in reply to: pmercader


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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report