Visual LISP, AutoLISP and General Customization

Reply
*Chris Jr.
Message 1 of 21 (2,224 Views)

Replace point with block/object

2224 Views, 20 Replies
01-16-2008 01:50 PM
Hello folks!

I have thousands of points in a file. What I would like to do is to place
circles (or any object/block?) on each of these points. Elevation and
Z-coordinate do not matter.

Are there ideas on how this can be accomplished? I am struggling with
learning LISP, a little support may make it easier.

~jr
Valued Contributor
jsowinski
Posts: 63
Registered: ‎04-12-2007
Message 2 of 21 (2,224 Views)

Re: Replace point with block/object

01-16-2008 02:46 PM in reply to: *Chris Jr.
Are these points just standard "points". If they are consider changing the "PDMODE" AND "PDSIZE". Look in the help section under "POINT". You'll find a selection of images you can use to change the display.

Jim
Distinguished Contributor
thatcadguy
Posts: 856
Registered: ‎04-27-2007
Message 3 of 21 (2,224 Views)

Re: Replace point with block/object

01-16-2008 03:06 PM in reply to: *Chris Jr.
its a very simple process, but which do you want, circles or blocks?

(setq
ss (ssget "X" '((0 . "POINT")))
ct 0
)
(repeat (sslength ss)
(setq inspt (cdr (assoc 10 (entget (ssname ss ct)))))

do stuff here

(setq ct (1+ ct))
)

the variable inspt will be the insertion points from every point found in the drawing, cycled through one at a time.

if you wanted to put circles over top of them, then delete the points.... (lets say a radius .5 circle)...put this in place of "do stuff here"

(command "_circle" inspt 0.5)

and put this after everything

(command "_erase" ss "")
Valued Mentor
mdhutchinson
Posts: 2,283
Registered: ‎11-18-2003
Message 4 of 21 (2,224 Views)

Re: Replace point with block/object

01-16-2008 03:08 PM in reply to: *Chris Jr.
Load this into your AutoCAD and then type Rp at the command prompt
if you have the object you want to locate at all the points then select it when you are prompted.
I didn't check this much but it worked first time.

[code]
(defun c:Rp()
(setq ss (ssget "x" (list (cons 0 "point"))))
(setq inc 0)
(setq obj (car (entsel "\nSelect an object to locate at each point: ")))
(setq orgpnt (cdr (assoc '10 (entget obj))))
(while (setq node (ssname ss inc))
(setq topnt (cdr (assoc '10 (entget node))))
(command "copy" obj "" orgpnt topnt)
(setq inc (1+ inc))
)
(princ "\nDone")
)
[/code]
*Chris Jr.
Message 5 of 21 (2,224 Views)

Re: Replace point with block/object

01-16-2008 03:53 PM in reply to: *Chris Jr.
Worked beautifully, I am very greatful.

~jr


wrote in message news:5822573@discussion.autodesk.com...
Load this into your AutoCAD and then type Rp at the command prompt
if you have the object you want to locate at all the points then select it
when you are prompted.
I didn't check this much but it worked first time.

[code]
(defun c:Rp()
(setq ss (ssget "x" (list (cons 0 "point"))))
(setq inc 0)
(setq obj (car (entsel "\nSelect an object to locate at each point: ")))
(setq orgpnt (cdr (assoc '10 (entget obj))))
(while (setq node (ssname ss inc))
(setq topnt (cdr (assoc '10 (entget node))))
(command "copy" obj "" orgpnt topnt)
(setq inc (1+ inc))
)
(princ "\nDone")
)
[/code]
*Chris Jr.
Message 6 of 21 (2,224 Views)

Re: Replace point with block/object

01-16-2008 04:00 PM in reply to: *Chris Jr.
This also worked wonderfully, thank you very much sir.

~jr

wrote in message news:5822557@discussion.autodesk.com...
its a very simple process, but which do you want, circles or blocks?

(setq
ss (ssget "X" '((0 . "POINT")))
ct 0
)
(repeat (sslength ss)
(setq inspt (cdr (assoc 10 (entget (ssname ss ct)))))

do stuff here

(setq ct (1+ ct))
)

the variable inspt will be the insertion points from every point found in
the drawing, cycled through one at a time.

if you wanted to put circles over top of them, then delete the points....
(lets say a radius .5 circle)...put this in place of "do stuff here"

(command "_circle" inspt 0.5)

and put this after everything

(command "_erase" ss "")
Contributor
mapwoman
Posts: 13
Registered: ‎06-14-2005
Message 7 of 21 (2,224 Views)

Re: Replace point with block/object

11-14-2008 12:31 PM in reply to: *Chris Jr.
This works really good, but ...........
Is it possible to select which points it is to replace with a block? I have a bunch of points, on different layers. I would like to be able to select a certain block to replace only the points on a certain layer.
Is this do-able?
*Kent Cooper
Message 8 of 21 (2,224 Views)

Re: Replace point with block/object

11-14-2008 12:59 PM in reply to: *Chris Jr.

Look at my last two posts at the end of this recent
thread:

 


 

which I think could be modified to do just one
Layer like that, by simply removing this part:

 

((= ptlay "Layer2") "Block2")

 

It doesn't *replace* the points, but uses them as
Block insertion points and leaves them in the drawing.  But it could be
made to erase them, easily enough.


face=Arial size=2>

--
Kent
Cooper

 

 

mapwoman wrote...
This works really good, but ........... Is it
possible to select which points it is to replace with a block? I have a bunch of
points, on different layers. I would like to be able to select a certain block
to replace only the points on a certain layer. Is this do-able?
Contributor
mapwoman
Posts: 13
Registered: ‎06-14-2005
Message 9 of 21 (2,224 Views)

Re: Replace point with block/object

11-17-2008 06:16 AM in reply to: *Chris Jr.
Okay, so I made a lisp file containing the code from you previous post, shown at bottom. When I load the List (I named it MBIP.lsp) I get the following message;

MBIP.LSP successfully loaded.
Command: ; error: syntax error
Command:

What could be wrong? Also what do I type in to activate the code?


(setq pointset (ssget "X" '((0 . "POINT")))) ; find all points in drawing
(while (> (sslength pointset) 0) ; as long as there's something left in the set
(setq ptdata (entget (ssname pointset 0)); entity data for first point in the set ptlay (cdr (assoc 8 ptdata)); layer the point is on blkname
(cond
((= ptlay "Layer1") "Block1")
((= ptlay "Layer2") "Block2")
(T nil); no block name if not one of those Layers
); end cond and blkname
); end setq
(if blkname ; -- set Layer and Insert Block only if an appropriate Layer
(command "_.-layer""_set" ptlay """_.insert" blkname (cdr (assoc 10 ptdata)) "" "" ""
); end command
); end if (setq pointset (ssdel (ssname pointset 0) pointset)); remove that point from the set, and
); end while -- go back and do it again with the next point.
*Kent Cooper
Message 10 of 21 (2,224 Views)

Re: Replace point with block/object

11-17-2008 07:34 AM in reply to: *Chris Jr.

That code didn't have the "wrapping" required to
make it into an independent command.  Also, if you're only
talking about one Layer, the (cond) function can be simplified into an (if)
function.  Try this as the content of MBIP.LSP:

 

(defun C:MBIP (/ pointset ptdata ptlay
blkname)

  (setq pointset (ssget "X" '((0 . "POINT"))))
; find all points in drawing

  (while (> (sslength pointset) 0) ; as
long as there's something left in the set

    (setq

      ptdata (entget
(ssname pointset 0)); entity data for first point in the set

      ptlay (cdr (assoc 8
ptdata)); layer the point is on

      blkname
face=Arial size=2>(if
(= ptlay "Layer1") "Block1"
nil); no block name if not one right Layer

    ); end setq

    (if blkname ; -- set Layer and
Insert Block only if Point is on the right Layer

    
 (command

       
"_.-layer" "_set" ptlay ""

       
"_.insert" blkname (cdr (assoc 10 ptdata)) "" "" ""

      ); end
command

    ); end if

    (setq pointset (ssdel (ssname
pointset 0) pointset)); remove that point from the set, and

  ); end while -- go back and do it again
with the next point

); end defun

 

Substitute into that the Layer name you want in
place of "Layer1" [but also in double quotes like that], and the Block name
similarly in place of "Block1".  Make sure the Block definition is
either already in the drawing, or available on one of the Support File Search
Paths in the Files tab of the Options dialog box.

 

Once it's loaded, just type MBIP at the Command:
prompt to activate it.  You could also make a menu or toolbar or similar
item that you could just pick on.

 


If you would like the User to be able to specify
the Layer and Block names differently every time, rather than having them
"fixed" in the routine, that can also be done -- write back.


It could also use some of the usual
enhancements (turning off Osnap, saving the current Layer, etc., and restoring
those settings at the end; error handling if it involves User input; perhaps a
message to the User about how many Blocks it put in; also erasing of the Point
entities if you want that).

 

--
Kent Cooper

 

 

mapwoman wrote...
Okay, so I made a lisp file containing the code from
you previous post, shown at bottom. When I load the List (I named it MBIP.lsp) I
get the following message; MBIP.LSP successfully loaded. Command: ; error:
syntax error Command: What could be wrong? Also what do I type in to activate
the code? ....

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community