Author Topic: Text angle help  (Read 2274 times)

0 Members and 1 Guest are viewing this topic.

bman

  • Guest
Text angle help
« 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.

Code: [Select]
(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:

Code: [Select]
;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

whdjr

  • Guest
Text angle help
« Reply #1 on: June 16, 2005, 10:50:09 AM »
'getangle' returns the ang in radians and the command line expects to receive degrees.  You have to convert the radians to degrees.

Code: [Select]
(defun Radian->Degrees (nbrOfRadians)
  (* 180.0 (/ nbrOfRadians pi))
)

bman

  • Guest
Text angle help
« Reply #2 on: June 16, 2005, 12:17:10 PM »
Where do I insert to make the conversion happen?
Code: [Select]
(defun Radian->Degrees (nbrOfRadians)
  (* 180.0 (/ nbrOfRadians pi))
)

whdjr

  • Guest
Text angle help
« Reply #3 on: June 16, 2005, 01:04:23 PM »
Try this:
Code: [Select]
;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)

bman

  • Guest
Text angle help
« Reply #4 on: June 16, 2005, 01:30:36 PM »
Sweeeeettt!! That worked perfect. Thanks so much for your help!!!

whdjr

  • Guest
Text angle help
« Reply #5 on: June 16, 2005, 04:35:40 PM »
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

bman

  • Guest
Text angle help
« Reply #6 on: June 16, 2005, 09:42:27 PM »
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.

whdjr

  • Guest
Text angle help
« Reply #7 on: June 17, 2005, 08:29:48 AM »
I use the 'VLIDE' (Visual Lisp IDE) which is built into AutoCAD.

daron

  • Guest
Text angle help
« Reply #8 on: June 17, 2005, 10:47:36 AM »
Aren't radians just 1-4, as in a radian of 1 = 90 degrees North, or is that too simple?

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Text angle help
« Reply #9 on: June 17, 2005, 01:22:27 PM »
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........

CADaver

  • Guest
Text angle help
« Reply #10 on: June 17, 2005, 04:28:40 PM »
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

daron

  • Guest
Text angle help
« Reply #11 on: June 17, 2005, 04:42:58 PM »
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.