Draw Polyline

Draw Polyline

SilentStrike24
Enthusiast Enthusiast
2,940 Views
24 Replies
Message 1 of 25

Draw Polyline

SilentStrike24
Enthusiast
Enthusiast

Hello all. Do you know if there's any free routine that makes the following?

 

I need to create the green polyline and the lengths A, B, C, D should be questioned.

C and D are always perpendicular on the original lines and they're at a specific distance from the ends (meaning lengths A, B).

Desired endpoints of the original lines should be the nearest endpoints to the cursor selection (needed when calculating from which end you want distances A, B).

Also, this polyline should always be on the smaller angle side, if you think at 360°.

Thanks!

 

nicolaearhire10_0-1640817708035.png

 

 

0 Likes
Accepted solutions (1)
2,941 Views
24 Replies
Replies (24)
Message 2 of 25

Sea-Haven
Mentor
Mentor

Is this not the same as the post requesting "CHAMFER" answer about 2 weeks ago, I will check maybe its on another forum. I know I posted as had questions. It was a double chamfer question.

0 Likes
Message 3 of 25

SilentStrike24
Enthusiast
Enthusiast

Yes, it’s the same idea.

I hope i‘m not “breaking” forum rules by posting again, but i urgently need a solution for this one.

And for that topic i got no help till now, so i thought posting again would be a solution.

I guess no one’s looking in posts from 2-3 weeks ago to solve, anymore.

If that’s not ok, i’ll delete it and search for guidance somewhere else.

0 Likes
Message 4 of 25

john.uhden
Mentor
Mentor

I am curious.  You presented an image, so aren't you capable of doing this using stock AutoCAD commands?

What, do you have hundreds of them to do and the boss is allowing only 5 minutes to do the work?  He should rethink his budget.  Maybe it's funny but when I need my shrubs trimmed I can never find anyone to do it for free, and especially in just 5 minutes.

John F. Uhden

0 Likes
Message 5 of 25

SilentStrike24
Enthusiast
Enthusiast

Hi @john.uhden,

 

You’re thinking is right. Want something, you should pay for it, or “rethink the budget”:))

But i guess this is the point of this kind of forums: get in touch with people having the same hobbies, share ideas and, consequently, help others improve.

Regarding your shrubs, I’ve seen here custom made routines of hundreds of code lines, i hardly believe my question is that hard. So what should be free and what not?

If you wanna help, help; if you consider this is a must-pay or an extremely difficult task, move on. It’s that simple.

FYI: no boss is asking me for this. It’s me who’s trying to ease my day to day work. So if you think i earn money for this polyline, you couldn't be more wrong.

 

0 Likes
Message 6 of 25

Sea-Haven
Mentor
Mentor

This is the code, Its not hard draw a circle from IP, from the 2 points draw a 90 line of length, join a new line end of the 2 lines.

 

OOPS method not code. 

 

It is not a bad task to start learning lisp. Google "draw line perp from line lisp autocad"

0 Likes
Message 7 of 25

SilentStrike24
Enthusiast
Enthusiast

Thanks for the help, @Sea-Haven.

I’ll try to solve it.

0 Likes
Message 8 of 25

ВeekeeCZ
Consultant
Consultant
Accepted solution
(defun c:Chamfer2 ( / ap av am bp bm ag ps pe)
  
  (if (and (or *ch-a* (setq *ch-a* 2.))
	   (setq *ch-a* (cond ((getdist (strcat "\nSpecify distance A <" (rtos *ch-a*) ">: "))) (*ch-a*)))
	   (or *ch-b* (setq *ch-b* 2.))
	   (setq *ch-b* (cond ((getdist (strcat "\nSpecify distance B <" (rtos *ch-b*) ">: "))) (*ch-b*)))
	   (or *ch-c* (setq *ch-c* 0.5))
	   (setq *ch-c* (cond ((getdist (strcat "\nSpecify distance C <" (rtos *ch-c*) ">: "))) (*ch-c*)))
	   (or *ch-d* (setq *ch-d* 0.5))
	   (setq *ch-d* (cond ((getdist (strcat "\nSpecify distance D <" (rtos *ch-d*) ">: "))) (*ch-d*)))
	   )
    
    (while (and (setq ap (cadr (entsel "\nSelect AD object: ")))
		(setq av (osnap ap "end"))
		(setq am (osnap ap "mid"))
		(setq bp (cadr (entsel "\nSelect BC object: ")))
		(setq bm (osnap bp "mid"))
		(setq ag (- (angle av bm) (angle av am)))
		(setq ag (if (< ag 0) (+ ag pi pi) ag))
		)
      
      (command "_.pline"
	       "_non" (setq ps (polar av (angle av am) *ch-a*))
	       "_non" (polar ps ((if (< ag pi) + -) (angle av am) (/ pi 2)) *ch-d*)
	       "_non" (polar (setq pe (polar av (angle av bm) *ch-b*))
			     ((if (< ag pi) - +) (angle av bm) (/ pi 2))
			     *ch-c*)
	       "_non" pe "")))
  (princ)
  )
0 Likes
Message 9 of 25

Kent1Cooper
Consultant
Consultant

I would change the wording of one prompt:

 .... "\nSelect AD object closer to its end that meets BC object: " ....

 

I suspect [without testing] that the result would go wonky if it is selected closer to its other end.

 

Or, the issue could be avoided [both AD and BC objects could be selected anywhere] by also saving the result of using ENDpoint Osnap on the BC object, and using (inters) with the endpoints and midpoints of both to determine the 'av' variable [where the two meet].

Kent Cooper, AIA
0 Likes
Message 10 of 25

SilentStrike24
Enthusiast
Enthusiast

Thanks for the help @ВeekeeCZ !

Code works perfect. It saves me a lot of time.

One more thing if i'm not asking too much, you know if the code can be updated so it can work on polylines too? You can see below how it is drawn when having polylines.

 

SilentStrike24_0-1640959207701.png

Anyway, thanks again for your time.

0 Likes
Message 11 of 25

CADaSchtroumpf
Advisor
Advisor

Hi,

I tried to start from the 'CHAMFER' command with the 'polyline' option to apply the principle of this special chamfer to all the vertices.
It remains a test, it seems to work but I certainly did not consider all the scenarios: it was more complicated than I thought.

(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:chamfer_po ( / lst_var js ent dxf_ent lst_pt new_lst_pt dfzz ob pt1 pt2 pt_m deriv alpha v1 v2 det_or nw_pt prm pt@subst)
  (mapcar '(lambda (x) (setq lst_var (cons (getvar x) lst_var)))
    '("CMDECHO" "TRIMMODE" "CHAMMODE" "COMMANDPREVIEW" "PROJMODE")
  )
  (mapcar '(lambda (x y) (setvar x y))
    '("CMDECHO" "TRIMMODE" "CHAMMODE" "COMMANDPREVIEW" "PROJMODE")
    '(1 1 0 1 1)
  )
  (mapcar
    '(lambda (x)
      (command "_.SETVAR" x
        (while (not (zerop (getvar "CMDACTIVE")))
          (command pause)
        )
      )
    )
    '("CHAMFERA" "CHAMFERB" "USERR1" "USERR2")
  )
  (princ "\nSelect polyline")
  (while (null (setq js (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (-4 . ">") (90 . 2)))))
    (princ "\nOject isn't valide")
  )
  (setq
    ent (ssname js 0)
    dxf_ent (entget ent)
    lst_pt (mapcar '(lambda (x) (trans x ent 1)) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) dxf_ent)))
  )
  (command "_.CHAMFER" "_Polyline" ent)
  (setq
    dxf_ent (entget ent)
    new_lst_pt (mapcar '(lambda (x) (trans x ent 1)) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) dxf_ent)))
  )
  (setq dfzz 1E-08)
  (foreach el lst_pt
    (setq new_lst_pt (vl-remove-if '(lambda (x) (and (equal (car x) (car el) dfzz) (equal (cadr x) (cadr el) dfzz))) new_lst_pt))
  )
  (cond
    (new_lst_pt
      (setq ob (vlax-ename->vla-object ent))
      (if (not (zerop (logand 1 (cdr (assoc 70 dxf_ent)))))
        (setq new_lst_pt (append (cdr new_lst_pt) (list (car new_lst_pt))))
      )
      (while (cdr new_lst_pt)
        (setq
          pt1 (car new_lst_pt)
          pt2 (cadr new_lst_pt)
          pt_m (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5 0.5))
          deriv (vlax-curve-getfirstderiv ent (1- (vlax-curve-getparamatpoint ent (vlax-curve-getClosestPointTo ent pt1))))
          alpha (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
          v1 (mapcar '- (polar pt1 alpha 1.0) pt1)
          v2 (mapcar '- pt_m pt1)
          det_or (apply '(lambda (x1 y1 z1 x2 y2 z2) (- (* x1 y2) (* y1 x2))) (append v1 v2))
          nw_pt (trans (polar pt1 (if (> det_or 0.0) (+ alpha (* pi 0.5)) (- alpha (* pi 0.5))) (getvar "USERR1")) ent 0)
          prm (vlax-curve-getparamatpoint ent (vlax-curve-getClosestPointTo ent (trans (polar pt1 (angle pt1 pt2) (getvar "USERR1")) ent 0)))
        )
        (add_vtx ob prm ent dfzz)
        (setq
          pt@subst (nth (1+ (fix prm)) (mapcar '(lambda (x) (trans x ent 1)) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (setq dxf_ent (entget ent))))))
          dxf_ent (subst (cons 10 (list (car nw_pt) (cadr nw_pt))) (cons 10 (list (car pt@subst) (cadr pt@subst))) dxf_ent)
        )
        (entmod dxf_ent)
        (setq
          deriv (vlax-curve-getfirstderiv ent (vlax-curve-getparamatpoint ent (vlax-curve-getClosestPointTo ent pt2)))
          alpha (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
          nw_pt (trans (polar pt2 (if (> det_or 0.0) (+ alpha (* pi 0.5)) (- alpha (* pi 0.5))) (getvar "USERR2")) ent 0)
          prm (vlax-curve-getparamatpoint ent (vlax-curve-getClosestPointTo ent (trans (polar pt2 (angle pt2 pt1) (getvar "USERR2")) ent 0)))
        )
        (add_vtx ob prm ent dfzz)
        (setq
          pt@subst (nth (1+ (fix prm)) (mapcar '(lambda (x) (trans x ent 1)) (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (setq dxf_ent (entget ent))))))
          dxf_ent (subst (cons 10 (list (car nw_pt) (cadr nw_pt))) (cons 10 (list (car pt@subst) (cadr pt@subst))) dxf_ent)
        )
        (entmod dxf_ent)
        (setq new_lst_pt (cddr new_lst_pt))
      )
    )
  )
  (mapcar '(lambda (x y) (setvar x y))
    '("CMDECHO" "TRIMMODE" "CHAMMODE" "COMMANDPREVIEW" "PROJMODE")
    (reverse lst_var)
  )
  (prin1)
)
0 Likes
Message 12 of 25

SilentStrike24
Enthusiast
Enthusiast

Hi @CADaSchtroumpf , thank you for the time! It looks like a lot of work!

Still, i tested it and it does a chamfer, not the polyline showed in my picture.

 

SilentStrike24_1-1641057853772.png

 

Please see above @ВeekeeCZ's code. It works exactly as it should. Only thing is that it's not working when having polylines as the dependent objects. 

 

SilentStrike24_0-1641057488698.png

Thanks anyway for the work!

0 Likes
Message 13 of 25

CADaSchtroumpf
Advisor
Advisor

Did you well inform the variables 'USERR1' (for chamferC) and 'USERR2' (for chamferD) at the beginning of the procedure?

If these values ​​remain at zero, it comes back to the "chamfer" command with the "polyline" option ...

0 Likes
Message 14 of 25

Sea-Haven
Mentor
Mentor

I dont see a problem pick 1 point at intersection is it 2 lines or a single pline, for 2 lines use the circle approach. For a pline ptatdist and 1st deiriv for angle. Oh yeah pick point is actually (ssget "F" say 4 points like pickbox a small box. Then can know if 2 objects, a line/pline is ok also.

 

Next question for pline straight and then lots of segments what is "A" & "B" distance a radial or distance along from point ? The get1stderiv will allow code for draw a line at 90 from the pline point. 

0 Likes
Message 15 of 25

SilentStrike24
Enthusiast
Enthusiast

Hi @CADaSchtroumpf,

Yes, i did. Please see below picture.

Apparently, if I change variables "USERR1"/"USERR2" or not,  it still asks for a polyline and the result is the same.

 

SilentStrike24_0-1641127813353.png

 

0 Likes
Message 16 of 25

CADaSchtroumpf
Advisor
Advisor

I see in your picture:

Command; error: no function definition: VLAX-ENAME->VLA-OBJECT

I have put the function (vl-load-com) in the first line in my code, have you copied also this?

Otherwise, I don't understand the problem

 

0 Likes
Message 17 of 25

SilentStrike24
Enthusiast
Enthusiast

I may have a problem with the file needed for (vl-load-com), meaning vlcom.dll.

I'll fix it and retry your function.

0 Likes
Message 18 of 25

SilentStrike24
Enthusiast
Enthusiast

Hi @CADaSchtroumpf,

Solved the problem with that .dll. Meaning i reinstalled the software 🙄

I got rid of that error, but there's another one. Please see below picture. 

And consequently, it keeps going with chamfer/polyline, even if i change variables.

 

SilentStrike24_0-1641144604411.png

 

0 Likes
Message 19 of 25

CADaSchtroumpf
Advisor
Advisor

Can you join a exemple drawing where the function don't work's

In this case this is my code is not good 😣

Also I hace tested on 2019 version, what version you use?

0 Likes
Message 20 of 25

CADaSchtroumpf
Advisor
Advisor

I was able to reproduce the same error; when you are not in the WCS.

Try with the attached file, I think to have fixed the code.

0 Likes