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

Lisp to auto draw a specific triangle at all polyline radii

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
3rduser
842 Views, 11 Replies

Lisp to auto draw a specific triangle at all polyline radii

Hello All,

 

I am looking for a code that will automatically draw site triangles at every radius of a polyline (closed or not), the radii will also have different values every time. Right now I am drawing these all manually and I know this can be automated. I would take a crack at it myself since it really is just spawning lines at certain points but I just don't know how to get said points in a coherent sequence. The existing lines will not always exactly match the tangent of the start / end points of each radii like I have in this example, I only need the new triangle to do this. I have attached a before and after picture for what I am looking for along with a short video of how I am going about drawing these manually every time. I imagine the code would go along these lines:

 

-Evaluate polyline and identify every radius.

-Starting at the first one, identify start and end points of said radius.

-Find intersecting point of a theoretical perpendicular line coming from each point (to match tangent of said radius).

-Draw two lines each starting from intersecting point directly towards start and end of radius points with a length of 70.

-Find theoretical points on each line offset length of 10 starting from intersecting point.

-Draw 2 lines from each of these points going to the end points of each 70 line already created.

-Move on to next radius.

 

I appreciate any help!

11 REPLIES 11
Message 2 of 12
Sea-Haven
in reply to: 3rduser

If I understand pick 2 lines or 2 sides of pline joined with an arc and redraw an IP based answer with say 2 distances away from the IP point.

 

This is version 1 as there is 4 variations, Line arc line, Pline arc same pline, Line arc pline, Pline arc line. So this is line line answer, as a quick response and proof of concept.

SeaHaven_0-1716006017883.png

 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-auto-draw-a-specific-triangle-at-all-polyline-radii/td-p/12781000

(defun c:wow ( / pt1 pt2 obj1 obj2 ss1 ss2 end1 end2 start1 start2 intpt)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 512)

(setq pt1 (getpoint "\nPick side 1 "))
(setq pt2 (getpoint "\nPick side 2 "))

;(setq d1 (getdist "\nEnter distance 1 "))
;(setq d2 (getdist "\nEnter distance 2 "))
(setq d1 10 d2 70)

(setvar 'clayer "INT") ;set it to your desired layer name

(setq ss1 (ssget pt1 '((0 . "Lwpolyline,Line"))))
(setq obj1 (vlax-ename->vla-object (ssname ss1 0)))
(setq ss2 (ssget pt2 '((0 . "Lwpolyline,Line"))))
(setq obj2 (vlax-ename->vla-object (ssname ss2 0)))

(if (= (vlax-get obj1 'objectname) "AcDbLine")
  (progn
    (setq start1 (vlax-curve-getstartPoint obj1))
    (setq end1 (vlax-curve-getEndPoint obj1))
    (setq start2 (vlax-curve-getstartPoint obj2))
    (setq end2 (vlax-curve-getEndPoint obj2))
    (setq intpt (vlax-invoke obj2 'intersectwith obj1 acExtendBoth))
    (setq ang1 (angle intpt start1))
    (setq ang2 (angle intpt start2))
    (setq pt1 (polar intpt ang1 d2))
    (command "line" intpt pt1 (polar intpt ang2 d1) "")
    (setq pt2 (polar intpt ang2 d2))
    (command "line" intpt pt2 (polar intpt ang1 d1) "")
  )
  ;(
  ; pline-arc-pline
  ;)
)

(setvar 'osmode oldsnap)
(princ)
)
(c:wow)

 

 

Some one else may jump before I get chance to add more options.

 

Message 3 of 12
3rduser
in reply to: Sea-Haven

Hey thank you for the code! I appreciate the attempt at solving this, unfortunately whenever I try and use the code (after changing the layer name value) nothing happens. I have tried it on a closed polyline and an open one, see attached.

Message 4 of 12
ronjonp
in reply to: 3rduser

@3rduser 

If all your angles are 90 degrees, creating a block would speed this up.

 

There is also some code HERE to get the intersection points at each fillet.

Message 5 of 12
Sea-Haven
in reply to: 3rduser

If you read the post it only works with 2 lines at moment, as I said solution has 4 combinations. I only did one to prove concept. 

 

Post a true dwg with example of plines or lines with arcs. 

Message 6 of 12
3rduser
in reply to: 3rduser

@Sea-Haven hey sorry for misunderstanding your post. I'm still learning lisp and didn't quite get what you meant but I do now. I tried it out and the non joined line-arc-line works great. For my purposes though only one version would need to be created which is pline-arc-same pline. The line will always be joined whether closed or not. I appreciate the proof of concept.

 

I also prefer not to post dwg's since I work with company files and don't want to risk posting something confidential online, even if it's just metadata or something. This is why I try and post simple pictures / videos to show as much as I can.

 

@ronjonp thank you for the code. Also no unfortunately the angles are not always 90, they can vary quite a bit even within the same closed polyline at different corners.

Message 7 of 12
ronjonp
in reply to: 3rduser

@3rduser This should do the trick:

 

 

(defun c:foo (/ _aap _line d1 d2 l1 l2 p p2 p3 s)
  ;; RJP » 2024-05-21
  (defun _aap (e pt / p)
    (if	(and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list e))))
	     (setq p (vlax-curve-getparamatpoint e pt))
	)
      (angle '(0 0 0) (vlax-curve-getfirstderiv e p))
    )
  )
  (defun _line (p1 p2)
    (entmakex (list '(0 . "LINE") '(8 . "TRIANGLE") '(62 . 1) (cons 10 p1) (cons 11 p2)))
  )
  (cond	((setq s (ssget ":L" '((0 . "LWPOLYLINE"))))
	 (setq d1 70)
	 (setq d2 10)
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (foreach o (vlax-invoke (vlax-ename->vla-object e) 'explode)
	     (cond ((= "AcDbArc" (vla-get-objectname o))
		    (setq p3 (inters (setq p (vlax-curve-getstartpoint o))
				     (polar p (_aap o p) 1)
				     (setq p2 (vlax-curve-getendpoint o))
				     (polar p2 (_aap o p2) 1)
				     nil
			     )
		    )
		    (setq l1 (_line p3 (setq p (polar p3 (angle p3 p) d1))))
		    (setq l2 (_line p3 (setq p2 (polar p3 (angle p3 p2) d1))))
		    (_line p (vlax-curve-getpointatdist l2 d2))
		    (_line p2 (vlax-curve-getpointatdist l1 d2))
		   )
	     )
	     (vla-delete o)
	   )
	 )
	)
  )
  (princ)
)

 

 

2024-05-21_14-09-18.gif

Message 8 of 12
Sea-Haven
in reply to: 3rduser

Very nice solution, did think about make points list so end result is pline.

Message 9 of 12
ronjonp
in reply to: Sea-Haven


@Sea-Haven wrote:

Very nice solution, did think about make points list so end result is pline.


Thanks .. nice idea. This should do it 🙂

(defun c:foo (/ _aap _line d1 d2 l1 l2 l3 l4 p p2 p3 p4 p5 p6 p7 s)
  ;; RJP » 2024-05-22
  (defun _aap (e pt / p)
    (if	(and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list e))))
	     (setq p (vlax-curve-getparamatpoint e pt))
	)
      (angle '(0 0 0) (vlax-curve-getfirstderiv e p))
    )
  )
  (defun _line (p1 p2)
    (entmakex (list '(0 . "LINE") '(8 . "TRIANGLE") '(62 . 1) (cons 10 p1) (cons 11 p2)))
  )
  (cond	((setq s (ssget ":L" '((0 . "LWPOLYLINE"))))
	 (setq d1 70)
	 (setq d2 10)
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (foreach o (vlax-invoke (vlax-ename->vla-object e) 'explode)
	     (cond ((= "AcDbArc" (vla-get-objectname o))
		    (setq p3 (inters (setq p (vlax-curve-getstartpoint o))
				     (polar p (_aap o p) 1)
				     (setq p2 (vlax-curve-getendpoint o))
				     (polar p2 (_aap o p2) 1)
				     nil
			     )
		    )
		    (setq l1 (_line p3 (setq p4 (polar p3 (angle p3 p) d1))))
		    (setq l2 (_line p3 (setq p5 (polar p3 (angle p3 p2) d1))))
		    (setq l3 (_line p4 (setq p6 (vlax-curve-getpointatdist l2 d2))))
		    (setq l4 (_line p5 (setq p7 (vlax-curve-getpointatdist l1 d2))))
		    (entmakex (list '(0 . "LWPOLYLINE")
				    '(100 . "AcDbEntity")
				    '(8 . "TRIANGLE")
				    '(62 . 1)
				    '(100 . "AcDbPolyline")
				    '(90 . 5)
				    (cons 10 p7)
				    (cons 10 p5)
				    (cons 10 p3)
				    (cons 10 p4)
				    (cons 10 p6)
			      )
		    )
		    (mapcar 'entdel (list l1 l2 l3 l4))
		   )
	     )
	     (vla-delete o)
	   )
	 )
	)
  )
  (princ)
)
Message 10 of 12
Sea-Haven
in reply to: ronjonp

Nice little addition the pline.

Message 11 of 12
3rduser
in reply to: ronjonp

@ronjonp this is awesome! Thank you so much for the code and thank you @Sea-Haven again for providing the proof of concept and pline idea addition.

 

this works great, it will be very helpful. Highly impressive!!

Message 12 of 12
ronjonp
in reply to: 3rduser


@3rduser wrote:

@ronjonp this is awesome! Thank you so much for the code and thank you @Sea-Haven again for providing the proof of concept and pline idea addition.

 

this works great, it will be very helpful. Highly impressive!!


You're welcome! It should save you a bit of time 🙂

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report