Inserting block on every polyline vertex and write in block attribute distance to polyline's start

Inserting block on every polyline vertex and write in block attribute distance to polyline's start

Angelswing91
Contributor Contributor
1,899 Views
16 Replies
Message 1 of 17

Inserting block on every polyline vertex and write in block attribute distance to polyline's start

Angelswing91
Contributor
Contributor

I have a polyline (axis) line. I need to insert a block on each vertex which will have (in attributes) a distance value to start point.

 

Is it even possible? Have you ever had such a question and managed to solve it? Can you help/share you experience or have a suggestion how I can achieve this result?

0 Likes
1,900 Views
16 Replies
Replies (16)
Message 2 of 17

Kent1Cooper
Consultant
Consultant

That is certainly possible.  I assume the Block's insertion point is what is at the vertex.

It looks like the completed Attribute in your image is a vertex number, not a distance.  Would you be looking for the distance along the Polyline at that vertex in addition to that "KOORDINATE" value, presumably in the "KM" Attribute?

Kent Cooper, AIA
0 Likes
Message 3 of 17

Angelswing91
Contributor
Contributor

My image is like example how it should look.

In my image the distance completed in KM attribute field. 

0 Likes
Message 4 of 17

Kent1Cooper
Consultant
Consultant

If KM stands for Kilometers, what is your drawing unit?  AutoLisp can easily find the distance along the Polyline to a given vertex, but if you're dealing with Kilometers but your drawing unit is a Meter, that should be divided by 1000 to put in the Attribute.  You could have the value shown to as many decimal places as you like -- is there a standard?

Kent Cooper, AIA
0 Likes
Message 5 of 17

Angelswing91
Contributor
Contributor

Yes, KM stands for kilometers, and yes, my drawing unit is a Meter. shown value must be in this format x.xxx

0 Likes
Message 6 of 17

-didier-
Advisor
Advisor

Bonjour @Angelswing91 

 

starting hypothesis: the "pkblock" block exists in the drawing and has three attributes, the first is the vertex number, the second is the PK and the third is "type" by default.

Try this code, I think it will be ok :

(setq ent (car (entsel "\nPolyligne de référence ?\n")))
(setq vlapol (vlax-ename->vla-object ent))
(repeat (setq par (fix (vlax-curve-getEndParam vlapol)))
    (command "_insert" "pkblock" 
             (vlax-curve-getpointatparam vlapol par)
             "" "" ""
             (itoa par)
             (rtos (/ (vlax-curve-getDistatParam vlapol par) 1000) 2 3)
             "type"
             )
    (setq par (1- par))
    )

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 7 of 17

Kent1Cooper
Consultant
Consultant

A little suggestion:

Filling in the Attribute values as part of the INSERT command means you need to know their order in the Block definition, and you need to supply values for all Attributes that will be requested, whether or not you have values ready.  But this can be done without those burdens, by using the (setpropertyvalue) approach, with which you can assign values without regard to their order, and to only those Attributes that you want to work with.  This is because in (getpropertyvalue)/(setpropertyvalue) functions, an Attribute tag is a "property" of the Block insertion, and you can set its value as you can any other property.

 

Turn off Attribute requesting, Insert the Block without supplying Attribute values, and then:
(setpropertyvalue (entlast) "KOORDINATE" {supply the vertex number})

(setpropertyvalue (entlast) "KM" {supply the calculated distance from the start})

You can ignore the "TYPE" Attribute if you don't have anything to put in it yet.

 

Kent Cooper, AIA
0 Likes
Message 8 of 17

-didier-
Advisor
Advisor

Bonjour @Kent1Cooper 

 

I fully understand those comments, they are constructive.
I proposed a written solution quickly with hypotheses for the block as I say in the preamble.

Indeed, to make the proposal more robust, your solution is perfect (hypothesis: we know the tags of the block).

 

I am flattered that you make comments about my code. As a little French, I often read the questions without answering them by shyness.

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 9 of 17

CADaSchtroumpf
Advisor
Advisor

If you want, you can try this?

0 Likes
Message 10 of 17

Sea-Haven
Mentor
Mentor

Should you look at the vertex point and check the angle of the line in and out so rotate block to a 1/2 angle where relevant or in case of straights it would be at say 90 degrees. If its a road they are not plain ortho but all over the place with regard to direction. Plenty of chainage.lsp examples do this. 

0 Likes
Message 11 of 17

Angelswing91
Contributor
Contributor

I apologies for the delay in responding, unfortunately due to more urgent projects this task had to be postponed for some time.

 

The sequence is consecutive according to the original polyline vertexes. Blocks should be placed on each vertex. 

0 Likes
Message 12 of 17

Angelswing91
Contributor
Contributor
Sorry for late answer... but not working... (i've changed "pkblock", to my block name) nothing happens and in command line appears "0".
0 Likes
Message 13 of 17

Angelswing91
Contributor
Contributor
Oh.. Thank you for your suggestion!.. but I need exactly this kind of block structure and information presentation (like in my image). This is stated in the specification and a drawing with this data is checked automatically by the system.
0 Likes
Message 14 of 17

Sea-Haven
Mentor
Mentor

This image is using a chainage.lsp you can see that it does increments, the add chainage at vertex could be added, I am sure other versions do it, the reason I mention it is that it rotates the text to be 90 off the pline.

 

SeaHaven_0-1713493854950.png

 

0 Likes
Message 15 of 17

CADaSchtroumpf
Advisor
Advisor

@Angelswing91 

Without your block provided in DWG!

But you can try this from the modified previous code (I'm not sure about the block definition)

 

0 Likes
Message 16 of 17

Angelswing91
Contributor
Contributor

Sorry (now added)

0 Likes
Message 17 of 17

CADaSchtroumpf
Advisor
Advisor

With your block, even if it does not exist in your drawing.

0 Likes