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

Block create

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
284 Views, 6 Replies

Block create

Is it any example to see how to create a block with attribute form lisp?
Thanks
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

I answear my self with something I found, but what I need now is instead of
CREATE an entity with ENTMAKE to add to the block an existing (already
drawn) entity ?

Thanks

(entmake '((0 . "block") (2 . "db") (70 . 2) (10 0.0 0.0 0.0) (8 .
"0") ) )
(entmake '((0 . "ATTDEF") (10 -0.21503 0.0563637 0.0)
(40 . 0.104167) (1 . "-") (50 . 0.0) (41 . 0.85) (51 . 0.0)
(7 . "ROMANS") (71 . 0) (72 . 1) (11 0.0 0.108447 0.0)
(210 0.0 0.0 1.0) (3 . "DETAIL NUMBER") (2 . "DETAIL")
(73 . 0) (74 . 2) (70 . 0) (8 . "0") ) )
(entmake '((0 . "LINE") (10 0.21875 0.0 0.0)
(11 -0.21875 0.0 0.0) (8 . "0" ) ) )
(entmake '((0 . "ENDBLK")))




"Gustavo_Guidi" escribió en el mensaje
news:5148510@discussion.autodesk.com...
Is it any example to see how to create a block with attribute form lisp?
Thanks
Message 3 of 7
Anonymous
in reply to: Anonymous

Gustavo,

The easy way to add an object to a block definition is use refedit. It translates the
new object to the object coordinate system (OCS) of the block based on whatever
instance of the block you choose to refedit.

To do it programmatically, without using refedit, you would have to replicate that
action. It ain't easy. It involves calculation of an inverse transformation matrix,
WCS to OCS. That matrix can be passed to the TransformBy method to transform the
object.

Joe Burke

"Gustavo_Guidi" wrote in message
news:5148504@discussion.autodesk.com...
I answear my self with something I found, but what I need now is instead of
CREATE an entity with ENTMAKE to add to the block an existing (already
drawn) entity ?

Thanks

(entmake '((0 . "block") (2 . "db") (70 . 2) (10 0.0 0.0 0.0) (8 .
"0") ) )
(entmake '((0 . "ATTDEF") (10 -0.21503 0.0563637 0.0)
(40 . 0.104167) (1 . "-") (50 . 0.0) (41 . 0.85) (51 . 0.0)
(7 . "ROMANS") (71 . 0) (72 . 1) (11 0.0 0.108447 0.0)
(210 0.0 0.0 1.0) (3 . "DETAIL NUMBER") (2 . "DETAIL")
(73 . 0) (74 . 2) (70 . 0) (8 . "0") ) )
(entmake '((0 . "LINE") (10 0.21875 0.0 0.0)
(11 -0.21875 0.0 0.0) (8 . "0" ) ) )
(entmake '((0 . "ENDBLK")))




"Gustavo_Guidi" escribió en el mensaje
news:5148510@discussion.autodesk.com...
Is it any example to see how to create a block with attribute form lisp?
Thanks
Message 4 of 7
Anonymous
in reply to: Anonymous

Here's part of something I started working a while ago and never got around to finishing. It creates a section symbol with two attributed tags. It checks to see if the block is already defined and if not creates it from a list of coordinates. It's not exactly the most refined but might be of some use to you.

(if (null (tblsearch "block" "Sec_blk")) (progn
(setq osmo (getvar "osmode"))
(setvar "osmode" 0)
(setq pt1 '(0 0))
(setq pt2 '(10.0 10.0))
(setq pt3 '(-10.0 10.0))
(setq pt4 '(0.0 10.0))
(setq pt5 '(0.0 11.0))
(setq pt6 '(0.0 7.0))
(command "pline" pt1 pt2 pt3 pt1 "")
(command "select" "p" (entlast) "")
(command "circle" pt4 "d" 14.14)
(command "select" "p" (entlast) "")
(command "attdef" "" "Section" "" "" "c" pt5 "2.5" "0")
(command "select" "p" (entlast) "")
(command "attdef" "" "Drawing_No" "" "" "c" pt6 "2.5" "0")
(command "select" "p" (entlast) "")
(command "chprop" "p" "" "c" "byblock" "la" "0" "")
(command "block" "Sec_blk" pt1 "p" "")
(setvar "osmode" osmo)
)
)
Message 5 of 7
Anonymous
in reply to: Anonymous

What's the VLA mode to make a block in order not to use COMMAND??
Message 6 of 7
Anonymous
in reply to: Anonymous

[code]
(setq doc (vla-get-activedocument (vlax-get-acad-object))
colBlk (vla-get-blocks doc)
insPt (vlax-3d-point (list 0.0 0.0 0.0))
blkDef (vla-add colBlk insPt "NewBlkName")
)
(vla-addline blkDef
(vlax-3d-point (list 0.0 0.0 0.0))
(vlax-3d-point (list 1.0 1.0 0.0))
)
(vla-addcircle blkDef
(vlax-3d-point (list 0.0 0.0 0.0))
0.5
)
[/code]

-KF
Message 7 of 7
Anonymous
in reply to: Anonymous

Try it

[code]
(defun C:AXB (/ acsp adoc block_coll block_def
bname bpt cnt hgt i obj_list
ob_list opt promp pt ss tag val
)

(vl-load-com)
(setq adoc (vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (and
(= (getvar "tilemode") 0)
(= (getvar "cvport") 1)
)
(setq acsp (vla-get-paperspace adoc))
(setq acsp (vla-get-modelspace adoc))
)
(setq block_coll (vla-get-blocks adoc))
(vla-endundomark
adoc
)
(vla-startundomark
adoc
)
(prompt "\nSelect entities to add in block\n")
(setq ss (ssget))
(setq i -1)
(repeat (sslength ss)
(setq obj_list
(cons
(vlax-ename->vla-object
(ssname ss (setq i (1+ i)))
)
obj_list
)
)
)
(setq ob_list (reverse obj_list))
(initget 1)
(setq bpt (getpoint "\nBase point Point >> ")
bname (getstring T "\nEnter block name : \n")
)
(setq block_def (vla-add block_coll (vlax-3D-Point bpt) bname))
(initget "Yes No")
(setq opt (getkword "\nAre there need add attribute? (Yes/No) \n"))
(if (not opt)
(setq opt "Yes")
)
(if (eq opt "Yes")
(progn
(setq hgt (getreal "\nEnter text height <0.05>: \n"))
(if (not hgt)
(setq hgt 0.05)
)
(setq cnt 1)
(while (setq
pt (getpoint
(strcat "\nPick "
(itoa cnt)
" attribute insertion point (Enter to stop) \n"
)
)
)
(setq promp (strcase (getstring (strcat "\nEnter "
(itoa cnt)
" attribute prompt : \n"
)
)
)
tag (strcase
(getstring
(strcat "\nEnter " (itoa cnt) " attribute tag : \n")
)
)
val (getstring
T
(strcat "\nEnter " (itoa cnt) " attribute value : \n")
)
pt (mapcar '- pt bpt)
)
(vlax-invoke
block_def 'Addattribute hgt
acAttributeModeVerify promp pt
tag val
)
(setq cnt (1+ cnt))
)
(vla-copyobjects
adoc
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbobject
(cons 0 (1- (length obj_list)))
)
obj_list
)
block_def
)
(vlax-release-object block_def)
)
)
(vla-endundomark
adoc
)
(princ)
)
(prompt "\n===========================\n")
(prompt "\n Type AXB to run ... ")
(prompt "\n===========================\n")
(princ)
[/code]

Fatty

~'J'~

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