TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: bman on June 16, 2005, 10:39:19 AM
-
What's wrong with the following....when I pick an insertion point for the slope label it's not taking the angle I picked.
(setq ang (getangle "\nPick text angle: "))
(prompt "\nSelect insertion point of slope text: ")
(if (> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "_text" "j" "bc" pause ang (strcat (rtos slope 2 2) "%"))
(command "_text" "j" "bc" pause "" ang (strcat (rtos slope 2 2) "%"))
)
Here's the entire routine:
;INV = Calcs & lbls inverts by picking points
(defun c:inv (/ elev run slope ang end_elev conv oldsnap clay)
(defun get_num (/ num elst ent)
(while (not
(cond
((setq num (getreal "\n*** Enter a starting elevation: <Enter to pick text>"))
num
)
((setq ent (entsel "\n>>--> Select starting elevation: <Enter to type number>"))
(setq elst (entget (car ent)))
(if (= (cdr (assoc 0 elst)) "TEXT")
(if (> (setq num (atof (cdr (assoc 1 elst)))) 0)
num
)
)
)
)
)
)
num
)
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq oldsnap (getvar "osmode"))
(setq clay (getvar "clayer"))
(setq elev (get_num))
(prompt "\nSelect point: ")
(setvar "osmode" 36)
(command "_.pline")
(while (> (getvar "cmdactive") 0)
(command pause)
)
(setq run (entlen (entlast)))
(initget 1)
(setq slope (getreal "\nEnter slope (in percentage): "))
(initget 1)
>>>>>(setq ang (getangle "\nPick text angle: "))
>>>>> (prompt "\nSelect insertion point of slope text: ")
>>>>>(if (> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
>>>>> (command "_text" "j" "bc" pause ang (strcat (rtos slope 2 2) "%"))
>>>>>(command "_text" "j" "bc" pause "" ang (strcat (rtos slope 2 2) "%"))
)
(setq conv (/ slope 100))
(setq end_elev (+ (* conv run) elev))
(prompt "\nSelect insertion point of ending elevation text: ")
(if (> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "_text" "j" "mc" pause "0" (rtos end_elev 2 2))
(command "_text" "j" "mc" pause "" "0" (rtos end_elev 2 2))
)
(setvar "CMDECHO" usercmd)
(princ)
)
(prompt "nInvert Loaded, enter INV to run.")
(princ)
(defun getx (object prop)
(if (= (type object) 'ename)
(setq object (vlax-ename->vla-object object))
)
(vlax-get object prop)
)
(defun entlen (obj)
(if (= (type obj) 'ename)
(setq obj (vlax-ename->vla-object obj))
)
(vlax-curve-getdistatparam
obj
(vlax-curve-getendparam obj)
) ;_ vlax-curve-getDistAtParam
) ;_ defun
-
'getangle' returns the ang in radians and the command line expects to receive degrees. You have to convert the radians to degrees.
(defun Radian->Degrees (nbrOfRadians)
(* 180.0 (/ nbrOfRadians pi))
)
-
Where do I insert to make the conversion happen?
(defun Radian->Degrees (nbrOfRadians)
(* 180.0 (/ nbrOfRadians pi))
)
-
Try this:
;INV = Calcs & lbls inverts by picking points
(defun c:inv (/ elev run slope ang end_elev conv oldsnap clay)
(defun get_num (/ num elst ent)
(while
(not (cond ((setq num
(getreal
"\n*** Enter a starting elevation: <Enter to pick text>"
)
)
num
)
((setq ent
(entsel
"\n>>--> Select starting elevation: <Enter to type number>"
)
)
(setq elst (entget (car ent)))
(if (= (cdr (assoc 0 elst)) "TEXT")
(if (> (setq num (atof (cdr (assoc 1 elst)))) 0)
num
)
)
)
)
)
)
num
)
;;;
(defun getx (object prop)
(if (= (type object) 'ename)
(setq object (vlax-ename->vla-object object))
)
(vlax-get object prop)
)
;;;
(defun entlen (obj)
(if (= (type obj) 'ename)
(setq obj (vlax-ename->vla-object obj))
)
(vlax-curve-getdistatparam obj (vlax-curve-getendparam obj))
)
;;;
(defun Radian->Degrees (nbrOfRadians) (* 180.0 (/ nbrOfRadians pi)))
;;;
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq oldsnap (getvar "osmode"))
(setq clay (getvar "clayer"))
(setq elev (get_num))
(prompt "\nSelect point: ")
(setvar "osmode" 36)
(command "_.pline")
(while (> (getvar "cmdactive") 0) (command pause))
(setq run (entlen (entlast)))
(initget 1)
(setq slope (getreal "\nEnter slope (in percentage): "))
(initget 1)
(setq ang (Radian->Degrees (getangle "\nPick text angle: ")))
(prompt "\nSelect insertion point of slope text: ")
(if (> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "_text" "j" "bc" pause ang (strcat (rtos slope 2 2) "%"))
(command "_text"
"j"
"bc"
pause
""
ang
(strcat (rtos slope 2 2) "%")
)
)
(setq conv (/ slope 100))
(setq end_elev (+ (* conv run) elev))
(prompt "\nSelect insertion point of ending elevation text: ")
(if (> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "_text" "j" "mc" pause "0" (rtos end_elev 2 2))
(command "_text" "j" "mc" pause "" "0" (rtos end_elev 2 2))
)
(setvar "CMDECHO" usercmd)
(princ)
)
(prompt "nInvert Loaded, enter INV to run.")
(princ)
-
Sweeeeettt!! That worked perfect. Thanks so much for your help!!!
-
hmm...that took about
5 seconds to find the function
+
4 seconds to recode
+
3 seconds to post the code
=
$100.00 dollars in my pocket from you.
:lol:
no really, I'm glad to help. :D
-
I'm no programmer I must admit...I know how to setup short commands & that's the extent of my programming capabilities. What program do you use to write & check these routines for errors?
Thanks again for your help.
-
I use the 'VLIDE' (Visual Lisp IDE) which is built into AutoCAD.
-
Aren't radians just 1-4, as in a radian of 1 = 90 degrees North, or is that too simple?
-
That's too simple, sorry. Half a circle (180 degrees) is pi Radians, so a circle is 2pi radians, 90 degrees is pi/2 radians, etc........
-
One radian is the angle of an arc created by wrapping the radius of a circle around its circumference.
The radius 'r' fits around the circumference of a circle exactly 2p times. That is why the circumference of a circle is given by:
circumference = 2(pi)r
So there are 2(pi) radians in a complete circle, and pi radians in a half circle.
http://id.mind.net/~zona/mmts/trigonometryRealms/radianDemo1/RadianDemo1.html
http://www.teacherschoice.com.au/Maths_Library/Angles/Angles.htm
http://math.rice.edu/~pcmi/sphere/drg_txt.html
-
hehe. I've really got to get back into math. I was looking at placement exams online today; hoooo, those aren't pretty. There was one that looked like an ampersand over the square root of 10. No idea how to figure that one out. I think I'll be taking some refresher courses before I can get up to college level math.