gsc Posted March 5, 2018 Author Posted March 5, 2018 Hi BIGAL, Thanx for the effort sofar. I have tested your code, but what happens if the input polyline contains a vertex point shorter than 50m from the start/end point? I have attached 2 examples with and without arcs to test With your current code these 2 examples fail to put the correct boundary around the polyline Test2.dwg Test1.dwg Quote
BIGAL Posted March 5, 2018 Posted March 5, 2018 (edited) One of the things to keep in mind is that people like myself do the coding for free, and at times there are situations where something does not work. In these situations it may be a case of having to do a manual answer. Is this short end going to be a situation that occurs all the time or only every now and then ? It would be a whole new rewrite to approach the task by offseting original pline both sides find the y offset point use the 1stderivative to trim the two new offset plines then draw in the arrows and rejoin all. Hey I just gave you the answer. Maybe have a go we are here to help. Its like lots of things to do with CAD there is more than one way to achieve a result. In the mean time I will fix up the arc issue in version 2. 1st derivative example in the case of an arc the angle is tangential (defun alg-ang (obj pnt) (angle '(0. 0. 0.) (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pnt ) ) ) ) (setq ang (alg-ang obj pt2)) Edited March 5, 2018 by BIGAL Quote
Grrr Posted March 6, 2018 Posted March 6, 2018 (defun C:test ( / SS off ext i ) (and (setq SS (ssget "_:L-I")) (setq off (getdist "\nInput Offset: ")) (setq ext (getdist "\nInput extension: ")) (repeat (setq i (sslength SS)) (test (ssname SS (setq i (1- i))) off ext) ) ); and (princ) ); defun C:test ; This was a separate #main function, translated easily to subfoo (defun test ( curve off ext / offo ends SS ) (and curve ; (setq curve (car (entsel "\nPick the curve: "))) (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getEndParam (list curve)))) (not (vlax-curve-isClosed curve)) (setq curve (vlax-ename->vla-object curve)) (not (member (vla-get-ObjectName curve) '("AcDbXline" "AcDbRay"))) ; (setq off (getdist "\nInput Offset: ")) ; (setq ext (getdist "\nInput extension: ")) (setq offo (mapcar '(lambda (x) (vlax-invoke curve 'Offset ((eval x) off))) '(- +))) (setq ends (GetEnds curve)) (setq ext (mapcar '(lambda (a b / p) (setq p (apply 'polar (append a (list ((eval b) ext))))) (mapcar '(lambda (xx) (Line p (polar (car a) (+ (* 0.5 PI) (cadr a)) ((eval xx) off)) ) ); lambda '(- +) ); mapcar ); lambda ends '(- +) ) ); setq ext (progn (setq SS (ssadd)) (foreach e (append (mapcar 'vlax-vla-object->ename (apply 'append offo)) (apply 'append ext)) (ssadd e SS)) (setvar 'cmdecho 0) (if (eq "AcDbSpline" (vlax-get-property curve 'ObjectName)) (command "_.PEDIT" "_M" SS "" "10" "_J" "0.0" "") (command "_.PEDIT" "_M" SS "" "_J" "0.0" "") ) (setvar 'cmdecho 1) ); progn ); and (princ) ); defun (vl-load-com) (princ) (defun Line (p1 p2) (entmakex (list (cons 0 "LINE")(cons 10 p1)(cons 11 p2)))) ; Lee Mac (defun GetEnds ( curve ) ; Resulted from BIGAL's help (if (member (type curve) '(ENAME VLA-OBJECT)) (mapcar '(lambda (x / prm) (setq prm ((eval x) curve)) (list (vlax-curve-getPointAtParam curve prm) (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv curve prm))) ) '(vlax-curve-getStartParam vlax-curve-getEndParam) ) ) ) Quote
gsc Posted March 6, 2018 Author Posted March 6, 2018 True, I have the same dilemma at my company, helping people to a higher level and keep ahead yourself or stay lonely at the top For what it's worth, I try to learn from these solutions for future other efficiency issues. Is this short end going to be a situation that occurs all the time or only every now and then ? I am using this function as a subfunction. This polyline is an electrical cable route in a windfarm at sea. There are on average 40-160 routes in a windfarm project. Every cable must have a safety zone. Normally the safety zone applies from start to end with a same offset distance (I have a LSP code for that), but this client suddenly wants safety zones with tapered ends Approx. 14% of these routes have shorter straight ends than the specified 50m, this applies to most windfarm projects. however this is the first project with tapered ends. Since I can't look into the future, a preventive adjustment of the existing code may be useful for other projects. thanx with this answer I will first try myself. Grrrr: your code result in the yellow line, but it should be the red line (see image) Quote
BIGAL Posted March 6, 2018 Posted March 6, 2018 (edited) Watch this space almost worked out the arc issue, which works for short line segments basically a full rewrite like Grrr, the code will allow pick line, arc or pline will work. The code in my 1st post has been redone totally and seems to work for line plines and arcs. Because it uses trim I plan on adding a better select trim side rather than use end point. So please let me know if it does not work. Two things I found but should not be a problem it will work as required, if the end shape short segments if funny angles the taper crosses over a pline. 2nd just zoom so you can see object before running. Edited March 6, 2018 by BIGAL Quote
Grrr Posted March 6, 2018 Posted March 6, 2018 Back to the short answer: Yes its possible. But like BIGAL there are many situations to consider. Heres a thread which codes might help out (to lengthen curves). I think approach like Lee's here+here would solve this in an ideal way (PEDIT required). In a conjunction with a lengthen curve subfoo my attempt results to: As you can see depending on how the ends are curved the results may be [un]expecting/[un]wanted. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.