Add Vertex to 2D / 3D Plines (depending on a specific distance) ?

Add Vertex to 2D / 3D Plines (depending on a specific distance) ?

braudpat
Mentor Mentor
3,942 Views
30 Replies
Message 1 of 31

Add Vertex to 2D / 3D Plines (depending on a specific distance) ?

braudpat
Mentor
Mentor

Hello

 

SORRY I don't find my dream with Google but my keywords were maybe not the right ones !?

 

I am looking for a Lisp routine concerning 2D or 3D PLines (Closed or NOT)

Off course 2D/3D PLines must not be splined !

I have to complexify PLines ! Depending on a distance (DIST)

 

1 - Question : Distance (Default value = 10.00) : ?

2 - Classic ACAD selection ...

So retaining only 2D or 3D PLines (Closed or NOT) on unlocked layers ...

3 - Analyse each segment ... If a segment is longer than DIST create a new Vertex

and if necessary on the same segment create AGAIN a new vertex ... And so one ...

So if a segment is 35.00 long, I will get 3 new vertex on THIS segment

If a segment is < 10.00 : NO new vertex

Process next segment then process next Pline

 

It's only a question of "Add a Vertex" on existing 2D/3D PLines !

 

Please don't explode because I have XDATAs and ODs (from MAP / CIVIL) on these Plines !

 

I hope, I am clear !

 

---- I know that 2D Plines can have ARCs! Maybe it's too complex to add some new vertex on Arc !

---- So please ignore the arcs on 2D Plines and go directly to the next segment !!

 

Thanks in advance, THE HEALTH (Stay Safe), Regards, Patrice

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Accepted solutions (3)
3,943 Views
30 Replies
Replies (30)
Message 2 of 31

dlanorh
Advisor
Advisor

In the case of 3dPolylines is this a horizontal distance (as with LWPolylines) or the distance along the line?

I am not one of the robots you're looking for

0 Likes
Message 3 of 31

braudpat
Mentor
Mentor

Hello @dlanorh 

 

For 3D PLines, it will be the real DIST along the 3D Segment !

 

Thanks in advance, THE HEALTH (Stay Safe), Regards, Patrice

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 4 of 31

dlanorh
Advisor
Advisor

I forget to ask about lwpolylines with arc segments, or are these to be ignored as well?  

I am not one of the robots you're looking for

0 Likes
Message 5 of 31

john.uhden
Mentor
Mentor

Wait a second.  If a segment length is 10.00001 units, you want to add a vertex at 10.00 units?

Are you trying to make a more exact surface model?  Land Desktop had the vertex addition for 3Dpolys and sampling settings for LWPoly contours.  Doesn't C3D have those capabilities?

John F. Uhden

0 Likes
Message 6 of 31

braudpat
Mentor
Mentor

Hello @john.uhden 

 

YES if the segment length is 10.1 then I would like a NEW Vertex at 10.0 !

 

Thanks in advance, Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 7 of 31

braudpat
Mentor
Mentor

Hello @dlanorh 

 

As I said, if it is too complex to manage ARCs on 2D Plines, please IGNORE ARCs !

 

Thanks in advance, Regards, Patrice

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 8 of 31

john.uhden
Mentor
Mentor
Okay, Pat. We can do it, even with arc segments. It's just that my
domestic boss has chores for me. I'm in trouble already.

John F. Uhden

0 Likes
Message 9 of 31

dlanorh
Advisor
Advisor

It's not difficult, it would just decurve the arc segments unless you recalculate the bulge for each new vertex.

 

I wanted to check which option you wanted, as I already have something that works to produce straight segment polylines and would need to adapt it if the bulges needed recalculating.

I am not one of the robots you're looking for

0 Likes
Message 10 of 31

devitg
Advisor
Advisor

@braudpat , please would upload a sample dwg ?

0 Likes
Message 11 of 31

braudpat
Mentor
Mentor

Hello Friends

 

If you want to process Arcs, please do it with the easiest way !!

But it is not my first priority !

 

I have a beautiful routine from Gilles, which transform 2D Arcs inside 2D PLines to many small segments !

 

Don't forget that 2D / 3D Plines can have only ONE Segment ! or MANY !!

 

Thanks in advance (Stay Safe), Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 12 of 31

braudpat
Mentor
Mentor

Hello

 

A DWG to test ... Test with a DIST = 100 / 200 / 300 ...

 

Thanks in advance (Stay Safe), Regards, Patrice

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 13 of 31

john.uhden
Mentor
Mentor
Aw, c'mon Ron. So you would prefer the Daytona 500 to be run in a straight
line?
No, I see... You want the curves to be sharp angular tangents. I think the
winning vehicle would have to be a tank. 😂

John F. Uhden

0 Likes
Message 14 of 31

dlanorh
Advisor
Advisor
Accepted solution

Attached is Test Lisp and returned Test Drawing. Feel free to rename the lisp as per your requirements, currently "test" to run. The lisp has been run on your test drawing using 100, 200 and 300 as the max distance. The selection set collects but does not process curve and spline fit LWpolylines or spline fit 3dpolylines. It will handle LWpolylines with arc segments but at present removes the bulges.

 

