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

Lisp to convert points to blocks..?

12 REPLIES 12
Reply
Message 1 of 13
DefCon5
8840 Views, 12 Replies

Lisp to convert points to blocks..?

Hello,
I need a lisp routine that will convert points into blocks using the same insertion point. Anyone know if this is possible?

I came across Geotools which sounds like it does it but I dont want to have to buy that whole package just to do one task.

Any help would be greatly appreciated!!
12 REPLIES 12
Message 2 of 13
rogerio_brazil
in reply to: DefCon5

whats block name?

Add sequential number?

:)

Rogerio
Message 3 of 13
Proxy
in reply to: DefCon5

Hi,

try this Lisp 'PKT_BLK'.

Credits to Holger Brischke.
Message 4 of 13
Anonymous
in reply to: DefCon5

This does exactly this. You must pass it the block name and the desired
scale, like so:
(pt2block "well" 100)

(defun pt2block (bname scale / ss i ent elist)
(if (and (tblobjname "BLOCK" bname)
(setq ss (ssget '((0 . "POINT"))))
)
(progn
(setq i -1)
(while (setq ent (ssname ss (setq i (1+ i))))
(setq elist (entget ent))
(entmake (list (cons 0 "INSERT")
(cons 2 bname)
(assoc 10 elist)
(assoc 8 elist)
(cons 41 scale)
(cons 42 scale)
(cons 43 scale)
(cons 50 0)
)
)
(entdel ent)
)
)
)
)


wrote in message news:5183699@discussion.autodesk.com...
Hello,
I need a lisp routine that will convert points into blocks using the same
insertion point. Anyone know if this is possible?

I came across Geotools which sounds like it does it but I dont want to have
to buy that whole package just to do one task.

Any help would be greatly appreciated!!
Message 5 of 13
rogerio_brazil
in reply to: DefCon5

Based in excellent Jeff Mishler idea (entmake block).

Jeff, all good?

The routine:


(defun c:pt2blk (/ #cmdecho blkname ss scale idx n entname edata)
(command "undo" "begin")
(setq #cmdecho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq blkname (getstring "\n Block name : "))
(if (= blkname "")(setq blkname "Block"))
(setq ss (ssget '((0 . "POINT"))))
(if ss
(progn
(setq scale (getreal "\n Block Scale <1>: "))
(if (= scale nil)(setq scale 1))
(setq idx 0)
(setq n (sslength ss))
(repeat n
(setq entname (ssname ss idx))
(setq edata (entget entname))
(entmake (list (cons 0 "INSERT")
(cons 2 blkname)
(assoc 10 edata)
(assoc 8 edata)
(cons 41 scale)
(cons 42 scale)
(cons 43 scale)
(cons 50 0)
)
)
(entdel entname)
(setq idx (1+ idx))
)
(princ "\n\n Done!")
)
(princ "\n Not point(s) selected(s)!")
)
(setvar "cmdecho" #cmdecho)
(command "undo" "end")
(princ))

:)


Rogerio
Message 6 of 13
Anonymous
in reply to: DefCon5

Yep, that looks pretty good to me 🙂

wrote in message news:5183972@discussion.autodesk.com...
Based in excellent Jeff Mishler idea (entmake block).

Jeff, all good?


:)


Rogerio
Message 7 of 13
Anonymous
in reply to: DefCon5

wrote in message news:5183699@discussion.autodesk.com...
Hello,
I need a lisp routine that will convert points into blocks using the same
insertion point. Anyone know if this is possible?

I came across Geotools which sounds like it does it but I dont want to have
to buy that whole package just to do one task.

Any help would be greatly appreciated!!



You might check this out. Wrote it a long time ago (and frankly forgot
about it). It will replace not only points, but circles, arcs, text, and
other blocks (entities with one significant point) with a specified block.
Gives options for replacing objects globally or only specified layer and
scaling, rotation, and exploding of block.
Message 8 of 13
orange47
in reply to: Anonymous

Phil, could you please modify your lisp program so that it works with plines? it doesn't matter which node of pline is used as block coordinate. thanks.
Message 9 of 13
Kent1Cooper
in reply to: orange47


@orange47 wrote:
Phil, could you please modify your lisp program so that it works with plines? it doesn't matter which node of pline is used as block coordinate. thanks.

I haven't worked with DCL, so I might not catch all the implications, but...

 

It looks to me as though it's already set up to do Polylines [despite not mentioning them in the prompt], though only of the "heavy" types.  To do lightweight ones instead, in the .LSP file, add polyline to the selection prompt, and replace this:

....(/= REP_TYPE "POLYLINE")....

with this:

....(/= REP_TYPE "LWPOLYLINE")....

or to do it with either, with this:

....(not (wcmatch REP_TYPE "*POLYLINE"))....

 

But it uses a more-complicated-than-necessary way to check the type; I would be inclined to replace this whole thing:

....

 (if (and (/= REP_TYPE "CIRCLE")(/= REP_TYPE "POLYLINE")(/= REP_TYPE "ARC")
    (/= REP_TYPE "POINT")(/= REP_TYPE "INSERT")(/= REP_TYPE "TEXT")
    (/= REP_TYPE "ELLIPSE"))
....

with this:

....

  (if (not (wcmatch REP_TYPE "CIRCLE,*POLYLINE,ARC,POINT,INSERT,*TEXT,ELLIPSE"))

....

[that will also alow Mtext, which the original routine doesn't.]

 

It's using the (assoc 10) value from the entity data for all entity types.  It would use the first vertex of a lightweight Polyline.  You could even add LINE to the options, and it would use the starting end, and there are some other less-often-used entity types you could add, too [e.g. IMAGE].  If you want to include Lines, Splines and Xlines in addition to Polylines, you could replace *POLYLINE above with just *LINE.

 

[I'm not sure of the purpose of the distinction in the (cond) function that's treating Blocks and Text differently from everything else, so it could be that those two options could be combined.]

Kent Cooper, AIA
Message 10 of 13
orange47
in reply to: Kent1Cooper

i've tried replacing polyline with lwpolyline but it aborts with error: quit/exit abort. (all 'wonderful' words!) interestingly it aborts like that with circle too 😞
Message 11 of 13
orange47
in reply to: orange47

its ok now, I didn't install file multins.dcl properly. but it asks for file with block? I defined the blocks in same drawing, not separate file.
Message 12 of 13
orange47
in reply to: orange47

everything ok, inserted the block as file, works perfectly, thanks to author.

this is truly fantastic lisp program.

Message 13 of 13
MGO-Norsyn
in reply to: orange47

This is a very good program, which I have used with great effect.

 

It could be even more fantastic if it could apply rotation of the text entity to the inserted block.

 

I tried to look at the code, but I do not know lisp... 😞

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

Post to forums  

Autodesk Design & Make Report

”Boost