Code Red > AutoLISP (Vanilla / Visual)
Block LISP - issue with attributes
like_citrus:
This code by others, makes a block at a selected point.
The issue is that if I have an attribute, it disappears in model space. But you can see it when you edit the block.
Is there a way to change so that the block is equivalent to that made by the BLOCK command. In this instance I can see the attributes.
Initially I also had issues with the BLOCK command. I tried settings such as ATTSYNC and ATTDISP and others, and now the attributes show up with the BLOCK command. But not with the LISP below.
--- Code: ---(defun c:CreateBlock (/ bkn eee i ndx nm ssst st)
(if (and (setq ssst (ssget)) (setq st (getpoint "\nPick Base Point: ")))
(progn (setq ndx 0)
(setq time (rtos (getvar "CDATE") 2 6)) ; Format YYYYMMDD.HHMMSS
(setq year (substr time 3 2)) ; Two digits instead of four
(setq month (substr time 5 2))
(setq day (substr time 7 2))
(setq hour (substr time 10 2)) ; Increment of 3 from day to account for "." character
(setq minutes (substr time 12 2))
(setq seconds (substr time 14 2))
(while (tblobjname "block" (setq nm (strcat "Block-" year month day hour minutes seconds))))
(entmake (list '(0 . "BLOCK")
'(100 . "AcDbEntity")
'(67 . 0)
'(8 . "0")
'(100 . "AcDbBlockReference")
(cons 2 nm)
(cons 10 st)
'(70 . 0)
)
)
(repeat (sslength ssst)
(entmake (cdr (entget (ssname ssst ndx))))
(entdel (ssname ssst ndx))
(setq ndx (+ 1 ndx))
)
(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
(entmake (list (cons 0 "INSERT")
(cons 2 nm)
(cons 6 (getvar "CELTYPE"))
(cons 8 (getvar "CLAYER"))
(cons 66 0)
(cons 10 st)
(cons 41 1)
(cons 42 1)
(cons 43 1)
(cons 50 0)
(cons 71 0)
(cons 44 0)
(cons 45 0)
)
)
)
)
(princ)
)
--- End code ---
BIGAL:
When you create a block its added to the block definitions then you would just insert it at the point required.
here is another example
--- Code: ---; bubble pt num
; BY ALAN H AUG 2014
(defun make_circle ()
(entmake (list (cons 0 "CIRCLE")
(cons 8 "0")
(cons 10 (list 0 0 0))
(cons 40 3.25) ; rad
(cons 210 (list 0 0 1))
(cons 62 256)
(cons 39 0)
(cons 6 "BYLAYER")
)
)
) ; DEFUN
(defun make_sq ()
(setq vertexList
(list
(list -3.25 -3.25 0.)
(list 3.25 -3.25 0.)
(list 3.25 3.25 0.)
(list -3.25 3.25 0.)
))
(entmake
(append
(list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
(cons 90 (length vertexList))
(cons 70 1) ; 1 closed : 0 open
(cons 8 "0")
(cons 38 0.0)
(cons 210 (list 0.0 0.0 1.0))
)
(mapcar '(lambda (pt) (cons 10 pt)) vertexList)
)
)
) ; defun
(defun Make_bubble ( )
(entmake (list (cons 0 "BLOCK")
(cons 2 Blkname)
(cons 70 2)
(cons 10 (list 0 0 0))
(CONS 8 "0")
))
(if (= resp "Circle")
(make_circle)
(make_sq)
)
(entmake (list (cons 0 "ATTDEF")
(cons 8 "0")
(cons 10 (list 0 0 0))
(cons 1 "1") ; default value
(cons 2 blkname) ; nblock name
(cons 3 "Ptnum") ; tag name
(cons 6 "BYLAYER")
(cons 7 "STANDARD") ;text style
(cons 8 "0") ; layer
(cons 11 (list 0.0 0.0 0.0)) ; text insert pt
(cons 39 0)
(cons 40 3.5) ; text height
(cons 41 1) ; X scale
(cons 50 0) ; Text rotation
(cons 51 0) ; Oblique angle
(cons 62 256) ; by layer color
(cons 70 0)
(cons 71 0) ;Text gen flag
(cons 72 1) ; Text Justify hor 1 center
(cons 73 0) ; field length
(cons 74 2) ; Text Justify ver 2 center
(cons 210 (list 0 0 1))
))
(entmake (list (cons 0 "ENDBLK")))
(princ)
)
(defun C:bub (/ ptnum ptnumb pt pt2 oldsnap chrnum sc curspace)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= ahbut nil)(setq ahbut 1))
(setq resp (ah:butts ahbut "v" '("Circle or square " "Circle" "Square")))
(if (= resp "Circle")
(setq blkname "SETOUT_POINT_NO")
(setq blkname "SETOUT_POINT_NOSQ")
)
(setq att (getvar 'attdia))
(setvar 'attdia 0)
(if (tblsearch "BLOCK" blkname)
(PRINC "FOUND") ; block exists
(Make_bubble)
)
(setq ah:ans (AH:getvalsm (list "Enter Pt details" "eg 1 a A " 5 4 "11" "Scale " 5 4 "100")))
(setq ptnum (nth 0 ah:ans))
(setq sc (atof (nth 1 ah:ans)))
(if (or (/= 1 (getvar 'cvport))(= "Model" (getvar 'ctab)))
(setq sc (/ sc 1000.0 ))
(setq sc 1.0)
)
(setq oldsnap (getvar "osmode"))
(setvar "textstyle" "standard")
(setq chrnum (ascii (substr ptnum 1 1))) ; 1st character is number
(if (< chrnum 58)
(setq ptnumb (atof ptnum)) ;convert back to a number
)
(while (setq pt (getpoint "\Pick end of line or Enter to exit"))
(setq pt2 (polar pt (/ pi 2.0) 3.25))
(setvar "osmode" 0)
(if (< chrnum 58)
(progn
(command "-insert"
blkname
pt
sc
""
0
(rtos ptnumb 2 0)
)
(setq ptnumb (+ ptnumb 1))
)
(progn
(command "-insert"
blkname
pt
sc
""
0
(chr chrnum)
)
(setq chrnum (+ chrnum 1))
)
)
(command "move" "L" "" pt pt2)
(setvar "osmode" 1)
)
(setvar "osmode" oldsnap)
(princ)
)
;;;;;;
; program starts here
(alert "Type Bub to repeat\n\nYou can do alpha's or numbers\n \nSquare or circles")
(C:BUB)
--- End code ---
Lee Mac:
After entmake'ing the INSERT entity, you'll also need to entmake the ATTRIB entities (the attribute references), followed by a terminating SEQEND entity - there are many examples of this technique to be found on the forums.
EDIT: here's a good example:
https://www.theswamp.org/index.php?topic=54428.0
like_citrus:
OK thank you for the comments.
I tried the ATTRIB and SEQEND entities and what happened is that the elements just disappeared. There was an error message about no "mxv" function so I added this at the top. Then the elements still disappeared, and I got the error message "Pick Base Point: ; error: bad DXF group: nil".
At this point I think I'll have to hold off on this one.
Lee Mac:
How are you calling gile's function?
Navigation
[0] Message Index
[#] Next page
Go to full version