User specified direction

User specified direction

Anonymous
Not applicable
952 Views
5 Replies
Message 1 of 6

User specified direction

Anonymous
Not applicable

So I have this routine that will make an elbow for duct based on user specified initial and final width and throat length, but in my code the elbow always turns right, is there a way i can make it go either way based on a user specified point?

 

; Garrett Ford 6/23/17

; The purpose of this program is to allow the user to enter a few
; dimensions and then insert and elbow with a turning vane

(defun C:bow(/ oldsnap oldlayer oldblip flag iw fw tt ip ang p1 p2 p3 p4 p5 p6)
 ;***********************************************************************
 	; Save System Variables

 	(setq oldsnap (getvar "osmode"))
 	(setq oldlayer (getvar "clayer"))
 	(setq oldblip (getvar "blipmode"))
 ;***********************************************************************
 	;Change Settings & User Input

 	(setvar "osmode" 35)
 	(setvar "blipmode" 0)
 	(setq flag (tblsearch "Layer" "LP-DUCT")) ; checks for LP-DUCT
		(if flag
			(setvar "clayer" "LP-DUCT") ; changes layer to LP-DUCT
			(alert ("No LP-DUCT Layer!")) ; if layer doesn't exist fuction terminates
		)
	(setq iw (getdist "\nWhat is the Initial Width? : "))
	(setq fw (getdist "\nWhat is the Final Width? : "))
	(setq tt (getdist "\nWhat is the Throat Length: "))
	(setq ang (getangle "\nWhat is the Angle of Rotation"))
(setq ip (getpoint "\nSelect an Insertion Point: ")) (setvar "osmode" 0) ;*********************************************************************** ; Polar Calculations (setq p1 (polar ip (+ ang (dtr 0)) (/ iw 2))) (setq p2 (polar p1 (+ ang (dtr 90)) tt)) ; Inside Corner (setq p3 (polar p2 (+ ang (dtr 0)) tt)) (setq p4 (polar p3 (+ ang (dtr 90)) fw)) (setq p5 (polar p4 (+ ang (dtr 180)) (+ tt iw))) ; Outside Corner (setq p6 (polar p5 (+ ang (dtr 270)) (+ tt fw))) ;*********************************************************************** ; Line & Insert Commands (command "Line" ip p1 p2 p3 p4 p5 p6 ip "") (setvar "osmode" oldsnap) (setvar "clayer" oldlayer) (setvar "blipmode" oldblip) ) ; End Defun ;************************************************************************ ;Converts the Degrees into Radians (defun dtr (ang) ;define degrees to radians function (* pi (/ ang 180.0)) ;divide the angle by 180 then ;multiply the result by the constant PI ) ;end of function ;************************************************************************
0 Likes
Accepted solutions (1)
953 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Try the following adjustments.  I found the "Angle of Rotation" confusing, being the direction of the second  leg.  So I changed to asking for the direction that the first leg heads from the start point, and changed the angle calculations accordingly.  It asks not for a User-specified point to determine which way to turn, but specifically whether the turn should be to the Left or Right, setting the 'bend' variable to either - or + to calculate angles in (polar) functions accordingly.  And since the angles are all parallel/perpendicular, I eliminated the use of the (dtr) function and just gave it radian angles involving pi [or not -- for instance, (+ ang (dtr 0)) is the same as just ang].

 

;;;; .... the preceding as in the original
 (setq ip (getpoint "\nSelect an Insertion Point: ")); moved [option to pick ang on-screen relative to it]
 (setq ang (getangle ip "\nWhat is the Initial Throat direction from the Insertion point?: "))
 (initget 1 "Left Right")
 (setq bend (if (= (getkword "\nBend direction [Left/Right]: ") "Right") - +))
 (setvar "osmode" 0)
;*********************************************************************** ; Polar Calculations (setq p1 (polar ip (bend ang (/ pi 2)) (/ iw 2))) (setq p2 (polar p1 ang tt)) ; Inside Corner (setq p3 (polar p2 (bend ang (/ pi 2)) tt)) (setq p4 (polar p3 ang fw)) (setq p5 (polar p4 (bend ang (- (/ pi 2))) (+ tt iw))) ; Outside Corner (setq p6 (polar p5 (+ ang pi) (+ tt fw))) ;***********************************************************************
;;;; .... the rest as in the original

Other things could be simplified in various ways, but first see whether that works for you.

Kent Cooper, AIA
Message 3 of 6

