Today’s featured routine lets you replace selected points in a drawing with a defined block in the drawing. This routine could be more rubust but it is still helpful. It does let you specify the scale of the block and rotation.
- Enter the name of the block that will replace the point objects with ,enter>
- Specify the insertion Scale Factor
- Specify the rotation angle
- Select Point objects that will be replaced by the block.
Note: this is not a global point replacement program by default. If you would like to replace all point objects, enter ALL at the command line.
Link to http://www.autocadtips.wordpress.com
;| PT2BLOCK.LSP Michael Weaver 2175 George Road Fairbanks, Alaska 99712 (907)488-3577 voice and fax Email:email@example.com Mike_Weaver_Alascad@compuserve.com Fri 02-23-1996 (c)1996 Alascad This routine will replace points (nodes) in the current drawing will insertions of a specified block. The insertion scale factor and the rotation angle for block are supplied by the operator. Example: command: PT2BLOCK Name of block to insert: MYBLOCK Insertion scale factor: 1 Insertion rotation angle: 0 Select points: <Select points to replace> Replace MYBLOCK with the name of your block. An enter at the Select points prompt will select all points in the drawing database (current space and excluding points found on layer DEFPOINTS). The blocks will be inserted on the same layer as the points. |; (defun c:pt2block(; replace points with blocks /; no arguments attreq; value to restore cmdecho; value to restore bname; block name to insert temp; temp variable ent; entity name elist; entity list scf; insertion scale factor rotang; insertion rotation angle ss1; selection set of points indx; index through selection set sslen; number of points selected inspt; insertion point ); end of local variable list (if (and (setq bname (getstring "\nName of block to insert: ") temp (/= "" bname) ) (progn (if (or (tblsearch "BLOCK" bname); the block exists in the drawing (findfile (strcat bname ".dwg")); the block can be pulled from disk ); end or T; continue (progn (alert (strcat "Block " bname " not found.")) nil ); end progn ); end if block found? ); end progn check for block (setq scf (getreal "\nInsertion scale factor: ")) (setq rotang (getangle "\nInsertion rotation angle: ")) (setq ss1 (ssget '((0 . "POINT"); get points (-4 . "<NOT"); not on (8 . "DEFPOINTS"); layer DEFPOINTS (-4 . "NOT>"); end not ); end the quoted filter list ); end ssget temp (if (and ss1 (< 0 (sslength ss1))); was anything selected T (setq ss1 (ssget "X" '((0 . "POINT"); get points (-4 . "<NOT"); not on (8 . "DEFPOINTS"); layer DEFPOINTS (-4 . "NOT>"); end not ); end the quoted filter list ); end ssget ); end setq (nested) ); end if? ); end setq (outer) (if (< 0 (sslength ss1)) T (progn (alert "No points found.") nil ); end progn ); end if points found? ); end and (progn (setq attreq (getvar "attreq"); value to restore cmdecho (getvar "cmdecho"); value to restore indx -1; a counter sslen (sslength ss1); number of points selected ) (setvar "attreq" 0) (setvar "cmdecho" 0) (while (> sslen (setq indx (1+ indx))) (setq ent (ssname ss1 indx); entity name elist (entget ent); entity list inspt (cdr (assoc 10 elist));location of the point inspt (trans inspt ent 1) ); end setq (entmake (list '(0 . "INSERT") (cons 2 bname) (assoc 8 elist) (cons 10 inspt) (cons 41 scf) (cons 42 scf) (cons 43 scf) (cons 50 (* rotang (/ pi 180))) (assoc 210 elist) ); end list ); end entmake (entdel ent); get rid of the point (princ "."); indicate progress ); end while (setvar "attreq" attreq) (princ (strcat "\t" (itoa sslen) " points replaced. ")) (command "_.redraw") (setvar "cmdecho" cmdecho) ); end progn ); end if valid input? (princ) ); end c:pt2block
Thank you very very much. that is exactly what I need…Peter
Glad that it worked for you
i’m using Civil 3D 2011; I get
Command: PT2BLOCK Unknown command “PT2BLOCK”. Press F1 for help.
Are you loading the lisp file?
Please see the following links to show how to save the code that is posted in the post as well as how to load the code.
Gets rid of points but does not insert block…
Check insertion point of block
how can text or mtext to block with text in to block???
Thanks, It works fine for normal blocks but not annotative blocks, Is it easy to edit it so that it works for them too?, I’m guessing that you just need to have an input for annotative scale.
Super helpful, even years later :D
The name of my block has spaces in it. How do I get around that without editing my block?
Replace this line
(getstring “\nName of block to insert: “)
(getstring T “\nName of block to insert: “)
Be note that we added T
Thanks. It works
Still working on v2019!! :-)
Pingback: AutoCAD: sustituir puntos por bloques – happservicios
Amazing routine. Thank you so much!!
I tried but it gives me a syntax error when I load the lsp file
I have the routine loaded correctly, but when I go to select my points, no points are selected. Is there a work around for this?
Could you please change write block name by select block existing?