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

Create LISP to Insert Block??

20 REPLIES 20
Reply
Message 1 of 21
rcpolaris
5151 Views, 20 Replies

Create LISP to Insert Block??

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!!
20 REPLIES 20
Message 2 of 21
Anonymous
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!!
Message 3 of 21
scot-65
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
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 4 of 21
rcpolaris
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!!
Message 5 of 21
Anonymous
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'~
Message 6 of 21
rcpolaris
in reply to: rcpolaris

ok, where do i specify the names of my blocks and the options I want to appear?
Message 7 of 21
Anonymous
in reply to: rcpolaris

Select block name from listbox and then hit OK button

Fatty

~'J'~
Message 8 of 21
scot-65
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
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 21
rcpolaris
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!!
Message 10 of 21
rcpolaris
in reply to: rcpolaris

cant anybody help me do this ???
It would be much appreciated! ! !
Message 11 of 21
Tom Smith
in reply to: rcpolaris

I wouldn't botherwith the routine to ask which block. If the user is going to have to type SS or ST to answer the question, it would be more direct to just provide two separate block insertion routines (or menu macros). To do it in lisp you don't need much more than:

(defun c:ss () (command "insert" "ssquoteform"))
(defun c:st () (command "insert" "stquoteform"))

Then the user can insert either block directly by typing SS or ST, without being asked a question first.
Message 12 of 21
rcpolaris
in reply to: rcpolaris

thanks!!
Message 13 of 21
V23
Explorer
in reply to: rcpolaris

Hello all,

I also know nothing about codes for writing LISP routines and would like to know or would like someone to help me out. This is what I need or would like some direction with:
-I created a block (DGS.dwg) which represents a graphic scale with attributes
-I would like to insert this block by typing "dgs"
-Lets say I saved the block on my C drive. file/location: "C:\graphic scale\DGS.dwg"
-What would the LISP be written like to insert this block into a drawing?

Please treat me like an computer illiterate jock.

Thanks!
V
Message 14 of 21
Anonymous
in reply to: rcpolaris


That's not hard to do, but I have to
wonder....  Are you using ONE block for a graphic scale at all drawing
scales?  I'm trying to figure out how that would work -- either it would be
Inserted in model space, in which case it would be way too big or way too small
for some scales, or it would be in paper space, in which case the increments in
it would represent really oddball distances in some scales.  But if you do
[as I do] a different one for each scale, so that the plotted size and the
increments and their identifiers are all appropriate, then you don't need the
complication of attributes.  A little more about how it/they are formatted
and used would be helpful, because it would affect the way such a routine would
be written.

--
Kent Cooper

 

 

V23 wrote...
Hello all, I also know nothing about codes for writing
LISP routines and would like to know or would like someone to help me out. This
is what I need or would like some direction with: -I created a block (DGS.dwg)
which represents a graphic scale with attributes -I would like to insert this
block by typing "dgs" -Lets say I saved the block on my C drive. file/location:
"C:\graphic scale\DGS.dwg" -What would the LISP be written like to insert this
block into a drawing? Please treat me like an computer illiterate jock. Thanks!
V
Message 15 of 21
V23
Explorer
in reply to: rcpolaris

Yeah, one block for all drawings at all scales. And yeah, it is inserted in Model Space and placed inside the boundary of the viewport. If the scale is inserted into a viewport which is at a 1:1 scale then the text in the scale would read accordingly as 1"=1'. And if the scale is inserted into a 1:10 veiwport then the text in the scale would be adjusted respectively to read 10 instead of 1.