I am not one of the robots you're looking for

Message 15 of 31

dlanorh
Advisor
Advisor

@john.uhden wrote:
Aw, c'mon Ron. So you would prefer the Daytona 500 to be run in a straight
line?
No, I see... You want the curves to be sharp angular tangents. I think the
winning vehicle would have to be a tank. 😂

It would probably be better for the planet, 😁 but it would also be crap for the spectators. ☹️

 

A curve is just a series of straight lines with a minimal deviation between each segment.

 

I am not one of the robots you're looking for

0 Likes
Message 16 of 31

braudpat
Mentor
Mentor

Hello Friends

 

YES some minimal tests show a great routine !

 

THANKS to @dlanorh and to @john.uhden for all the routines

they have written for me and others people !

 

XDs and ODs are always HERE ...  Beautiful !!

 

THE HEALTH (Stay Safe), Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 17 of 31

Sea-Haven
Mentor
Mentor

Just a my $0.05 would it better to look at a value slightly less than the spacing and do equal intervals then as suggested 10.0 and 10.1 would not occur rather 5.05 spacing. See close spacing in image at start of an arc, The task is to add more vertices so being exact 10.0 I dont think is really locked in. The minimum would still apply. 10.1/10 = ? 20.1/10= 2.01 say roundup TO 3 space = 6.7

 

screenshot205.png

0 Likes
Message 18 of 31

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Good stuff for 3DPOLY, but for LWPOLYLINE with bulge, the result is aleatory

For only LWPOLYLINE I propose this. This respect bulge and width of polyline and also Xdata or Object Data...

(vl-load-com)
(defun add_vtx (obj add_pt ent_name fz / sw ew nw bulg next)
	(vla-GetWidth obj (fix add_pt) 'sw 'ew)
	(vla-addVertex
		obj
		(1+ (fix add_pt))
		(vlax-make-variant
			(vlax-safearray-fill
				(vlax-make-safearray vlax-vbdouble (cons 0 1))
					(list
						(car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
						(cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
					)
			)
		)
	)
	(setq next (1+ (fix add_pt)))
	(while (equal (vlax-curve-getdistatparam obj next) (vlax-curve-getdistatparam obj (fix add_pt)) fz)
		(setq next (1+ next))
	)
	(setq
		nw
		(*
			(/
				(- ew sw)
				(- (vlax-curve-getdistatparam obj next) (vlax-curve-getdistatparam obj (fix add_pt)))
			)
			(- (vlax-curve-getdistatparam obj add_pt) (vlax-curve-getdistatparam obj (fix add_pt)))
		)
		bulg (atan (vla-GetBulge obj (fix add_pt)))
	)
	(vla-SetBulge obj
		(fix add_pt)
		(/
			(sin (* 4 bulg (- add_pt (fix add_pt)) 0.25))
			(cos (* 4 bulg (- add_pt (fix add_pt)) 0.25))
		)
	)
	(vla-SetBulge obj
		(1+ (fix add_pt))
		(/
			(sin (* 4 bulg (- (1+ (fix add_pt)) add_pt) 0.25))
			(cos (* 4 bulg (- (1+ (fix add_pt)) add_pt) 0.25))
		)
	)
	(vla-SetWidth obj
		(fix add_pt)
		sw
		(+ nw sw)
	)
	(vla-SetWidth obj
		(1+ (fix add_pt))
		(+ nw sw)
		ew
	)
	(vla-update obj)
)
(defun c:AddVtx2Dist ( / js AcDoc Space interval n obj ename v_length)
	(princ "\nSélectionnez une polyligne.")
	(setq js (ssget '((0 . "LWPOLYLINE"))))
	(cond
		(js
			(setq
				AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
				Space
				(if (= 1 (getvar "CVPORT"))
					(vla-get-PaperSpace AcDoc)
					(vla-get-ModelSpace AcDoc)
				)
			)
			(initget 6)
			(setq interval (getdist "\nAjouter un sommet tous les <1.0>?: "))
			(if (not interval) (setq interval 1.0))
			(repeat (setq n (sslength js))
				(setq
					obj (ssname js (setq n (1- n)))
					ename (vlax-ename->vla-object obj)
					v_length 0.0
				)
				(while (< v_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
					(if (not (equal (fix (vlax-curve-getEndParam ename)) v_length 1E-08))
						(progn
							(add_vtx ename (vlax-curve-getParamAtDist ename v_length) obj 1E-08)
							(setq v_length (+ interval v_length))
						)
						(setq v_length (+ interval v_length))
					)
				)
			)
		)
	)
	(prin1)
)

 

Message 19 of 31

john.uhden
Mentor
Mentor
We haven't yet found out the purpose of his request.
I looked back and found I had provided him one for splitting segments in
half, so I guess this is either a refinement or something different.

John F. Uhden

Message 20 of 31

braudpat
Mentor
Mentor

Hello @john.uhden 

 

YES it's a refinement of a previous demand where I asked for only a New Vertex at the Middle of segment ...

 

Thanks John for your routine, THE HEALTH (Stay Safe), Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes