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

How to insert block at every vertice of a polyline in lisp?

65 REPLIES 65
Reply
Message 1 of 66
Anonymous
6680 Views, 65 Replies

How to insert block at every vertice of a polyline in lisp?

I need a quick lisp that will insert a block on every vertice of a polyline.
(possibly a 3d polyline) Any help would be GREATLY appreciated. Thx!
65 REPLIES 65
Message 2 of 66
Anonymous
in reply to: Anonymous

Please show us the code you've come up with so far...

--
R. Robert Bell, MCSE
http://www.acadx.com


"Jd" wrote in message
news:96638997F665ABA9C4EB59BDCC24929F@in.WebX.maYIadrTaRb...
| I need a quick lisp that will insert a block on every vertice of a
polyline.
| (possibly a 3d polyline) Any help would be GREATLY appreciated. Thx!
|
|
Message 3 of 66
Anonymous
in reply to: Anonymous

I just got chgpln.lsp sent to me. Seems to work great for my needs. It
doesn't do 3dpolylines, but this isn't an issue. At least, not right now!
;-) Thx

"R. Robert Bell" wrote in message
news:6193FE84A03E90515BDBB78D0768A1F1@in.WebX.maYIadrTaRb...
> Please show us the code you've come up with so far...
>
> --
> R. Robert Bell, MCSE
> http://www.acadx.com
>
>
> "Jd" wrote in message
> news:96638997F665ABA9C4EB59BDCC24929F@in.WebX.maYIadrTaRb...
> | I need a quick lisp that will insert a block on every vertice of a
> polyline.
> | (possibly a 3d polyline) Any help would be GREATLY appreciated. Thx!
> |
> |
>
>
Message 4 of 66
TherealJD
in reply to: Anonymous

Does anybody have the lisp mentioned here? looks like an old thread, but i need to do the same thing right now.
Message 5 of 66
Kent1Cooper
in reply to: Anonymous

In simplest terms, and assuming scale factors of 1 and rotation of 0 for all the Blocks, something like this should do it, since the vertices of Polylines are the integer parameter locations along them in (vlax-curve...) terms:

(setq
plobj (car (entsel "\nSelect Polyline: "))
inc 0
); end setq
(while (<= inc (vlax-curve-getEndParam plobj))
(command
"_.insert"
yourblockname
(vlax-curve-getPointAtParam plobj inc)
"" "" ""
); end command
(setq inc (1+ inc))
); end while

But there's a lot more you could [should?] do. That would put *two* Blocks at the same spot (the beginning and the end) of a *closed* Polyline, so if you might have those, you could test for that and adjust. You could have them aligned with the direction of the Polyline in the way that Measure and Divide can do with their Block options. You could have it filter the selection and ask again if the User picked the wrong kind of object. You would presumably prompt the User for the Block name, and possibly for the scale, or maybe calculate that from something like the drawing scale. Etc., etc., etc.

--
Kent Cooper


Jd wrote...
I need a quick lisp that will insert a block on every vertice of a polyline.
(possibly a 3d polyline)....
Kent Cooper, AIA
Message 6 of 66
TherealJD
in reply to: Anonymous

Thanks for the code!

I'm not sure how to test for the duplicate scenario you mentioned. But i'll start with this.
Message 7 of 66
Kent1Cooper
in reply to: Anonymous

You can check whether a Polyline [or Spline or Ellipse or even Circle] is closed, with (vlax-curve-isClosed), for example:

{code}
(setq
plobj (car (entsel "\nSelect Polyline: "))
inc (if (vlax-curve-isClosed plobj) 1 0); <-- changed line
); end setq
(while (<= inc (vlax-curve-getEndParam plobj))
(command
"_.insert"
yourblockname
(vlax-curve-getPointAtParam plobj inc)
"" "" ""
); end command
(setq inc (1+ inc))
); end while
{code}

If the Polyline is *open*, that will have it place the first Block at the start point [parameter 0]. But if it's *closed*, it will put the first one at the next vertex [parameter 1] -- then the one it puts at the end [in either case] won't duplicate one that's already there.

--
Kent Cooper


theraljd wrote...
....
I'm not sure how to test for the duplicate scenario you mentioned. But i'll start with this.
Kent Cooper, AIA
Message 8 of 66
jbear0000
in reply to: Anonymous

So how can I make this lisp work? I tried to copy everything from (setq to ); end while into notepad and I saved it as a lsp file, but when I load it, it asks for a polyline and then reloads appload. Is there something more that needs to be done? This is in Autocad 2007.
Message 9 of 66
Kent1Cooper
in reply to: Anonymous

You would need to wrap it in a command or function definition, such as in the attached [as a command]. I suspect that if you merely loaded the posted code without that "wrapping," it might be like pasting it into the Command: prompt line, and I find that gets thrown off by semi-colon-prefixed comments such as "; end command." It might possibly work that way if you remove those.

Adjust the content of the attached if you need to [see below], APPLOAD it, and type BlockVert [or something else if you also adjust that] to run the command.

Again, that's the barest routine, without error handling, Layer or Osnap control, object type filtering, etc.

