Visual LISP, AutoLISP and General Customization

Reply
Contributor
rcpolaris
Posts: 17
Registered: ‎08-18-2006
Message 1 of 21 (745 Views)

Create LISP to Insert Block??

745 Views, 20 Replies
09-12-2006 10:37 AM
I am new to writing LISP routines, I have two Blocks made with attributes and I want to write a LISP routine that will allow me to Insert one of the two different blocks... I want it to ask me which block I am going to use and then let the attributes take over... any help would be great!!
*Moshe
Message 2 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-12-2006 10:52 AM in reply to: rcpolaris
Hi,

actually you do not need lisp to a complish such a task,
but in order to learn autolisp here is one example:

(setq blkName (getstring "\nBlock name: ")) ; get block name
(setq p0 (getpoint "\nBlock base point: ")) ; get insertion base point

(setvar "attdia" 1) ; force autocad to open attributes dialog box
(command "-insert" blkName p0 1 1 0)

be sure to restore attdia to 0 at the end

there are many way to do this.

Moshe

wrote in message news:5326460@discussion.autodesk.com...
I am new to writing LISP routines, I have two Blocks made with attributes
and I want to write a LISP routine that will allow me to Insert one of the
two different blocks... I want it to ask me which block I am going to use
and then let the attributes take over... any help would be great!!
*Expert Elite*
scot-65
Posts: 2,128
Registered: ‎12-11-2003
Message 3 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-12-2006 04:09 PM in reply to: rcpolaris
Yes, there are many ways to do this...

Set ATTDIA to 0 then:

command ".insert" BLK1 pt1 1 "" pause "attval1" "attval2" "attval3" ...

Note (Downside to this method):
If you edit the attributed block, the order of the attributes requested for filling out might change.
This includes moving the tag to another location within the block, or further formatting the tag (color, etc...).

Upside to this method:
No Idiot Mouse Box to pop up and fill out as this method already has the known information to add to the attributed block.

Good Luck!

Scot-65
Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Contributor
rcpolaris
Posts: 17
Registered: ‎08-18-2006
Message 4 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-13-2006 08:41 AM in reply to: rcpolaris
So if the names of my files blocks were "Quote 1" and "Quote 2" where would I place the names? Where does the code ask which one to open??
Sorry... But I almost know nothing about writing LISP routines!!
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 5 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-13-2006 11:02 AM in reply to: rcpolaris
Hope you know how to run lisp

[code]
;~~~~~~~~~~code starting here
; insert block & edit attribute ;

(defun build_dial ()

(setq fname
(strcat (getvar "DWGPREFIX") "blk-list-box.dcl"))
(setq fn (open fname "w"))
(write-line "setlist : dialog { label = \"SELECT BLOCK :\";" fn)
(write-line "spacer_1;" fn)
(write-line ": list_box {" fn)
(write-line (strcat "key = " "\"" "alist" "\"" ";") fn)
(write-line "alignment = centered; width = 10; height = 12;}" fn)
(write-line "spacer_1;" fn)
(write-line "ok_cancel; " fn)
(write-line "}" fn)
(close fn)
)

;___________________________________________;

(defun keep (v)
(setq bname (nth (atoi v) blk_lst)))

;___________________________________________;

(defun rundcl ()
(setq dcl_id (load_dialog fname))
(if (not (new_dialog "setlist" dcl_id))
(exit)
)
(start_list "alist")
(mapcar 'add_list blk_lst)
(end_list)

(action_tile "alist" "(keep $value)")
(action_tile "accept" "(done_dialog)(setq pick T)")
(action_tile "cancel" "(done_dialog)(setq pick nil)")
(start_dialog)
(unload_dialog dcl_id)
(done_dialog)
(vl-file-delete fname)
)
; 'Table' function
; Written By Michael Puckett.

(defun Table (s / d r)
(while (setq d (tblnext s (null d)))
(setq r (append r (list (cdr (assoc 2 d)))))
)
)
;___________________________________________;

(defun C:iba ( / blk_lst bname pause pick pt)
(setq osm (getvar "osmode"))
(setq atd (getvar "attdia"));1
(setvar "osmode" 0)
(setvar "attdia" 1)
(setvar "cmdecho" 0)
(setq blk_lst (Table "block"))
(build_dial)
(rundcl)
(if pick
(progn
(while
(setq pt (getpoint "\nSpecify insertion point (or Enter to stop) : \n"))
(command "-insert" bname pt 1 1 0)
(initdia)
(command "attedit" (entlast) pause))))
(setvar "osmode" osm)
(setvar "attdia" atd)
(setvar "cmdecho" 1)
(princ)
)
;___________________________________________;
(prompt "\n\t\t*** Type iba to insert block and edit attributes ***\n")
(princ)
; code ending here~~~~~~~~~~~~~~~~~~~
[/code]

Fatty

~'J'~
Contributor
rcpolaris
Posts: 17
Registered: ‎08-18-2006
Message 6 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-13-2006 12:23 PM in reply to: rcpolaris
ok, where do i specify the names of my blocks and the options I want to appear?
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 7 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-13-2006 12:52 PM in reply to: rcpolaris
Select block name from listbox and then hit OK button

Fatty

~'J'~
*Expert Elite*
scot-65
Posts: 2,128
Registered: ‎12-11-2003
Message 8 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-13-2006 02:50 PM in reply to: rcpolaris
[Sorry... But I almost know nothing about writing LISP routines!!]

If you are running commands inside LISP, test the command on the command line first. Mimic the action you entered to the LISP.
An enter is a double quote "". A stop for user input (pic point or text) to be entered is "pause", without the quotes.
In script the enter is a semi-colon ";" or a space. Stop for user input is a backslash "\".

Depending on what AutoCAD version you are using, you may need to turn on the command line to develop your programs, and see what your results are, if any, from running the programs.

Say you have an elbow fitting. You use the same attributed block to define the size of each end of this elbow. This can be done in script using the insert command followed by the attributed values for each possible combinations of sizes. No longer do you need to fill out the values each time you insert this block, it becomes automatic. Now is time to look into the pull-down, Screen Menu, and toolbar areas. I am not knowledgeable enough to know if design center can do this...

**Elbows
[Elbows: ]
[ ]
[.5/.5 ]^C^C-insert;ELBOW01;\;;\0.5;0.5;
[.5/.25 ]^C^C-insert;ELBOW01;\;;\0.5;0.25;
[.75/.5 ]^C^C-insert;ELBOW01;\;;\0.75;0.5;
[...]

Scot-65
Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Contributor
rcpolaris
Posts: 17
Registered: ‎08-18-2006
Message 9 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-14-2006 08:12 AM in reply to: rcpolaris
ok... So heres the deal, I have two different blocks... I want the user to type in "Quote" in the command line and have a lisp routine to start up... I want it to start out by asking SilverScreen or SilverTape... when the user types in SS or ST it will then insert the appropriate block... SSquoteform and Stquoteform are the names of the blocks... is there any way someone can make this for me? I think it would be really simple to make I just have no clue about codes!!
Contributor
rcpolaris
Posts: 17
Registered: ‎08-18-2006
Message 10 of 21 (745 Views)

Re: Create LISP to Insert Block??

09-18-2006 08:08 AM in reply to: rcpolaris
cant anybody help me do this ???
It would be much appreciated! ! !

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community