AutoLISP: Replace Selected Points with Block

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.

Here’s how:

  • 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

                           Michael Weaver
                          2175 George Road
                      Fairbanks, Alaska 99712
                    (907)488-3577 voice and fax
                           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.


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
    bname (getstring "\nName of block to insert: ")
    temp (/= "" bname)
    (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
      (alert (strcat "Block " bname " not found."))
     );				end progn
    );				end if block found?
   );				end progn check for block
   (setq scf (getreal "\nInsertion scale factor: "))
   (setq rotang (getangle "\nInsertion rotation angle: "))
    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
      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
     );				end setq (nested)
    );				end if?
   );				end setq (outer)
   (if (< 0 (sslength ss1))
     (alert "No points found.")
    );				end progn
   );				end if points found?
  );				end and
    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)))
     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
      '(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?
);				end c:pt2block

About AutoCAD Tips

This entry was posted in AutoLISP, AutoLISP: Blocks, AutoLISP: Creating, AutoLISP: Modify. Bookmark the permalink.

15 Responses to AutoLISP: Replace Selected Points with Block

  1. says:

    Thank you very very much. that is exactly what I need…Peter

  2. 204 says:

    i’m using Civil 3D 2011; I get
    Command: PT2BLOCK Unknown command “PT2BLOCK”. Press F1 for help.

  3. Acad_H says:

    Gets rid of points but does not insert block…

  4. how can text or mtext to block with text in to block???

  5. pnoraa says:

    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.

  6. ibrews says:

    Super helpful, even years later :D

  7. GKS says:

    The name of my block has spaces in it. How do I get around that without editing my block?

    • HasanCAD says:

      Replace this line
      (getstring “\nName of block to insert: “)
      (getstring T “\nName of block to insert: “)
      Be note that we added T

  8. Solomon Woldeyesus says:

    Thanks. It works

  9. Amazing!
    Still working on v2019!! :-)
    Great work!

  10. Pingback: AutoCAD: sustituir puntos por bloques – happservicios

  11. Dustin Harrington says:

    Amazing routine. Thank you so much!!

Leave a Reply to pnoraa Cancel reply


You are commenting using your account. Log Out /  Change )

Google photo


Twitter picture


Facebook photo


Connecting to %s