Author Topic: On a bias..  (Read 4172 times)

0 Members and 1 Guest are viewing this topic.

Water Bear

  • Guest
On a bias..
« on: January 07, 2004, 10:24:00 AM »
Can anyone see why this routine prints what I want, but I can't seem to justify the text
Code: [Select]
(defun elvcalc ()
  (setq oldunits (getvar "lunits"))
  (setvar "lunits" 5)
  (setq #wid1  (getreal "\nEnter duct WIDTH: ")
#dep1  (getreal "\nEnter duct DEPTH: ")
#bod   (getstring "\nEnter BOTTOM elevation: ")

#conn1 (strcat "\n" (rtos #wid1) " X " (rtos #dep1))
)
  ;;convert elev from string to REAL calc top & bot elev

  (setq #bod (distof #bod 4))

  ;;calc top & center elev using REALS
  (setq #tod (+ #bod #dep1)
#cod (+ #bod (/ #dep1 2))
)

  ;;convert REALS back to strings, add plus signs(will only be used in tags, not for calc)
  (setq #tod (strcat "\nT+ " (rtos #tod 4 2))
#cod (strcat "\nC+ " (rtos #cod 4 2))
#bod (strcat "\nB+ " (rtos #bod 4 2))
)
  (setq elv_text (strcat #conn1 #tod #cod #bod))
  (princ #tod)
  (princ #cod)
  (princ #bod)
  (princ #conn1)
  (setq elvpnt (getpoint "\nSelect point to insert Elevation text:  "))
  (if (null (tblsearch "style" "duc_el"))
    (command "style" "duct_el" "romans" "2" "" "20" "" "" "")
    )
  (command "layer" "m" "SM-Duct Elevations" "c" "4" "" "")
  (command "text" "s" "duct_el" "bl" elvpnt 0 elv_text)
  (setvar "lunits" oldunits)
  (princ)
  ) ;end defun
(princ)

SMadsen

  • Guest
On a bias..
« Reply #1 on: January 08, 2004, 06:47:27 AM »
I wonder if anyone ever intended for text to contain newline characters. At least it seems to be the standard behavior to indent the new lines of text and I don't think there's a way to change the feature. Could be terribly wrong on that, though!

Why don't you use MTEXT instead (insert /P codes for newline instead of \n)? Or maybe multiple lines of TEXT?

Just a side note: Beware of the variable #conn1 in your code. It seems to be a global that might happened to be assigned by luck during your test runs.

Anonymous

  • Guest
mtext
« Reply #2 on: January 08, 2004, 10:52:25 AM »
Thanks Smadsen...I'd actually been trying that before your post. I changed it to this:
Code: [Select]
(command "-mtext" pause "r" (rtd #trav) pause #conn1 #tod #cod #bod "")But I think I'm using an improper syntax because although it accomplishes the task...the menuecho doesn't look right

deegeecees

  • Guest
On a bias..
« Reply #3 on: January 08, 2004, 11:03:05 AM »
Try echoing, then inserting the pcodes.

SMadsen

  • Guest
On a bias..
« Reply #4 on: January 08, 2004, 11:30:25 AM »
Water Bear,
How about constructing the text before you call the MTEXT command. To determine the size of the text box, you can use TEXTBOX like shown below and try to fit it with some approximate factors. Here I've just used 1.5 times the width and six times the height. You can change it to whatever you think is appropriate but asking the user for anything but the insertion point isn't fair, I think.

Code: [Select]
(defun elvcalc (/ #bod #cod #conn1 #dep1 #tod #wid1 elvpnt elv_text oldunits txtbox)
  (setq oldunits (getvar "lunits"))
  (setvar "lunits" 5)
  (setq #wid1 (getreal "\nEnter duct WIDTH: ")
        #dep1 (getreal "\nEnter duct DEPTH: ")
        ;;changed this to GETREAL (just for the heck of it)
        #bod  (getreal "\nEnter BOTTOM elevation: ")
  )
  ;;convert elev from string to REAL calc top & bot elev
  ;;(setq #bod (distof #bod 4))

  ;;added some error stuff (just for the heck of it):
  (cond
    ((apply 'and (mapcar 'numberp (list #wid1 #dep1 #bod)))
     (setq #conn1 (strcat (rtos #wid1) " X " (rtos #dep1)))

     ;;calc top & center elev using REALS
     (setq #tod (+ #bod #dep1)
           #cod (+ #bod (/ #dep1 2))
     )

     ;;convert REALS back to strings, add plus signs(will only be used in tags, not for calc)
     (setq #tod (strcat "T+ " (rtos #tod 4 2))
           #cod (strcat "C+ " (rtos #cod 4 2))
           #bod (strcat "B+ " (rtos #bod 4 2))
     )
     (setq elv_text (strcat #conn1 "\\P" #tod "\\P" #cod "\\P" #bod))
     (setq txtbox (textbox (list (cons 1 elv_text))))
     (princ #tod)
     (princ #cod)
     (princ #bod)
     (princ #conn1)
     ;;added some extra reassuring (just for .. of it)
     (cond
       ((and txtbox (setq elvpnt (getpoint "\nSelect point to insert Elevation text:  ")))
        (if (null (tblsearch "style" "duc_el"))
          (command "style" "duct_el" "romans" "2" "" "20" "" "" "")
        )
        (command "layer" "m" "SM-Duct Elevations" "c" "4" "" "")

        (command "-mtext"
                 elvpnt
                 (list (+ (car elvpnt) (* 1.5 (- (caadr txtbox) (caar txtbox))))
                       (+ (cadr elvpnt) (* 6.0 (- (cadadr txtbox)) (cadar txtbox)))
                       (caddr elvpnt)
                 )
                 elv_text
                 ""
        )
       )
     )
    )
  )
  (setvar "lunits" oldunits)
  (princ)
) ;_ end defun

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
On a bias..
« Reply #5 on: January 08, 2004, 11:32:59 AM »
Try this :

Code: [Select]
(defun elvcalc ()
  (setq oldunits (getvar "lunits"))
  (setvar "lunits" 5)
  (setq   #wid1  (getreal "\nEnter duct WIDTH: ")
   #dep1  (getreal "\nEnter duct DEPTH: ")
   #bod   (getstring "\nEnter BOTTOM elevation: ")

   #conn1 (strcat "\n" (rtos #wid1) " X " (rtos #dep1))
   )
  ;;convert elev from string to REAL calc top & bot elev

  (setq #bod (distof #bod 4))

  ;;calc top & center elev using REALS
  (setq   #tod (+ #bod #dep1)
   #cod (+ #bod (/ #dep1 2))
   )

  ;;convert REALS back to strings, add plus signs(will only be used in tags, not for calc)
  (setq   #tod (strcat "\nT+ " (rtos #tod 4 2))
   #cod (strcat "\nC+ " (rtos #cod 4 2))
   #bod (strcat "\nB+ " (rtos #bod 4 2))
   )
  (setq elv_text (strcat #conn1 #tod #cod #bod))
  (princ #tod)
  (princ #cod)
  (princ #bod)
  (princ #conn1)
  (setq elvpnt (getpoint "\nSelect point to insert Elevation text:  "))
  (if elvpnt ; make 2D point
    (setq elvpnt (list (car elvpnt) (cadr elvpnt)))
  )
  (if (null (tblsearch "style" "duc_el"))
    (command "style" "duct_el" "romans" "2" "" "20" "" "" "")
    )
  (command "layer" "m" "SM-Duct Elevations" "c" "4" "" "")
  (command "-mtext" elvpnt "s" "duct_el" "W" 0  #conn1 #tod #cod #bod "")
  (setvar "lunits" oldunits)
  (princ)
  )               ;end defun
(princ)
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.

Water Bear

  • Guest
eagle ayes...
« Reply #6 on: January 08, 2004, 07:31:07 PM »
thanks for the help...
And you were right about that global #conn1...!