If yourblockname would be something that is set into a variable value [e.g. by the earlier part of some longer routine], leave it un-quoted [but change the variable name to whatever you're using]. If you're talking about a specific always-the-same block name, put that in there in its place, *with* double-quotes around it.

If you want it to be executed from within something larger, remove the first and last lines and stick the rest in there. There are other possible variants [defining it as a function rather than as a command, without the C:, but that requires doing something different to use it] -- write back if you need adjustment.

--
Kent Cooper


jbear0000 wrote...
So how can I make this lisp work? ....
Kent Cooper, AIA
Message 10 of 66
jbear0000
in reply to: Anonymous

Thank you for your help and posting the file, but it still won't work right for me. It loads fine, I type BLOCKVERT, then select a polyline and get the message "Unknown command "BLOCKVERT". Press F1 for help." That message repeats a bunch of time until the command ends and then it simply says 10 or 5 or 13 or however many vertices there are on the polyline.
Message 11 of 66
Kent1Cooper
in reply to: Anonymous

It works for me. If you edited it, for example to specify a particular Block name, or to add a request to the User to supply one, might you have gotten something wrong in parentheses or quotes or something?

On the other hand, if you didn't edit it at all, and don't have any block name set into the yourblockname variable, I think that would explain the problem. The variable name would return nil, which would cancel the Insert command. The point would be fed in, but not really mean anything since it wouldn't be in a command any more. The first "" [Enter] would try to recall the BlockVert command, which would work if you did it manually. But (defun)'d command names can't be used in (command) functions in the way that regular AutoCAD command names can [e.g. (command "BlockVert" ...) won't know what you're talking about; you would have to do (C:BlockVert) instead]. I expect that is the source of the error message. Try doing (setq yourblockname "whatever") first, putting a real block name in place of the whatever, and see whether it works. That's what I did to test it.

--
Kent Cooper Edited by: Kent1Cooper on Aug 11, 2009 1:01 PM
[added second paragraph]
Kent Cooper, AIA
Message 12 of 66
flopo
in reply to: Anonymous

Hello,
I'm trying to insert a block at every vertex of a polyline. Do you know how to do this? Or you have a lisp for this? Thanks!
Message 13 of 66
flopo
in reply to: Anonymous

I tried to run this lisp, it doesn't work. Let's say my block name is "vertex", can you tell me what should i modify in your routine to work? Sorry for my english... Thanks! Edited by: flopo on Sep 2, 2009 12:19 PM
Message 14 of 66
flopo
in reply to: Anonymous

hello jd
Have you succeed runing this routine ? Can you help me please? Thanks!
Message 15 of 66
Kent1Cooper
in reply to: Anonymous

Replace the line that says:

yourblockname

with:

"vertex"

including the quotation marks.

--
Kent Cooper
Kent Cooper, AIA
Message 16 of 66
Anonymous
in reply to: Anonymous

Hi,

You could use the old school DXF codes to extract the vertices from the
polyline's (entget ...) returned stuff, or you can use the new ActiveX
enabled VisualLISP to extract the same vertices using the Coordinates
property. With the latter, you will get a flat list, so you will have to
group the values in order to create a list of valid points lists, something
like '((x1 y1)(x2 y2) x3 y3)(xn yn)) for a lwpolyline or '((x1 y1 z1)(x2 y2
z2) x3 y3 z3)(xn yn zn)) for the old format polyline.

Then you will use these points in a loop, calling the insert command and
using each vertex from the previous list as insertion point for your block.

As a matter of fact, I think I've already seen this one being discussed
here, so you could search the web or the forum and you might have some code
too.

HTH

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


a écrit dans le message de news: 6247359@discussion.autodesk.com...
Hello,
I'm trying to insert a block at every vertex of a polyline. Do you know how
to do this? Or you have a lisp for this? Thanks!
Message 17 of 66
flopo
in reply to: Anonymous

Thank you, Kent. It is working. Thank a lot!!!
Message 18 of 66
flopo
in reply to: Anonymous

Hi Kent,
In your lisp Blockvert, if the block that i want to insert has attributes, is it possible to be an attribute that count the number of vertices? For example, to be... V1, V2....V100? More than this, can be something like V1-0, V2-181.75 , V3-324.18 - i mean , to be an order number + the lenght of the polyline from the beginning to the vertice ? maybe I ask to much... Thanks!!
Message 19 of 66
Kent1Cooper
in reply to: Anonymous

I have approximately zero experience working with Attributes, but if the insertion just has an additional prompt asking for a text-string value to give to one, then yes, you should be able to answer that prompt with something like this:

(strcat
"V"
(itoa inc)
"-"
(rtos (vlax-curve-getDistAtParam plobj inc) 2 2)
); end strcat

That would label the starting vertex as V0, its parameter number. If you want that labeled V1, replace (itoa inc) with (itoa (1+ inc)).

--
Kent Cooper


flopo wrote...
....is it possible to be an attribute that count the number of vertices? For example, to be... V1, V2....V100? More than this, can be something like V1-0, V2-181.75 , V3-324.18 - i mean , to be an order number + the lenght of the polyline from the beginning to the vertice ?
Kent Cooper, AIA
Message 20 of 66
flopo
in reply to: Anonymous

Hi Kent,
I don't know what you mean by additional prompt to the insertion.


(strcat
"V"
(itoa inc)
"-"
(rtos (vlax-curve-getDistAtParam plobj inc) 2 2)
); end strcat


Should i ad this to the lisp Blockvert?
Thanks

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

Post to forums  

Autodesk Design & Make Report

”Boost