When I insert the block now the slow way (by typing "insert" then searching for it in my C drive) it asks for the basics, insertion point and rotation and then since there is attributed text along with the block it asks me to fill in the appropriate fields by displaying the "Edit Attributes" window. Once I have the information entered such as the 'scale size' (ie 10), the '2x scale size' (ie 20) and the 'scale name' (1"=20') then I hit ok and the block is displayed in my drawing. The text is all justified on center, height 0.10, rotation 0d, width 1

Thanks for the input so far.
Message 16 of 21
Anonymous
in reply to: rcpolaris


[I am not the guy to help you if it involves
Attributes -- I never use them, so I don't have a sense of how they're prompted
for, whether you can preset values into them in Lisp, etc., etc.]
--
Kent
Cooper

 

 

V23 wrote...
Yeah, one block for all drawings at all scales. ....
there is attributed text along with the block it asks me to fill in the
appropriate fields by displaying the "Edit Attributes" window.
....
Message 17 of 21
V23
Explorer
in reply to: rcpolaris

what if it didnt involve attributes? what would be the LISP command to insert a block (DGS.dwg) from the location on my hard drive C:\Blocks\? could you show me that?
Message 18 of 21
Anonymous
in reply to: rcpolaris


Why not use AutoCAD'S INSERT command ? LISP is good
if you have already established all the parameters of the insertion, like the
insertion point, the insertion scale, the the rotation and even the values for
the attributes (if ATTREQ is set to 1) so you can feed them in your code. Is
this the case, could you explain what are you up to ?

 

HTH


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello
all, I also know nothing about codes for writing LISP routines and would like
to know or would like someone to help me out. This is what I need or would
like some direction with: -I created a block (DGS.dwg) which represents a
graphic scale with attributes -I would like to insert this block by typing
"dgs" -Lets say I saved the block on my C drive. file/location: "C:\graphic
scale\DGS.dwg" -What would the LISP be written like to insert this block into
a drawing? Please treat me like an computer illiterate jock. Thanks!
V
Message 19 of 21
Anonymous
in reply to: rcpolaris


Sorry, I didn't read the other messages, so don't
bother...


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Why not use AutoCAD'S INSERT command ? LISP is
good if you have already established all the parameters of the insertion, like
the insertion point, the insertion scale, the the rotation and even the values
for the attributes (if ATTREQ is set to 1) so you can feed them in your code.
Is this the case, could you explain what are you up to ?

 

HTH


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello
all, I also know nothing about codes for writing LISP routines and would
like to know or would like someone to help me out. This is what I need or
would like some direction with: -I created a block (DGS.dwg) which
represents a graphic scale with attributes -I would like to insert this
block by typing "dgs" -Lets say I saved the block on my C drive.
file/location: "C:\graphic scale\DGS.dwg" -What would the LISP be written
like to insert this block into a drawing? Please treat me like an computer
illiterate jock. Thanks! V
Message 20 of 21
Anonymous
in reply to: rcpolaris


If that location is in a Support File Search Path
in the Files tab in Options, then you don't need to spell it out in an insertion
routine.  And in the case of Insert, it's not necessary to specify the
filetype -- DWG is the only kind it will use.  [In fact, it ignores it if
you *do* spell it out, so it's wasted.  If you have a Block called DGS
already in the drawing, and you ask it to Insert a DGS.dwg that's *different*
from the existing definition, it still uses the existing Block definition, and
ignores the .dwg ending on what you asked for.]

 

If both scales would be 1 and the rotation would be
0, and you want the User to specify the insertion point, then:

 

(command "_.insert" "dgs" pause "" ""
"")

 

You can replace the pause with a variable name or a
known location, and the "" Enters with scale factors and rotation
angle.

 

If that location isn't somewhere that AutoCAD knows
to look, you need to spell it out, but you need to use either *forward* slashes
or *double* backslashes in place of the usual filepath single backslashes [they
have a different meaning in Lisp]:

 

(command "_.insert" "C:/Blocks/dgs"
yourinsertionpoint "" "" "")

or


(command "_.insert" "C:\\Blocks\\dgs"
yourinsertionpoint "" "" "")


size=2>--
Kent Cooper

 

 

V23 wrote...
what if it didnt involve attributes? what would be the
LISP command to insert a block (DGS.dwg) from the location on my hard drive
C:\Blocks\? could you show me that?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost