Lisp For Automatic Change the Angle

Lisp For Automatic Change the Angle

ishaq03
Advocate Advocate
5,198 Views
20 Replies
Message 1 of 21

Lisp For Automatic Change the Angle

ishaq03
Advocate
Advocate

I want to provide the angles for Pipes as per my corridor route. But I am looking a command which automatically change the angles while I am Creating the polyline. I have a 11.25,22.5,45,&90 Angles for pipes in my project. Please check my dwg for better understanding.

0 Likes
Accepted solutions (2)
5,199 Views
20 Replies
Replies (20)
Message 2 of 21

hak_vz
Advisor
Advisor

@ishaq03 

Do you pick points along inclined line or you have defined pipe segments lengths?

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 21

ishaq03
Advocate
Advocate

I have pick points along inclined line

0 Likes
Message 4 of 21

hak_vz
Advisor
Advisor

If you don't have defined lengths of segments, I can not help.  I've tried to make a lisp to use only your defined angles and lengths along a segment, but if you have to pick a point by mouse my method won't work. Try to play with polar tracking <F10>. Add your angles to additional angles list, and  select polar tracking measurement relative to last segment.

My idea was to create set of xlines at the end of each segment when you pick point that is rotated relative to that segment. You would pick a point along a desired xline and provide a segment distance. At each next point previous xlines are erased. If that can help, I'll work when I catch some free time. Hopefully someone will come up with better solution. 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 21

CADaSchtroumpf
Advisor
Advisor

Perhaps this?

(defun errlsp (ch)
  (cond
    ((eq ch "Function cancelled") nil)
    ((eq ch "quit / exit abort") nil)
    ((eq ch "console break") nil)
    (T (princ ch))
  )
  (setvar "CMDECHO" v1)
  (setvar "ORTHOMODE" v2)
  (setvar "OSMODE" v3)
  (setvar "SNAPANG" v5)
  (setq *error* olderr)
  (princ)
)
(defun C:PL_with_angle ( / v1 v2 v3 v4 olderr p_o p_n ang alpha)
  (setq v1 (getvar "CMDECHO")
        v2 (getvar "ORTHOMODE")
        v3 (getvar "OSMODE")
        v4 (getvar "SNAPANG")
  )
  (setvar "CMDECHO" 1)
  (setvar "USERR1" 90.0)
  (setq olderr *error* *error* errlsp)
  (initget 8)
  (setq p_o (getpoint "\nFirst point of polyline: "))
  (initget 8)
  (setq p_n (getpoint p_o "\nNext point of polyline: "))
  (command "_.pline" p_o p_n)
  (setq ang (angle p_o p_n))
  (setvar "SNAPANG" ang)
  (setvar "ORTHOMODE" 1)
  (while (not (zerop (getvar "CMDACTIVE")))
    (initget "11.25 22.5 45.0 90.0")
    (setq alpha (getkword (strcat "\nEnter next value of angle [11.25/22.5/45.0/90.0]<" (rtos (getvar "USERR1")) ">: ")))
    (if alpha (setvar "USERR1" (atof alpha)))
    (if (or (eq (getvar "USERR1") 11.25) (eq (getvar "USERR1") 22.5))
      (progn
        (initget "Clockwise Anti-clockwise")
        (if (eq (getkword "\n[Clockwise/Anti-clockwise]?<Clockwise>: ") "Anti-clockwise")
          (setq alpha (/ (* (getvar "USERR1") pi) 180))
          (setq alpha (/ (* (- (getvar "USERR1")) pi) 180))
        )
      )
      (setq alpha (/ (* (getvar "USERR1") pi) 180))
    )
    (setvar "SNAPANG" (+ (getvar "SNAPANG") alpha))
    (command pause)
  )
  (setvar "CMDECHO" v1)
  (setvar "ORTHOMODE" v2)
  (setvar "OSMODE" v3)
  (setvar "SNAPANG" v4)
  (setq *error* olderr)
  (prin1)
)

 

With 11.25 or 22.5, you must indicate the clockwise or anti-clockwise for have a good angle.

The options are disponibles with the rigth click

0 Likes
Message 6 of 21

Sea-Haven
Mentor
Mentor

It would appear to me that you would do 2pts at a time so draw 1st segment, pick next pt, compare the angles of the last segment and the new segment if close to say 45 then draw a 45 line using line length. It would just need a cond a little tricky as you have negative angles. No code an idea will have  a think. 

 

22.5 = 0.3927 rads
45.0 = 0.7854 rads
67.5 = 1.1781 rads
90.0 = 1.5708 rads

Then the large angle for go CC.

 

A bit of code to just show angle as draw lines, final code would be a pline. 

(defun c:wow ()
(setq pt1 (getpoint "\npt1"))
(setq pt2 (getpoint pt1 "\npt2"))
(princ (strcat "\n" (rtos (angle pt1 pt2) 2 3)))
(command "line" pt1 pt2 "")
(setq pt1 pt2)
(while (setq pt2 (getpoint pt1 "\npt2"))
(princ (strcat "\n" (rtos (angle pt1 pt2) 2 3)))
(command "line" pt1 pt2 "")
(setq pt1 pt2)
)
(princ)
)

 

0 Likes
Message 7 of 21

Sea-Haven
Mentor
Mentor

Try this appears to be working. Auto to steps of  22.5 bends. 

;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-automatic-change-the-angle/td-p/10632287

; DRAW LINES AT FIXED ANGLES 
; vER 1 BY ALANH SEP 2021 info@alanh.com.au

(defun AH:chkang ( / )
(cond 
((> angl (* step 15.0))(setq angl 0.0))
((> angl (* step 14.0))(setq angL (* 15.0 step)))
((> angl (* step 13.0))(setq angL (* 14.0 step)))
((> angl (* step 12.0))(setq angL (* 13.0 step)))
((> angl (* step 11.0))(setq angL (* 12.0 step)))
((> angl (* step 10.0))(setq angL (* 11.0 step)))
((> angl (* step 9.0))(setq angL (* 10.0 step)))
((> angl (* step 8.0))(setq angL (* 9.0 step)))
((> angl (* step 7.0))(setq angL (* 8.0 step)))
((> angl (* step 6.0))(setq angL (* 7.0 step)))
((> angl (* step 5.0))(setq angL (* 6.0 step)))
((> angl (* step 4.0))(setq angL (* 5.0 step)))
((> angl (* step 3.0))(setq angL (* 4.0 step)))
((> angl (* step 2.0))(setq angL (* 3.0 step)))
((> angl (* step 1.0))(setq angL (* 2.0 step)))
((< angl (/ pi 16) )(setq angl 0.0))
)
(setq pt2 (polar pt1 angL dist))
(command "line" pt1 pt2 "")
(princ)
)

(defun c:wow ( / angL step pt1 pt2 dist )
(setq ang (/ pi 16.0) step (/ pi 8.0))
(setq pt1 (getpoint "\npick pt1"))
(setq pt2 (getpoint pt1 "\npick next pt2"))
(princ (strcat "\n" (rtos (angle pt1 pt2) 2 3)))
(setq angL (angle pt1 pt2) dist (distance pt1 pt2))
(princ (strcat "\n" (rtos angL 2 3)))
(aH:chkang)
(setq pt1 pt2)
(while (setq pt2 (getpoint pt1 "\npick next pt2 Enter to exit"))
(setq angL (angle pt1 pt2) dist (distance pt1 pt2))
(princ (strcat "\n" (rtos angL 2 3)))
(aH:chkang)
(setq pt1 pt2)
)
(princ)
)

 

0 Likes
Message 8 of 21

Kent1Cooper
Consultant
Consultant

@ishaq03 wrote:

.... But I am looking a command which automatically change the angles while I am Creating the polyline. I have a 11.25,22.5,45,&90 Angles for pipes in my project. ....


And 60.  Any others?  Should zero [continue in the same direction as the last section] be included?  Presumably directions can bend in either direction?  And the limited angles are not absolute angles but relative to the previous segment [amounts of bend], correct?

 

Describe what you imagine being the process.  You call the command, and pick a starting point, and presumably a second point not limited in angle [since the end segments in the sample drawing are not at any of your specified angles], and --- then what happens?  The rubber-band line for the next point pops to only those limited amounts of bend from the previous segment?  Or do you answer a prompt for the angle of bend, as in @CADaSchtroumpf 's suggestion?  When you pick another point, it uses the distance from the previous one, but locked in angle to the closest of the limited direction-change angles?  Do you imagine the option to type in a distance rather than pick a point, as with ortho or polar mode in regular drawing?  Something else I haven't thought of?

Kent Cooper, AIA
0 Likes
Message 9 of 21

ishaq03
Advocate
Advocate

CADaSchtroump 

Your command is working fine as per my need. But I would like  to request you add the 60.00° angle and check the attached my image file where I marked the curser, After assign the angles curser position is rotating. so how can I change curser to normal position.

0 Likes
Message 10 of 21

CADaSchtroumpf
Advisor
Advisor
Accepted solution

I added the 60 ° option but also the 'Exit' option to exit the function properly.
Indeed before it was necessary to validate several blank faiths to exit cleanly and find the variables in the initial state.
So now the cursor will find its orientation at the end of the command because it follows the SNAPANG variable.
Note: It is possible to provide the precise distance by entering a value when the elastic cursor is in the right direction.

0 Likes
Message 11 of 21

hak_vz
Advisor
Advisor
Accepted solution

@ishaq03   Here is my code that don't require selection angles through keyboard entries.

 

After you create first segments, at each next point a fan of colored helping lines appears inclined to desired angles relative to previous polyline segment. To pick point at desired angle assure you have osnap mode NEAREST turned on.

You can either pick a point along desired inclined line or place a cursor over desired line so that symbol of nearest is active and enter distance to next point. To exit hit <enter>

Untitled.png

(defun c:inc_pline ( / *error*  adoc pt deg_to_rad make_helplines elist base_angles_list pa pb pe po ptlist coords)
	;Author:  hak_vz 
	;Monday, September 20, 2021
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Posted at 
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-automatic-change-the-angle/td-p/10632287
	;Creates lwpolyline with inclined angles 11.25 22.5 45 60 and 90 degree relative to previous segment
	;Important: Assure you have osnap mode NEAREST turned on to enable drawing along helper line 
	(vl-load-com)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if elist (foreach e elist (entdel e)))
		(setq elist nil)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ)
	)
	(defun deg_to_rad (deg)(* pi (/ deg 180.0)))
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun make_helplines (p1 ptlist / clist i p2)
		(setq clist '(1 3 5 6 30 1 3 5 6 30))
		(if elist (foreach e elist (entdel e)))
		(progn
			(setq elist nil i -1)
			(while (< (setq i (1+ i)) (length ptlist))
				(setq p2 (nth i ptlist))
				(setq elist 
					(cons
						(entmakex
							(list
								(cons 0 "LINE")
								(cons 100 "AcDbEntity")
								(cons 100 "AcDbLine")
								(cons 10 (trans p1 1 0))
								(cons 11 (trans (polar p1 (angle p1 p2) 10000) 1 0))
								(cons 62 (nth i clist))
							)
						)
						elist
					)
				)			
			)
		)
	)
	(setq adoc (vla-get-activedocument (vlax-get-acad-object)))
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(setq base_angles_list (mapcar 'deg_to_rad '(11.25 22.5 45 60 90 -11.25 -22.5 -45 -60 -90)))
	(princ "\nHave you tourned on osnap mode NEAREST? If not, turn it on and start again!")
	(princ "\nTo exit function hit <enter>!")
	(setq pa (getpoint "\nFirst point of polyline: "))
	(setq pb (getpoint pa "\nNext point of polyline: "))
	(setvar 'cmdecho 0)
	(command "_.pline" pa pb "")
	(setq pe (entlast) po (vlax-ename->vla-object pe))
	(setq coords (append (take 2 pa) (take 2 pb)))
	(setq ptlist nil)
	(foreach e base_angles_list (setq ptlist (cons (polar pb (- (angle pa pb) e) 10) ptlist)))
	(make_helplines pb ptlist)
	(setq ptlist nil)
	(while (setq pt (getpoint "\nNext point >"))
		(setq pa pb pb pt)
		(foreach e base_angles_list (setq ptlist (cons (polar pb (- (angle pa pb) e) 10) ptlist)))
		(make_helplines pb ptlist)
		(setq ptlist nil)
		(command "_.pline" pa pb "")
		(setq coords (append coords (take 2 pb)))
		(vlax-put po 'Coordinates coords)
		(entdel (entlast))
	)
	(if elist (foreach e elist (entdel e)))
	(setq elist nil)
	(vla-endundomark adoc)
	(setvar 'cmdecho 1)
	(princ "\nDone!")
	(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 12 of 21

diagodose2009
Collaborator
Collaborator

snapshot.gif

You   exeute the programe ":minidump\asm_jc_lda18.lsp" with 

You select "1"  at install_fedora(1.yes)(0.no)"

 

You appload the "pp_cadaschtroumpf_makepline_.lsp"

You enter the command C:q2[enter]

 

 

 

0 Likes
Message 13 of 21

Sea-Haven
Mentor
Mentor

Very nice like the guide lines idea. 

0 Likes
Message 14 of 21

ishaq03
Advocate
Advocate

 

 
 

  Thanks it's working fine as per my need.

0 Likes
Message 15 of 21

ishaq03
Advocate
Advocate

hak_vz

Your Code also Awesome sir, Thanks It's great help me when I designed any pressure network. 

Message 16 of 21

ishaq.syed7CX2A
Enthusiast
Enthusiast

@hak_vz 

Thanks, your command is working fine, but I would like to ask, can we add the vertical bend angles, meaning above and below, of 11.25, 22.5, 45, 60, and 90 degree For your understanding, I am attaching the sample photo on the bottom.

 

ishaqsyed7CX2A_0-1680394308536.png

 

0 Likes
Message 17 of 21

Sea-Haven
Mentor
Mentor

This may be better answered by some one using Autodesk Plant which draws pipes.

0 Likes
Message 18 of 21

hak_vz
Advisor
Advisor

@ishaq.syed7CX2A wrote:

@hak_vz 

Thanks, your command is working fine, but I would like to ask, can we add the vertical bend angles, meaning above and below, of 11.25, 22.5, 45, 60, and 90 degree.

 


You can add any angle you want by simply changing angles in list:

(setq base_angles_list (mapcar 'deg_to_rad '(11.25 22.5 45 60 90 -11.25 -22.5 -45 -60 -90)))

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 19 of 21

ishaq.syed7CX2A
Enthusiast
Enthusiast

@hak_vz 

 

I'm sorry, but I don't understand what you're trying to communicate. Could we include this code in the list you've supplied here? Prior to that, if that's the case, kindly add this code and send here.

0 Likes
Message 20 of 21

ishaq03
Advocate
Advocate

@hieveryone, @hak,

 

👉Is it possible to update or enhance this command so that it supports different horizontal and vertical scales?
For example, as shown in the attached screenshot, I want the horizontal scale to remain 1:1000 and the vertical scale to be 1:10. This would allow vertical exaggeration to be applied directly while drafting, similar to how we view profiles in Civil 3D.

This adjustment would make the command more practical for profile drafting and design workflows.

Thank you in advance for your guidance! I attached the lisp previously provided by @hak_vz .

 

 

 

ishaq03_0-1755447548685.png

 

0 Likes