Convert splines to polylines horizontal and vertical line

Convert splines to polylines horizontal and vertical line

Anonymous
Not applicable
2,750 Views
6 Replies
Message 1 of 7

Convert splines to polylines horizontal and vertical line

Anonymous
Not applicable

I want to change the spline to a polyline consisting of a horizontal line (n1) / a vertical line (n2).
It is difficult because there are too many lines.
Are you there to help?11.PNG

0 Likes
Accepted solutions (2)
2,751 Views
6 Replies
Replies (6)
Message 2 of 7

marko_ribar
Advisor
Advisor

Values n1/n2 are obviously varying... Can you explain better how do you want to achieve horizontal/vertical mimic of I suppose planar splines (you showed open spline example)... I'd try something like SPLINEDIT/Polyline option or CVREFINE/CVREBUILD command and after you get many vertices/control points, you can create (x y) point list... Then I suppose you could do something like : (setq plplst (append (list (car plst)) (apply 'append (mapcar '(lambda ( a b ) (list (list (/ (+ (car a) (car b)) 2.0) (cadr a)) (list (/ (+ (car a) (car b)) 2.0) (cadr b)))) plst (cdr plst))) (list (last plst)))) to get pline point list and finally (entmake/entmakex) new pline...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 7

Anonymous
Not applicable

I don't know much about lisp.

It was difficult to express in words, so I drew roughly.
What I want is, 
1. Select the splines I want to convert.
2. Enter origin and n1, n2 values.
3. Convert to Polyline
(yellow/green lines: polylines that do not intersect splines;
Red line : Polyline crossing with splines)

Can you make all three or one LISP?


Thank you.22.PNG

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....
1. Select the splines I want to convert.
2. Enter origin and n1, n2 values.
3. Convert to Polyline
(yellow/green lines: polylines that do not intersect splines;
Red line : Polyline crossing with splines) ....


 

Here's a start on a crossing-the-path [your red] version.  It works on any  kind of path object [anything in the (vlax-curve...) class -- Line, Polyline, Arc, Circle, Spline, Ellipse], one at a time.  But it doesn't  yet do a lot of things it could [verify selection of valid path object including forbidding Xline/Ray, do multiple paths, remember 'n1' & 'n2' values, error handling, etc.], and so far it always uses 0,0 for the origin.  It can be made to ask for an origin, and have those other features, all with additional code, but see what you think of it so far.

 

(vl-load-com); if needed
(defun C:SPC ; = Stepped-Polyline Conversion (/ round roundXY pathsel path pathlen closed stepH stepV steps pathinc step lastpt plv1 roundpt roundX roundY) (defun round (value to) ; modified from Joe Burke [no 'to' value of 0] (* (atoi (rtos (/ (float value) to) 2 0)) to) ); defun -- round (defun roundXY (pt) (list (round (car pt) stepH) (round (cadr pt) stepV)) ); defun -- roundXY (setq pathsel (entsel "\nPath to convert to stepped Polyline: ") path (car pathsel) pathlen (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path)) closed (vlax-curve-isClosed path) stepH (getdist "\nHorizontal stepping increment: ") stepV (getdist "\nVertical stepping increment: ") steps (fix (/ pathlen (/ (min stepH stepV) 4))); arbitrary -- 1/4 of smaller step size pathinc (/ pathlen steps) step 0 ); setq (command "_.pline" "_none" (setq plv1 (roundXY (vlax-curve-getStartPoint path)))) (setq lastpt plv1) (repeat (- steps (if closed 1 0)) (setq roundpt (roundXY (vlax-curve-getPointAtDist path (* pathinc (setq step (1+ step)))))) (if (not (or (equal roundpt lastpt 1e-4) (equal roundpt plv1 1e-4))) (progn (if (or ; orthogonal from previous? (equal (car roundpt) (car lastpt) 1e-4); same X (equal (cadr roundpt) (cadr lastpt) 1e-4); same Y ); or (command "_none" roundpt); then -- add it to Polyline (progn ; else -- find nearer orthogonal next point (setq roundX (list (car lastpt) (cadr roundpt)); above or below previous roundY (list (cadr lastpt) (car roundpt)); left or right of previous roundpt ; replace (if ; which is closer to path? (< (distance roundX (vlax-curve-getClosestPointTo path roundX)) (distance roundY (vlax-curve-getClosestPointTo path roundY)) ); < roundX ; then roundY ; else ); if & roundpt ); setq (command "_none" roundpt); add it to Polyline ); progn ); if (setq lastpt roundpt) ); progn ); if ); if (command (if closed "_close" "")) ); defun

EDIT:

Its initially calculated rounded locations at first sometimes resulted in diagonal segments, and I had worked out how to prevent that along the way, but it still needs some work to prevent that possibility at the Closing end of a closed path object:

SPC.PNG

I'll have to think about how to fix that one....

Kent Cooper, AIA
Message 5 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

Too late to Edit again, but I found a mistake.  This line:

 

             roundY (list (cadr lastpt) (car roundpt)); left or right of previous

 

should be like this instead:

 

              roundY (list (car roundpt) (cadr lastpt)); left or right of previous

 

And here's a condition that can occur, which I think is "legitimate" under the crieteria, but possibly undesirable for you -- stepping out and then back in along the same route:

SPC2.PNG

 

AND now, having made the first change in this Message, I did not  get the diagonal closure shown in the image in the previous Message, on the same Ellipse in the same position with the same stepping values.  But I'm not sure it can't happen under some geometric conditions.

Kent Cooper, AIA
Message 6 of 7

Anonymous
Not applicable

It helped a lot.
Thank you very much.

0 Likes
Message 7 of 7

pbejse
Mentor
Mentor

@Kent1Cooper wrote:
(vl-load-com); if needed
(defun C:SPC ; = Stepped-Polyline Conversion (/ round roundXY pathsel path pathlen closed stepH stepV steps pathinc step lastpt plv1 roundpt roundX roundY)
...
... ); defun

....


 

Very nice Kent thumbsup.gif

 

 

0 Likes