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

Drawing of a perpendicular between 2 polylines

34 REPLIES 34
Reply
Message 1 of 35
Anonymous
3064 Views, 34 Replies

Drawing of a perpendicular between 2 polylines

Good afternoon. Prompt, please. There is a drawing with set of polylines. How with the help lisp to choose two of them and to construct between them perpendiculars? Thus the first polyline should be broken into identical pieces, and from each these points, since the polyline beginning, perpendiculars on the second polyline will be constructed.
P.S. Polyines can be parallel and not parallel. Edited by: m45bgz on Aug 19, 2009 5:14 AM
34 REPLIES 34
Message 21 of 35
Kent1Cooper
in reply to: Anonymous

The attached is a work in progress, but try it out. Some of the things I would like to change have to do with contour lines at different elevations, since I have seen topographical drawings in which each contour line is actually at its designated elevation. The attached would not work on such a drawing, because the IntersectWith method requires the intersecting things to be at the same elevation. Some other things in the description at the top are also "wish list" items, and are not true yet, either. But for things in the same plane in the World Coordinate System, it seems to work, for both open-ended and closed contours. And it can use certain things other than Polylines, and has some other bells and whistles I took from another routine I wrote.

If it works for you, I will continue to refine it, though I'm now thinking about making something with much wider application [for example, something that would let the User choose *any* number of intermediate strokes, or choose to draw lines of any specified length, not just toward another selected object, or choose to draw them centered on the selected path rather than to one side, etc., etc.]. If I come up with something that does all the things I have in mind, it would do what you want with the right options, but would also do many other things.

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

wrote in message news:6245955@discussion.autodesk.com...
MelFranks, I has tested yours lisp, all is good, that is necessary. But it works only on the closed contour. On the opened
contour does not work. I spread the drawing in which this lisp too should work. Check up, please, and if you can, under it make
lisp.

M45bgz,

Attached is an update.


Kent Cooper,

I didn't realize you were working on this since several days had passed without a reply.
Maybe one should call "I got it" when the pass is thrown. 🙂
I'm sure I'll learn something looking at your code, which is always a good thing.
It's also interesting to look at different approaches to a problem.
At any rate, not trying to step on your toes.

Regards,

Mel
Message 23 of 35
Kent1Cooper
in reply to: Anonymous

I wouldn't want to lay claim to a thread, partly because someone else might be able to provide a solution sooner than I might, and partly to see what people come up with and perhaps learn something. You can step on my toes all you want [as they say, I only use the bottoms, so someone may as well use the tops]. I was partway into working something out when I saw your suggestion come in, so I was content to lay back until the OP responded, to find out whether it worked for them [I didn't test it myself, though I did look at it briefly, enough to see that we had the same ideas about how to handle parts of the problem]. I only posted my thing after they responded, because I knew mine would work on open Polylines. But now I've got my sights on the broader concept I mentioned before, since I figured it might be useful to have something that would include other options beyond the very particular original question.

--
Kent Cooper


MelFranks wrote...
....
I didn't realize you were working on this since several days had passed without a reply.
Maybe one should call "I got it" when the pass is thrown. 🙂
....
Kent Cooper, AIA
Message 24 of 35
Anonymous
in reply to: Anonymous

MelFranks, It already works, but at drawing of slopes in the opened contour in some places is drawn very long lines. Look on an example as slopes thanks to yours lisp - Otkos2.dwg (AutoCAD 2004) were drew. If you can, edit the lisp that all was drew correctly.
Message 25 of 35
Anonymous
in reply to: Anonymous

wrote in message news:6246450@discussion.autodesk.com...
MelFranks, It already works, but at drawing of slopes in the opened contour in some places is drawn very long lines. Look on
an example as slopes thanks to yours lisp - Otkos2.dwg (AutoCAD 2004) were drew. If you can, edit the lisp that all was drew
correctly.

The issue is that the program is looking for intersections at right angles to the direction of the initial polyline, and that
intersection may in some cases be in an undesirable location.
I've made some changes, one of which was making the program interactive.
You can step through each operation and either accept it, delete the line, or change the endpoint.
Alternatively, you can select "Nonstop" and it will complete automatically.

Regards,

Mel
Message 26 of 35
Kent1Cooper
in reply to: Anonymous

