Author Topic: Need help with a routine...  (Read 2784 times)

0 Members and 1 Guest are viewing this topic.

bman

  • Guest
Need help with a routine...
« on: December 29, 2004, 02:47:03 PM »
The code below calculates a lower invert elevation by:
1. prompting user to select the upper text entity with a numeric value
2. prompt user to select points to get length
3. prompt user to input slope for calculating lower invert.

Here's the question....how can I modify the routine to give the user an option  to either input a value at the command or by selecting a text entity with a numeric value as it currently does?

     
Code: [Select]
(defun c:inv (/ txt1 ent1 txt2 txt3 ent2 txt4 txts ang1 txtend conv oldsnap clay)
(setq oldsnap (getvar "osmode"))
(setq clay (getvar "clayer"))
(setq txt1 (entsel "\nSelect starting elevation: "))
(if txt1
(progn
(setq ent1 (makex (car txt1)))
(setq txt2 (getx ent1 'TextString))
(setq txt3 (atof txt2))
(prompt "\nSelect point: ")
(setvar "osmode" 36)
(command "_.pline")
(while (> (getvar "cmdactive") 0)
(command pause)
)
(setq ent2 (makex (entlast)))
(setq txt4 (getx ent2 'Length))
(initget 1)
(setq txts (getreal "\nEnter slope (in percentage): "))
(setq ang1
(rtd
(angle
(getpoint "\nSelect start point of for angle (going left to right). ")
(getpoint "\nSelect end point of angle. ")
)
)
)
;;;(setvar "osmode" 512)
(prompt "\nSelect insertion point of slope text: ")
(if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
(command "_text" "j" "bc" pause ang1 (strcat(rtos txts 2 2)"%"))
(command "_text" "j" "bc" pause "" ang1 (strcat(rtos txts 2 2)"%"))
)
(setq conv (/ txts 100))
(setq txtend (+ (* conv txt4) txt3))
(prompt "\nSelect insertion point of ending elevation text: ")
(if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
(command "_text" "j" "mc" pause "0" (rtos txtend 2 2))
(command "_text" "j" "mc" pause "" "0" (rtos txtend 2 2))
)
)
)
)


(defun MakeX (entname)
(vlax-ename->vla-object entname)
)

(defun GetX (object prop)
(vlax-get object prop)
)

(defun RTD (a) ;Radians to degrees conversion
(* 180.0 (/ a pi)))

BAshworth

  • Guest
Need help with a routine...
« Reply #1 on: December 29, 2004, 04:07:32 PM »
Easiest way I could think of, would be to prompt for the text value first, with an option of entering in a letter to start the entsel routine.

Ex...

(setq UsrVal (getstring "\nEnter Value or [Select]:"))

Check the value after they enter it.  If it's "S" then go to the selection portion, otherwise, convert the typed value to a real, and continue on.

bman

  • Guest
Need help with a routine...
« Reply #2 on: December 29, 2004, 05:19:45 PM »
What syntax do i use to check the value subsequent of the getstring line?

BAshworth

  • Guest
Need help with a routine...
« Reply #3 on: December 29, 2004, 05:49:55 PM »
You would use an IF statement.

(if = UsrVal "S"
          (progn
               (setq UsrVal (atof UsrVal))
           ); end progn
;else
           (progn
                (.       <--- your code to select on the screen goes here.

Anonymous

  • Guest
Need help with a routine...
« Reply #4 on: December 29, 2004, 07:43:25 PM »
thanks BAshworth, i'll give it a try.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need help with a routine...
« Reply #5 on: December 30, 2004, 12:42:56 AM »
bman
Try this:
Code: [Select]
(defun get_num ()
  (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
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bman

  • Guest
Need help with a routine...
« Reply #6 on: December 30, 2004, 09:05:08 AM »
cab, what am i doing wrong?

Code: [Select]
;INV = Calcs & lbls inverts by picking points

(defun c:inv (/ txt1 ent1 txt2 txt3 ent2 txt4 txts ang1 txtend conv oldsnap clay)
(setq oldsnap (getvar "osmode"))
(setq clay (getvar "clayer"))
;;;(setq txt1 (entsel "\nSelect starting elevation: "))
;;;(if txt1
;;;(progn
;;;(setq ent1 (makex (car txt1)))
;;;(setq txt2 (getx ent1 'TextString))
;;;(setq txt3 (atof txt2))
;;;(prompt "\nSelect point: ")
;;;(setvar "osmode" 36)
(defun get_num ()
  (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
)
(command "_.pline")
(while (> (getvar "cmdactive") 0)
(command pause)
)
(setq ent2 (makex (entlast)))
(setq txt4 (getx ent2 'Length))
(initget 1)
(setq txts (getreal "\nEnter slope (in percentage): "))
(setq ang1
(rtd
(angle
(getpoint "\nSelect start point of for angle (going left to right). ")
(getpoint "\nSelect end point of angle. ")
)
)
)
;;;(setvar "osmode" 512)
(prompt "\nSelect insertion point of slope text: ")
(if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
(command "_text" "j" "bc" pause ang1 (strcat(rtos txts 2 2)"%"))
(command "_text" "j" "bc" pause "" ang1 (strcat(rtos txts 2 2)"%"))
)
(setq conv (/ txts 100))
(setq txtend (+ (* conv txt4) txt3))
(prompt "\nSelect insertion point of ending elevation text: ")
(if (>(cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))0)
(command "_text" "j" "mc" pause "0" (rtos txtend 2 2))
(command "_text" "j" "mc" pause "" "0" (rtos txtend 2 2))
)
)
)
)


(defun MakeX (entname)
(vlax-ename->vla-object entname)
)

(defun GetX (object prop)
(vlax-get object prop)
)

(defun RTD (a) ;Radians to degrees conversion
(* 180.0 (/ a pi)))

TR

  • Guest
Need help with a routine...
« Reply #7 on: December 30, 2004, 09:15:50 AM »
You can nest functions like that in lisp?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Need help with a routine...
« Reply #8 on: December 30, 2004, 10:27:06 AM »
bman,
The routine needs more work & error checking but this seems to work.
Code: [Select]
(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: "))
  ;;(setvar "osmode" 512)
  (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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

bman

  • Guest
Need help with a routine...
« Reply #9 on: December 30, 2004, 11:17:02 AM »
thanks cab....works for me :D