Ranjit_Singh
Advisor
Advisor

You just need to re calc your points. As @Kent1Cooper mentioned you could do it in different ways. Here is one option. One could also give an option at the end of the routine to flip the object and issue a mirror command. You can give it a try.

  ; Garrett Ford 6/23/17

  ; The purpose of this program is to allow the user to enter a few
  ; dimensions and then insert and elbow with a turning vane

(defun C:bow (/ dir oldsnap oldlayer oldblip flag iw fw tt ip ang p1 p2 p3 p4 p5 p6)
  ;***********************************************************************
  ; Save System Variables

  (setq oldsnap (getvar "osmode"))
  (setq oldlayer (getvar "clayer"))
  (setq oldblip (getvar "blipmode"))
  ;***********************************************************************
  ;Change Settings & User Input

  (setvar "osmode" 35)
  (setvar "blipmode" 0)
  (setq flag (tblsearch "Layer" "LP-DUCT")) ; checks for LP-DUCT
  (if flag
    (setvar "clayer" "LP-DUCT") ; changes layer to LP-DUCT
    (alert ("No LP-DUCT Layer!")) ; if layer doesn't exist fuction terminates
  )
  (setq iw (getdist "\nWhat is the Initial Width? : "))
  (setq fw (getdist "\nWhat is the Final Width? : "))
  (setq tt (getdist "\nWhat is the Throat Length: "))
  (setq ang (getangle "\nWhat is the Angle of Rotation"))
  (setq ip (getpoint "\nSelect an Insertion Point: "))
  (initget "Left Right")
  (setq dir (getkword "\nDirection [Left/Right]: "))
  (setvar "osmode" 0)
  ;***********************************************************************
  ; Polar Calculations
  (if (= dir "Right")
    (progn
      (setq p1 (polar ip (+ ang (dtr 0)) (/ iw 2)))
      (setq p2 (polar p1 (+ ang (dtr 90)) tt)) ; Inside Corner
      (setq p3 (polar p2 (+ ang (dtr 0)) tt))
      (setq p4 (polar p3 (+ ang (dtr 90)) fw))
      (setq p5 (polar p4 (+ ang (dtr 180)) (+ tt iw))) ;  Outside Corner
      (setq p6 (polar p5 (+ ang (dtr 270)) (+ tt fw)))
    )
    (progn (setq p1 (polar ip (+ ang (dtr 0)) (/ iw 2)))
	   (setq p2 (polar p1 (+ ang (dtr 90)) (+ fw tt))) ; Inside Corner
	   (setq p3 (polar p2 (+ ang (dtr 180)) (+ tt iw)))
	   (setq p4 (polar p3 (+ ang (dtr 270)) fw))
	   (setq p5 (polar p4 ang tt)) ;  Outside Corner
	   (setq p6 (polar p5 (+ ang (dtr 270)) tt))
    )
  )
  ;***********************************************************************
  ; Line & Insert Commands

  (command "Line" ip p1 p2 p3 p4 p5 p6 ip "")
  (setvar "osmode" oldsnap)
  (setvar "clayer" oldlayer)
  (setvar "blipmode" oldblip)
) ; End Defun
  ;************************************************************************
  ;Converts the Degrees into Radians

(defun dtr (ang) ;define degrees to radians function
  (* pi (/ ang 180.0))
  ;divide the angle by 180 then
  ;multiply the result by the constant PI
) ;end of function
  ;************************************************************************
0 Likes
Message 4 of 6

Anonymous
Not applicable

That worked beautifully (I know things could probably be simplified I just don't have the LISP knowledge to know when they could)

also the angle of Rotation is what angle the elbow will be rotated at say 20 degrees. because while the elbow is made from parallel and perpendicular lines, what I'm attaching it to might not necessarily be at 0 90 180 or 270 degrees. So I have to add that in there thus the (+ ang 0) because if the angle of rotation of the elbow is 0 then it will just be inserted at an agle 0-360 in multiples of 90, but if the rot angle is say 20 it would be on a slant

0 Likes
Message 5 of 6

Anonymous
Not applicable

Also what you did with the if statement setting bend to equal + or - was something i've never thought about before that's really cool. I didn't know you could save operators to a variable

 

Also do you want me to reference you in my code as a comment up top next to my name?

0 Likes
Message 6 of 6

Anonymous
Not applicable

Same for you would you like me to reference you in my code (previous ones you've helped me with) next to my name?

0 Likes