Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replace point with block/object

26 REPLIES 26
Reply
Message 1 of 27
Anonymous
26205 Views, 26 Replies

Replace point with block/object

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
26 REPLIES 26
Message 2 of 27
Anonymous
in reply to: Anonymous

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
Message 3 of 27
Anonymous
in reply to: Anonymous

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 "")
Message 4 of 27
mdhutchinson
in reply to: Anonymous

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]
Message 5 of 27
Anonymous
in reply to: Anonymous

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]
Message 6 of 27
Anonymous
in reply to: Anonymous

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 "")
Message 7 of 27
Anonymous
in reply to: Anonymous

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?
Message 8 of 27
Anonymous
in reply to: Anonymous


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?
Message 9 of 27
Anonymous
in reply to: Anonymous

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.
Message 10 of 27
Anonymous
in reply to: Anonymous


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? ....
Message 11 of 27
Anonymous
in reply to: Anonymous

That would make it perfect if the User was able to specify
the Layer and Block names differently every time, rather than having them
"fixed" in the routine.

Hate to bug, but could you write that into it for me, please?
Message 12 of 27
Anonymous
in reply to: Anonymous

That would make it perfect if the User was able to specify
the Layer and Block names differently every time, rather than having them
"fixed" in the routine.

Hate to bug, but could you write that into it for me, please?
Message 13 of 27
Anonymous
in reply to: Anonymous



In simplest terms, and also otherwise slightly
rearranged:

 

(defun C:MBIP (/ mbiplay mbipblk pointset ptdata
ptlay)

  (setq

    mbiplay (getstring "Layer of
Points to add Blocks to: ")

    mbipblk (getstring "Block to
Insert at Points on that Layer: ")

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

  ); end setq

  (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

    ); end setq

    (if (= ptlay mbiplay); set
Layer and Insert Block only if Point is on the
right Layer

    
 (command

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

       
"_.insert" mbipblk (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

 

It could also be made more sophisticated in other
ways than I mentioned before [e.g. to check whether the Layer name entered is in
the drawing, and/or even offer to create it if it isn't, or to save the Block
name as a default for use with another Layer].  But first see whether this
much works -- I haven't tested it.


--
Kent
Cooper

 

 

mapwoman wrote...
That would make it perfect if the User was able to
specify the Layer and Block names differently every time, rather than having
them "fixed" in the routine. Hate to bug, but could you write that into it for
me, please?
Message 14 of 27
Anonymous
in reply to: Anonymous

I copied and pasted your code, but I still get this ...........

Command: appload
MBIP.LSP successfully loaded.


Command: ; error: syntax error

Command:
Command: mbip
Unknown command "MBIP". Press F1 for help.
Message 15 of 27
Anonymous
in reply to: Anonymous


I didn't mention one thing that you probably won't
find in Help, but that is likely the source of the problem.  A Lisp file
like this needs to end with a hard return [Enter].  In the file, hit
ctrl-End -- the cursor would need to end up on a blank line *below*
the last line of code.  If the cursor ends up at the end of, but
*on*, the last line of code, hit Enter to give it that blank line at the
end, and Save and appload it again.

 

Also, I realize that the Layer names, in the
drawing database and in the User's entry, might not match as to upper-
and/or lower-case letters.  So they should both be forced to one or the
other for the comparison.  Change this, inside the (if)
function:

 

(= ptlay mbiplay)

 

to

 

(= (strcase ptlay) (strcase mbiplay))

 

to force them both to upper-case, so the comparison
will find them equivalent [when appropriate].



face=Arial size=2>--
Kent Cooper

 

 

mapwoman wrote...
I copied and pasted your code, but I still get this
........... Command: appload MBIP.LSP successfully loaded. Command: ; error:
syntax error Command: Command: mbip Unknown command "MBIP". Press F1 for
help.
Message 16 of 27
Anonymous
in reply to: Anonymous

Nope, unfortunatley ending it with a hard return change anything. I still get the same error message and unknown command.
I've attached the Lisp file I made (renamed it .doc to allow attachment here). I am stumped..............
Message 17 of 27
stevor
in reply to: Anonymous

1. You might as well learn how to debug it on the spot, as you have spent enough time to do so.

2. To get help on the debuging, attach the failed lisp file as a .lsp in text format, or post it using the Rich Text tab in the Reply - Message window.

3. To show your error clearly, coy the error statement string and paste it into the reply message, or, make a screen grab of the area and attach it as a small file.
S
Message 18 of 27
Anonymous
in reply to: Anonymous




(defun C:MBIP (/ mbiplay mbipblk pointset ptdata



ptlay)











(setq











mbiplay (getstring "Layer of



Points to add Blocks to: ")











mbipblk (getstring "Block to



Insert at Points on that Layer: ")











pointset (ssget "X" '((0 .



"POINT"))) ; find all points in drawing











); end setq











(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











); end setq











(if (= (strcase ptlay) (strcase mbiplay)); set



Layer and Insert Block only if Point is on the



right Layer















(command















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















"_.insert" mbipblk (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



Message 19 of 27
Anonymous
in reply to: Anonymous


I didn't notice any differences, but here's
the one that works for me here, using ADT2004.  If it doesn't work for
you, I don't have any more ideas.

 

[By the way, I agree with Stevor -- changing the
file type from .LSP to .TXT would be better than .DOC, which imposes various
formatting crud on it when opened.  But leaving it as a .LSP file and
Zipping it, as I have done here, also seems to work.]


face=Arial size=2>

size=2>


size=2>--
Kent Cooper

 

 

mapwoman wrote...
Nope, unfortunatley ending it with a hard return
change anything. I still get the same error message and unknown command. I've
attached the Lisp file I made (renamed it .doc to allow attachment here). I am
stumped..............
Message 20 of 27
Anonymous
in reply to: Anonymous

I replaced my lsp with the one you attached, and now it works beautifully.
Thank you all so much for your help!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report