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
6759 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 21 of 66
Kent1Cooper
in reply to: Anonymous

Again, I don't work with attributes, but when you insert a block with attributes, doesn't it prompt you for values to put in them [non-constant ones, that is]? If so, you would put that (strcat) function in at the point where that prompt occurs. I'm guessing, but assuming there's only one attribute, and it asks for a value for it right after the block rotation angle, then something like:

{code}
(defun C:BlockVert (/ plobj inc)
(setq
plobj (car (entsel "\nSelect Polyline: "))
inc (if (vlax-curve-isClosed plobj) 1 0)
); end setq
(while (<= inc (vlax-curve-getEndParam plobj))
(command
"_.insert"
"vertex" ; block name
(vlax-curve-getPointAtParam plobj inc)
"" "" "" ; scale factors [1] and rotation [0]
(strcat ; for attribute prompt
"V"
(itoa inc) ; text of parameter number
"-"
(rtos (vlax-curve-getDistAtParam plobj inc) 2 2)
); end strcat
); end command
(setq inc (1+ inc))
); end while
); end defun
{code}

--
Kent Cooper


flopo wrote...
I don't know what you mean by additional prompt to the insertion.
....
Should i ad this to the lisp Blockvert?
Kent Cooper, AIA
Message 22 of 66
Anonymous
in reply to: Anonymous

wrote in message news:6248185@discussion.autodesk.com...
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!!

Give the attached a try.
It assumes that you have a block named "VERTEX" in the drawing containing an attribute with a tag value of "VERTEX-POSITION".
(both can be changed in the code if you want.)
You can also change the precision of the distance value at (rtos dist 2 2), change the last 2 to whatever precision you want.

Regards,

Mel
Message 23 of 66
gilsoto13
in reply to: Anonymous