That is exactly the reason why I wondered in my first post whether you really want the lines drawn perpendicular *from* the first selected contour line, rather than perpendicular *to* the second one. But even the other way, you will sometimes get situations where it doesn't do what you would prefer. Go back there and try my suggested routine, with and without the "per" code line in it. It doesn't do the intermediate strokes [I didn't know about those yet, at the time], but if what it does with the full-length lines is more like what you want, it can easily be made to do the rest.

I think it would be very difficult to define exactly what "drawn correctly" would mean, if sometimes it means perpendicular to the first contour, sometimes it means perpendicular to the second one, and sometimes it means to the closest point on the second one, which may not be perpendicular to either. I wonder whether dividing both contours into the same number of equal segments would look more like what you want. But writing code for that would take some care, because open-ended contour lines might be drawn in opposite directions, or closed ones might not have their starting points close to each other.

--
Kent Cooper


m45bgz wrote...
....drawing of slopes in the opened contour in some places is drawn very long lines. ..... If you can, edit the lisp that all was drew correctly.
Kent Cooper, AIA
Message 27 of 35
Anonymous
in reply to: Anonymous

One more change. If you manually pick end points, pick them all on the opposite polyline.
Any strokes that should be short will automatically pull back to 1/2 length.
Attached is a result achieved by picking some points manually.

Regards,

Mel
Message 28 of 35
CADaSchtroumpf
in reply to: Anonymous

Try this
{code}
(defun selec_tal (msg / js)
(princ (strcat"\nSélectionner le " msg " de talus: "))
(while
(not
(setq js
(ssget "_+.:E:S"
(list
(cons 0 "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE")
(cons 67 (if (eq (getvar "CVPORT") 2) 0 1))
(cons 410 (if (eq (getvar "CVPORT") 2) "Model" (getvar "CTAB")))
(cons -4 " (cons -4 "&") (cons 70 112)
(cons -4 "NOT>")
)
)
)
)
)
js
)
(defun c:talus ( / js_htal e_tal g_barb e_barb vlaobj pt_start pt_end param_start param_end perim_obj
d_x lst_ptal lst_pdir deriv lst_3htal lst_2htal pt_hsel param alpha js_btal v1 v2 det_or scnd_lst count lst_flag pt)
lst_3htal lst_2htal pt_hsel
(setq js_htal (selec_tal "haut"))
(redraw (setq e_tal (ssname js_htal 0)) 3)
(initget 91)
(setq g_barb (getdist "\nLongueur des barbes les plus longues: "))
(setq e_barb (/ g_barb 11.0))
(setq
vlaobj (vlax-ename->vla-object e_tal)
pt_start (vlax-curve-getStartPoint vlaobj)
pt_end (vlax-curve-getEndPoint vlaobj)
param_start (vlax-curve-getStartParam vlaobj)
param_end (vlax-curve-getEndParam vlaobj)
perim_obj (vlax-curve-getDistAtParam vlaobj param_end)
)
(setq d_x 0.0 lst_ptal nil lst_pdir nil)
(while (< d_x perim_obj)
(setq
lst_ptal (cons (vlax-curve-getPointAtDist vlaobj d_x) lst_ptal)
deriv (vlax-curve-getfirstderiv vlaobj (vlax-curve-getparamatpoint vlaobj (car lst_ptal)))
lst_pdir (cons (atan (cadr deriv) (car deriv)) lst_pdir)
d_x (+ d_x e_barb)
)
)
(setq lst_3htal lst_ptal)
(setq lst_2htal (mapcar 'list (mapcar 'car lst_ptal) (mapcar 'cadr lst_ptal)))
(setq
pt_hsel (vlax-curve-getClosestPointTo vlaobj (trans (cadar (cdddar (ssnamex js_htal 0))) 1 0))
param (vlax-curve-getparamatpoint vlaobj pt_hsel)
deriv (vlax-curve-getfirstderiv vlaobj param)
alpha (atan (cadr deriv) (car deriv))
)
(redraw (setq e_tal (ssname js_htal 0)) 4)
(setq js_btal (selec_tal "bas"))
(redraw (setq e_tal (ssname js_btal 0)) 3)
(setq
v1 (mapcar '- (polar pt_hsel alpha 1.0) pt_hsel)
v2 (mapcar '- (trans (cadar (cdddar (ssnamex js_btal 0))) 1 0) pt_hsel)
det_or (apply '(lambda (x1 y1 z1 x2 y2 z2) (- (* x1 y2) (* y1 x2))) (append v1 v2))
)
(cond
((> det_or 0.0) (setq ang_dir (/ pi 2)))
((< det_or 0.0) (setq ang_dir (- (/ pi 2))))
)
(setq lst_pdir (mapcar '(lambda (x) (+ ang_dir x)) lst_pdir) count -1 lst_flag nil)
(redraw (setq e_tal (ssname js_btal 0)) 4)
(setq scnd_lst (mapcar '(lambda (x y n) (polar x y (/ g_barb n))) lst_2htal lst_pdir
(repeat (length lst_pdir)
(setq count (rem (1+ count) 3))
(if (zerop count)
(setq lst_flag (cons 1 lst_flag))
(setq lst_flag (cons 3 lst_flag))
)
)
))
(while lst_2htal
(entmake
(append
'(
(0 . "LINE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "Talus")
(62 . 35)
(6 . "ByLayer")
(370 . -2)
(100 . "AcDbLine")
)
(list (cons 10 (append (car lst_2htal) '(0.0))))
(list (cons 11 (append (car scnd_lst) '(0.0))))
'((210 0.0 0.0 1.0))
)
)
(setq pt (vlax-invoke (vlax-ename->vla-object e_tal) 'IntersectWith (vlax-ename->vla-object (entlast)) acExtendThisEntity))
(if pt
(entmod (subst (cons 11 pt) (assoc 11 (entget (entlast))) (entget (entlast))))
)
(setq lst_2htal (cdr lst_2htal) scnd_lst (cdr scnd_lst))
)
(prin1)
)
{code}
Message 29 of 35
Anonymous
in reply to: Anonymous

CADaStroumph, first, at you draws only a slope with two strokes, without a choice. Secondly, the length of a slope gets out, and it should be a constant if the perpendicular is under construction correctly, and to change depending on an arrangement of polylines as wrote Kent1Cooper.
Message 30 of 35
Anonymous
in reply to: Anonymous

Kent1Cooper, thanks, all that you have told, it is correct, but I do not know as it to write on lisp. It is possible to edit SlopeStrokes.lsp or test4.lsp, written MelFranks, proceeding from your offers? Edited by: m45bgz on Sep 2, 2009 4:20 AM
Message 31 of 35
Anonymous
in reply to: Anonymous

MelFranks, thanks. The previous variant was better (Posted: Aug 31, 2009 8:50 PM) and it is more convenient for me. And you can change this variant lisp, proceeding from offers Kent1Cooper (Posted: Sep 1, 2009 5:13 PM)?
Message 32 of 35
Anonymous
in reply to: Anonymous

wrote in message news:6247351@discussion.autodesk.com...
MelFranks, thanks. The previous variant was better (Posted: Aug 31, 2009 8:50 PM) and it is more convenient for me. And you
can change this variant lisp, proceeding from offers Kent1Cooper (Posted: Sep 1, 2009 5:13 PM)?

Attached is another change.
I tried both closest point and perpendicular and neither gave decent results.
There is another option, "maximum stroke length", just indicate a distance slightly wider than the widest distance between contours.
The program now attempts to "fix" lines that intersect each other by moving the endpoint to the closest point on the contour.
You may still need to manually move some endpoints and it may simply not work well on certain contour variations.
This will be my last attempt as I have become extremely busy at work.

Regards,

Mel
Message 33 of 35
Anonymous
in reply to: Anonymous

Sorry, I posted the wrong file, attached is the correct one.

Regards,

Mel
Message 34 of 35
Anonymous
in reply to: Anonymous

Many thanks. For me the first variant was better! I will test it. If there will be new thoughts, will look forward to hearing.
Message 35 of 35
Anonymous
in reply to: Anonymous

wrote in message news:6248137@discussion.autodesk.com...
Many thanks. For me the first variant was better! I will test it. If there will be new thoughts, will look forward to hearing.

It would be very helpful to have several examples completed by you to look at.
It may be that a completely different approach is what you are after, as I believe there exists somewhat of a language barrier.

Regards,

Mel

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report