Hi Guys,
Im using the following routine to insert blocks ( Spacial thanks o Tharwat and Kent Cooper ) :
(defun BlobkInsert (Nme pt x y z)
(entmakex (list (cons 0 "INSERT")
(cons 2 Nme)
(cons 10 pt)
(cons 41 x); Scale Factor
(cons 42 y); Scale Factor
(cons 43 z); Scale Factor
)
)
the routine is great but i want to insert blocks with attributes and I dont want to use (command "-insert" ... etc )
Is it possile to amend the above routine in order to insert block with attributes ?
Many thanks.
Hi,
Here complete routine without Insert command.
I hope that it can help you for your's job with ENTMAKE.
(defun inc_txt (Txt / Boucle Decalage Val_Txt) (setq Boucle 1 Val_txt "" ) (while (<= Boucle (strlen Txt)) (setq Ascii_Txt (vl-string-elt Txt (- (strlen Txt) Boucle))) (if (not Decalage) (setq Ascii_Txt (1+ Ascii_Txt)) ) (if (or (= Ascii_Txt 58) (= Ascii_Txt 91) (= Ascii_Txt 123)) (setq Ascii_Txt (cond ((= Ascii_Txt 58) 48) ((= Ascii_Txt 91) 65) ((= Ascii_Txt 123) 97) ) Decalage nil ) (setq Decalage T) ) (setq Val_Txt (strcat (chr Ascii_Txt) Val_Txt)) (setq Boucle (1+ Boucle)) ) (if (not Decalage) (setq Val_Txt (strcat (cond ((< Ascii_Txt 58) "0") ((< Ascii_Txt 91) "A") ((< Ascii_Txt 123) "a") ) Val_Txt ) ) ) Val_Txt ) (defun c:numerotation (/ all_path end_pos id_path pto x y z sv_zp n_ini nb nb_dec inc ) (if (not (tblsearch "LAYER" "numerotation")) (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "numerotation") (70 . 0) (62 . 7) (6 . "Continuous") (290 . 1) (370 . -3) ) ) ) (if (not (tblsearch "STYLE" "$numerotation")) (progn (setq all_path (getenv "ACAD") n 0 ) (while (setq end_pos (vl-string-position (ascii ";") all_path)) (setq id_path (substr all_path 1 end_pos)) (if (wcmatch (strcase id_path) "*FONTS*") (setq fonts_path (strcat id_path "\\")) ) (setq all_path (substr all_path (+ 2 end_pos))) ) (setq file_shx (getfiled "Selectionnez un fichier de police" fonts_path "shx" 8 ) ) (if (not file_shx) (setq file_shx "txt.shx") ) (entmake (append '((0 . "STYLE") (5 . "40") (100 . "AcDbSymbolTableRecord") (100 . "AcDbTextStyleTableRecord") (2 . "$numerotation") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 2.5) (4 . "") ) (list (cons 3 file_shx)) ) ) ) ) (setvar "textstyle" "$numerotation") (if (not (tblsearch "BLOCK" "$numero")) (progn (initget 7) (setq ht (getdist "\nEntrez la hauteur du texte: ")) (entmake '((0 . "BLOCK") (2 . "$numero") (70 . 2) (10 0.0 0.0 0.0)) ) (entmake (append '((0 . "ATTDEF") (67 . 0) (8 . "numerotation") (62 . 0) (10 0.0 0.0 0.0) (40 . 1.0) (1 . "0") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "$numerotation") (210 0.0 0.0 1.0) (3 . "Numéro ?: ") (2 . "NO") (70 . 0) ) (list (cons 40 ht)) ) ) (entmake '((0 . "ENDBLK"))) ) ) (setq sv_zp (getvar "dimzin")) (setvar "dimzin" 3) (if (not n_next) (setq n_ini (getstring "\nIncrementer en débutant à [chiffre/lettre/alphanumérique]: " ) n_next n_ini ) (progn (initget "Oui Non _Yes No") (if (eq (getkword "\nRéinitialiser l'incrémentation [Oui/Non] <Non>: ") "Yes" ) (setq n_ini (getstring "\nIncrementer en débutant à [chiffre/lettre/alphanumérique]: " ) n_next n_ini ) (setq n_ini n_next) ) ) ) (initget 8) (while (setq pto (getpoint "\nSpécifiez l'emplacement du numéro: ")) (setq pto (trans pto 1 0) x (car pto) y (cadr pto) z (caddr pto) ) (entmake (append '((0 . "INSERT") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbBlockReference") (50 . 0) (66 . 1) (2 . "$numero") (41 . 1.0) (42 . 1.0) (43 . 1.0) (70 . 0) (71 . 0) (44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0) ) (list (cons 10 pto)) ) ) (entmake (append '((0 . "ATTRIB") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "numerotation") (62 . 0) (100 . "AcDbText")) (list (cons 10 pto)) (list (cons 40 ht)) (list (cons 1 n_next)) (list (cons 50 (atan (/ (cadr (getvar "UCSXDIR")) (car (getvar "UCSXDIR"))) ) ) ) '((41 . 1.0) (51 . 0.0) (7 . "$numerotation") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttribute") (280 . 0) (2 . "NO") (70 . 0) (73 . 0) (74 . 0) (280 . 0)) ) ) (entmake '((0 . "SEQEND"))) (setq n_ini n_next) (cond ((eq (type (read n_ini)) 'INT) (setq n_next (itoa (1+ (atoi n_ini)))) ) ((eq (type (read n_ini)) 'REAL) (setq nb 0) (repeat (strlen n_ini) (if (eq (substr n_ini (setq nb (1+ nb)) 1) ".") (setq nb_dec (1- (strlen (substr n_ini nb)))) ) ) (setq inc 1.0) (repeat nb_dec (setq inc (/ inc 10))) (setq n_next (rtos (+ inc (atof n_ini)) 2 nb_dec)) ) ((eq (type n_ini) 'STR) (setq n_next (inc_txt n_ini)) ) ) (initget 8) ) (setvar "dimzin" sv_zp) (princ) )
@copoljan wrote:....i want to insert blocks with attributes and I dont want to use (command "-insert" ... etc )
....
You would need to (entmake) the Block Insertion, and the Attribute(s), and the SEQEND finisher. Something like this seems to be enough information.
(entmake
(list
'(0 . "INSERT")
'(66 . 1); has attribute(s)
(cons 2 "YourBlockName")
(cons 10 YourInsertionPoint)
'(41 . 1.0); X
'(42 . 1.0); Y
'(43 . 1.0); Z
; (cons 50 YourRotation); if not default 0
); list
)
(entmake
(list
'(0 . "ATTRIB")
(cons 10 YourBaseLineLeftEnd);;;;; get from Attribute data within Block definition
(cons 40 YourHeight)
(1 . "YourTextContent")
; (cons 50 YourRotation); if not default 0
(cons 72 YourValue); part of justification
(cons 11 YourInsertionPoint);;;;; get from Attribute data within Block definition
(cons 2 "YOURTAG")
'(70 . 0); I don't know what, but necessary
(cons 73 YourValue); part of justification
)
)
(entmake '((0 . "SEQEND")))
You may be able to leave out the XYZ of the Block if they're all the default of 1 -- I didn't try it that way.
The tricky part seems to be establishing the insertion point for the Attribute(s). I haven't worked it out yet, but I think if you want them at their default locations in relation to the Block, you'd need to get into the Block definition with (tblobjname), and step through the Attribute definitions within that with (entnext), and get their insertion points relative to the Block's insertion point, then calculate values to put into (enmake) for the Attributes, presumably with (mapcar '+) adding the Attribute definition's insertion point [relative to the Block] to the Block's insertion point.
@Kent1Cooper wrote:....
The tricky part seems to be establishing the insertion point for the Attribute(s). I haven't worked it out yet, but I think if you want them at their default locations in relation to the Block, you'd need to get into the Block definition with (tblobjname), and step through the Attribute definitions within that with (entnext), and get their insertion points relative to the Block's insertion point, then calculate values to put into (enmake) for the Attributes, presumably with (mapcar '+) adding the Attribute definition's insertion point [relative to the Block] to the Block's insertion point.
Not to mention accounting for a possible non-zero rotation angle, and/or non-1 scale factors, in figuring an insertion point to put into an Attribute.... That's why it's so much easier to use (command "_.insert" ...) instead in a case like this, because that handles all of those complications for you.
ATTRIBute points are based on the offset of the ATTDEF groups 10 & 11 from the INSBASE ( 10 ) of the BLOCK table header times the XYZ scale factors 41 42 & 43 of the INSERT definition and the INSERT rotation 50 translated to the INSERT 210 extrusion direction. -David