Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
@GeryKnee hi,
if you mean to insert a block reference inside other block creating nested block?
the easy way i know is to use ActiveX method (vla-InsertBlock)
example:
say you have in drawing a block "test0" and you want to insert block "test1 inside.
(setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(setq BTR (vla-item blocks "test0"))
(vla-insertblock BTR insertionPnt "test1" 1 1 1 0)
BTR is AcDbBlockTableRecord which is block object.
since you cannot use (command) function to insert a block or block with attributes, using this method is much more complicated with attributes.
Moshe
If you have a block in the current dwg then maybe start with command method a bit simpler while you learn.
(command "-insert" fname "0,0" 1 1 0)
with attributes
(command "-insert" fname "0,0" 1 1 0 att1 att2 att3)
Note you must match how many attributes are required even if blank is used
(command "-insert" fname "0,0" 1 1 0 att1 att2 "" "")
Ok attreq and attdia control how attributes are handled you can set attreq to 0 and the insert command will not ask for any attributes. I suggest you read the help about the 2 variables attreq and attdia.
Ok last suggestion can make a block that does not exist using entmake. This is an example from another post at How-to entmake solid arrow. (theswamp.org)
(defun arr ()
(entmake '((0 . "BLOCK") (2 . "ARR")(70 . 0)(10 0 0 0)))
(entmake '((0 . "POLYLINE")(8 . "0")(66 . 1)(10 0 0 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 -12 0 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 0 0 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 -8 8 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 8 0 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 -8 -8 0)))
(entmake '((0 . "VERTEX")(8 . "0")(10 0 0 0)))
(entmake '((0 . "SEQEND")(8 . "0")))
(entmake '((0 . "ENDBLK"))))
(arr)
Here is a program pt num bubble that gives 2 choices a circle or square and makes the block if it does not exist.
Hello Sir,
I mean that i want to start creating a new block named "MyBlock"
After that i have to start drawing entieties (lines plines etc) in block space (nod model space)
That is "MyBlock
After that i sould use blockRef of MyBlock in ModelSpace
I don't know how to do this using lisp
Regards
Gery
@GeryKnee Good Morning,
Hi
Which is the lisp code to create block drawing in block Space ?
@GeryKnee wrote:Hello Sir,
I mean that i want to start creating a new block named "MyBlock"
After that i have to start drawing entieties (lines plines etc) in block space (nod model space)
That is "MyBlock
After that i sould use blockRef of MyBlock in ModelSpace
I don't know how to do this using lisp
Regards
Gery
Wow you know what my son would say about that? Dad you took this to far 😂🤣
Hello Sir,
I try to get information about lisp.
I see now, that there's no way to work with lisp the way in autocad works using "block editor".
In block editor you can use draw commands working with (the most of ) commands as you do that working on the current document's model space.
In Block Editor if you draw a circle with center (0 0 0) and rad 1.00 , the center is the block base point.
Anyway, sould help me a minimal lisp code that's
1. Creates a new block
Maybe ("-block" "BlockName" ....
2. Includes a Circle in block.
Thank you very much
Regards
Gery
the Block Edit (bedit) command is UI interface enabling user an isolate environment to create\edit block.
but this is not the case for the AutoLISP API
to create a block with lisp, use the (command) function to draw some objects than invoke the BLOCK command from the (command) function and gather all these object in
i think that you are at a state of understanding the power of (command) function - yes?!
Moshe
here is a simple command MBK for you to make a block, something you can catch up with. it starts with some constant
; const
(setq BNAME "GERYKNEE")
(setq CMDLST '("rectangle" "circle" "text"))
cmdlst is a list of 3 autocad commands to be execute in a row \ (foreach) loop.
than a while loop runs to collect the 3 new objects just drawn.
Note the use of (command-s) function as opposed to (command).
than a scan with (ssget) runs to find old blocks inserted and delete them
at last, define the new block + insert
Note the use of (setq ename (entlast)) if the command is run on existing dwg (has at least 1 entity), ename will hold that entity. if it runs on a new drawing (empty) the first entity drawn (in our case the rectangle) will be catched inside the loop otherwise this will run in an error 😀
the use of EXPERT sysvar is explained in code.
carefully run the command and at each step follow the prompts reply the exact data.
when you reach the BLOCK command it will pause for your insertion base point
when you reach the INSERT command it will pause for your insertion point.
enjoy
Moshe
; make block
(defun c:mbk (/ BNAME CMDLST ename cmdLst ss0 ss1)
(command "undo" "begin") ; begin undo
; const
(setq BNAME "GERYKNEE")
(setq CMDLST '("rectangle" "circle" "text"))
; if dwg is empty, ename will be nil, sse next
(setq ename (entlast)) ; set a pointer
(foreach cmd CMDLST
(command-s cmd)
; next is relevent for running command in empty dwg
(if (not ename)
(setq ename (entlast))
)
); foreach
; collect objects
(setq ss0 (ssadd))
(while ename
(ssadd ename ss0)
(setq ename (entnext ename))
); while
; scan database for my block
(if (setq ss1 (ssget "_x" (list '(0 . "insert") (cons '2 BNAME))))
(command "erase" ss1 "") ; if some old blocks found, delete them
)
(setvar "expert" 5) ; make sure the block won't complain redefine...
(command "block" "GERYKNEE" pause "si" ss0) ; define the new block
(setvar "expert" 0)
(command-s "insert" BNAME pause 1 1 0) ; bring the block
(command "undo" "end") ; end undo
(princ)
); c:mbk
Thank you very much sir, Maybe you feel bored with such simple things, but it's something new for me. Your help was essential for me. Regards, Gery.
Can you hint what the blocks are a image or dwg would be good, sounds like you want to answer some questions and draw objects, lines etc. Second question do you use these all the time ? If so why not save as a mini dwg and just insert when required.
I have like 118 general blocks in just one directory, 126 in another and so on, I must have maybe 500 general blocks, saved in catergories, CARS, TREES, Road Symbols and so on.