It works... perfect... It is just necessary to make a block with those properties (called "vertex" and with an attribute value called "VERTEX-POSITION" then it will work as required...
Message 24 of 66
flopo
in reply to: Anonymous

Hi Mel,
Thanks! It works very good 🙂 It helps me a lot!
Can this lisp be modified to work the other way? I mean, to insert a block to a certain distance from the begining of the polyline- is it possible? Let's say, i want to insert a block at 321,18 m from the beginning of the polyline... (my english is bad, this is why i insist with explanations...)
Thanks!
Message 25 of 66
Anonymous
in reply to: Anonymous

"flopo" wrote in message news:6250025@discussion.autodesk.com...
> Hi Mel,
> Thanks! It works very good 🙂 It helps me a lot!
> Can this lisp be modified to work the other way? I mean, to insert a block
> to a certain distance from the begining of the polyline- is it possible?
> Let's say, i want to insert a block at 321,18 m from the beginning of the
> polyline... (my english is bad, this is why i insist with explanations...)
> Thanks!

Yes, that would be possible.
Do you want the same block with the same attribute?
I'm at home today but can look at it tomorrow if someone does not get to it
first.

Regards,

Mel
Message 26 of 66
flopo
in reply to: Anonymous

Yes, can be the same block, thanks!
Message 27 of 66
Anonymous
in reply to: Anonymous

wrote in message news:6250297@discussion.autodesk.com...
Yes, can be the same block, thanks!

Attached is the modified code.
I provided an opportunity to enter the text for blocks placed by distance, so you could, for example, make a block with text
"Distance-10.0" instead of "V1-10.0".

Regards,

Mel
Message 28 of 66
flopo
in reply to: Anonymous

Thanks mel, it's perfect!
Message 29 of 66
Anonymous
in reply to: Anonymous

wrote in message news:6251120@discussion.autodesk.com...
Thanks mel, it's perfect!

You're welcome, glad it worked out.

Regards,

Mel
Message 30 of 66
flopo
in reply to: Anonymous

Hi Mel,
Me again 🙂
Can this lisp, (vtxblk) do something else? To do the same thing like Measure command, but to add at every block inserted at a certain distance ( 1km, or 0.1 km or other distance) the value of the distance? I mean, to insert that Vertex Block along a polyline and the attribute of the block to display the distance from the 0 point of polyline - 0,1 km, 0,2 km...etc.
On Vins lisp, instead of inserting the distance where Vertex should be inserted, can be indicated a location (point) along the polyline, and inthat point to be inserted a block whose attribute to indicate the distance from the 0 point of polyline?
Thanks!
Message 31 of 66
Kent1Cooper
in reply to: Anonymous

Maybe something like this, if there is only the one attribute [untested]:

{code}
(defun C:MeaPLDist (/ plobj space inc)
(setq
plobj (car (entsel "\nSelect Polyline: "))
space (getdist "\nSpacing of Blocks: ")
inc 1
); end setq
(setvar 'attdia 0)
(while ; as long as next position is not beyond end
(<=
(setq pldist (* inc space))
(vlax-curve-getDistAtParam plobj (vlax-curve-getEndParam plobj))
); end <=
(command
"_.insert"
"blockname"
(vlax-curve-getPointAtDist plobj pldist)
"" "" "" ; scale factors [1] and rotation [0]
(rtos pldist); answer to attribute value prompt
); end command
(setq inc (1+ inc))
); end while
); end defun
{code}

Save and restore the ATTDIA System Variable value if you like, add error handling, etc., etc. Add mode and precision arguments to the (rtos) function if you like [as written, it will just use the current settings], and (strcat) a suffix onto it if needed. Depending on your drawing unit, you may also need to convert if you want it expressed in km.

It would operate like Measure in the sense that it would *not* put one at the beginning of the Polyline. It could be made to by starting the 'inc' value at 0 instead of 1.

--
Kent Cooper


flopo wrote...
....do the same thing like Measure command, but to add at every block inserted at a certain distance ( 1km, or 0.1 km or other distance) the value of the distance?
.... Edited by: Kent1Cooper on Oct 27, 2009 9:46 AM
[corrected a ) to a " as stevor pointed out elsewhere]
Kent Cooper, AIA
Message 32 of 66
stevor
in reply to: Anonymous

1. Kent's C: works for distance spaced Insertions, with a couple typos fixed:

{code}
(setq plobj (car (entsel "\n Select Polyline: "))
space (getdist "\n Spacing of Blocks:" ) ; add a ", rem a )
inc 1 )
{code}

Works also on Splines and Break parts of Splines.

Albeit, the first, or start, of the curve is not inserted at, just as the code defines it; and the last is not usually on the end, again as it is not defined to be, unless done so by coincidence. These would require more code, just as a Vertex location version.
S
Message 33 of 66
flopo
in reply to: Anonymous

Thank Kent,
The only problem is that my LISP knowledge is almost 0, so i can't use your advices. All that I know to do , is to use a working LISP.
Message 34 of 66
Kent1Cooper
in reply to: Anonymous

If you tried it when I first posted it, it would have had a problem which stevor pointed out. That's been corrected, and all you should need to do is change "blockname" to the name of the actual block you want to use, copy/paste it all into Notepad and save it as MeaPLDist.lsp [or whatever you want to call it], load it and use it. The "if you like" suggestions are optional -- it should work without incorporating any of them.

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

I did all this things, blocks are inserted but distance values are not inserted in block attribute (all blocks have the same attribute, as initial). Also, blocks are not inserted along the polyline, they are positioned somehow offseted from polyline. Am I doing something wrong?
Message 36 of 66
flopo
in reply to: Anonymous

I did all this things, blocks are inserted but distance values are not inserted in block attribute (all blocks have the same attribute, as initial). Also, blocks are not inserted along the polyline, they are positioned somehow offseted from polyline. Am I doing something wrong?
Message 37 of 66
Kent1Cooper
in reply to: Anonymous

It works for me. But it needs to have no running Object-snap modes in effect -- the attached takes care of that [but you'll still need to change the block name]. I don't really use attributes, so if there is anything about the attribute itself, or some related AutoCAD setting, that could be causing it to not have the distance value put in it [constant value? visibility setting? text size? attribute prompting setting?], I would not be the best person to explore that.

Also, are you currently in the World Coordinate System? If not, that would explain the positioning problem. If that's what's wrong, would you like the routine to compensate for that?

--
Kent Cooper


flopo wrote...
....blocks are inserted but distance values are not inserted in block attribute (all blocks have the same attribute, as initial). Also, blocks are not inserted along the polyline, they are positioned somehow offseted from polyline.....
Kent Cooper, AIA
Message 38 of 66
flopo
in reply to: Anonymous

Thanks Kent, it works perfect! 🙂
Is there any variable for distance? If I work with meter or Kilometer, can I change the unit ?
Message 39 of 66
Kent1Cooper
in reply to: Anonymous

It works with whatever the drawing unit settings are, both in asking for the spacing and setting a value to the Attribute. See the UNITS command, and/or the LUNITS, LUPREC, MEASUREMENT, and INSUNITS [and its related] System Variables. This line:

(rtos pldist)

is the one that you would need to adjust if you don't want just a number in current drawing units. For instance, if your drawing unit is a millimeter and you want the Attribute to be expressed in meters, or if your drawing unit is a meter and you want the Attribute to be expressed in kilometers, change that to

(rtos (/ pldist 1000))

Or if you want it to put an "m" on the end for meters,

(strcat (Rtos (/ pldist 1000)) "m")

or "km" instead, etc. It would be possible to ask the User what units they want the Attribute expressed in, if that's what you want to do.

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

Hi Kent,
I modified those variables, is perfect, thanks!
I want to ask you something more, if you can support me any more 🙂
Can you modify this Lisp to do something else? To insert a block that show the distance from the 0 point of polyline to a point chosen by me, along the polyline, that is not a vertice and has no other "quality". Thanks!

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

Post to forums  

Autodesk Design & Make Report

”Boost