Jump to content

Removing Decimals in an existing routine.


tmelancon

Recommended Posts

Hello all. I have a routine that enters data labels in a drawing where the user would like them. It finds data in a file and inserts it based on the label number the user inputs. However, for the data labels that we enter that have no information, but the user still wants that label called out, it simply enters "#50.00-0.00". I was able to remove the "0.00" suffix because it was obvious in the code. But I would also like to remove ".00" immediately after the data label, and this isnt working out in my favor. The only thing that I would like displayed is "#50-". No decimals and no zeros.

 

I have included the routine. and snap shot of the data labels. With the original on bottom. The current in the middle. And the goal data label I am looking for on top. Hope this helps and plenty thanks in advance.

 

(defun c:DTEST (/ *ERROR* oldlayr p1 p2 DPNUM)
(defun *error* (msg)
   (if oldlayr (setvar "clayer" oldlayr))
   (if oldos (setvar "osmode" oldos))
   (if msg (prompt msg))
   (princ)
   )
(defun getdpnum ()
(if (= dpnum nil)
(setq dpnum (getreal "\nEnter STARTING datapoint number (1.00-999.99): "))
(setq dpnum (+ dpnum 1)))
)
(WHILE
 (setq oldos (getvar "osmode"))
 (setq oldlayr (getvar "clayer")) (command "._-layer" "s" DATAPOINT "")
 (initget 1)  (setq p1 (getpoint "\nSelect datapoint location on pipe: "))
 (setvar "osmode" 0)
 (initget 33) (setq p2 (getpoint p1 "\nSelect datapoint label location: "))
 (getdpnum)
 (get_info "DATAPOINTS" "END DATAPOINTS" DPINFO "#" "-")
 (command "._-layer" "s" oldlayr "")
 (setvar "OSMODE" OLDOS)
)
(*error* nil)
(prin1))

 

 

attachment.php?attachmentid=56146&cid=1&stc=1

data labels.JPG

Link to comment
Share on other sites

Sorry Lee, I left it out thinking that the answer was somewhere within this specific routine, since the "0.00" was in there. See below for GET_INFO routine. Again keep in mind this code most likely references other routines and if you think the answer might be in one of those other functions please call it out and I will get it for you. Thanks a bunch!

 

(defun get_info (st_pt end_pt lay_name str1 str2 / side p3 p4 inputline
                dpff nlp lchanged printed linetext placeholder)
(if (not (equal p1 p2))
 (progn
  (if (< (car p1) (car p2))
   (progn (setq side "ML") (setq dir 0.0))
   (progn (setq side "MR") (setq dir 180.0))
  )
  (setq p3 (polar p2 (dtr dir) (getvar "userr1")))
  (setq p4 (polar p3 (dtr dir) (getvar "userr1")))
 )
 (progn (setq p4 p2) (setq side "ML")
 )
)
(setq inputline nil)
(openfile)
(seek-tcircuit)
(while (not (equal inputline st_pt)) (setq inputline (read-line infile)))
(setq printed "N")
(while (not (equal inputline end_pt))
 (setq inputline (read-line infile))
 (if (/= inputline end_pt)
  (progn
   (if (= etype "G")
    (progn
     (dpn inputline)
     (setq dpff txt))
    (progn
     (dpn inputline)
     (setq dpff (atof txt))))
   (if (= dpnum dpff)
    (progn
     (if (not (equal p1 p2))
      (progn
       (command "._line" p1 p2 p3 "")
       (setq a (angle p2 p1))
       (command "._solid" p1 (polar p1 (- a 85) (getvar "userr1"))
                             (polar p1 (+ a 85) (getvar "userr1")) "" "")
      )
     )
     (command "._text" side p4 (getvar "userr1") 0 (getline 1 inputline))
     (setq lchanged "N")
     (setq nLp 2)
     (while (<= nLp 5)
      (setq LineText (getline nLp inputline))
      (if (/= (strlen LineText) 0)
       (progn
        (command "._text" "" Linetext)
        (if (= lchanged "N")
         (command "._change" "L" "" "P" "LA" lay_name ""))
        (setq lchanged "Y")
       )
      )
      (setq nLp (1+ nLp))
     )
     (setq Printed "Y")
     (setq inputline end_pt)
    )
   )
  )
 )
)
(closefile)
(if (= printed "N")
 (progn
  (command "._line" p1 p2 p3 "")
  (setq a (angle p2 p1))
  (command "._solid" p1 (polar p1 (- a 85) (getvar "userr1"))
                        (polar p1 (+ a 85) (getvar "userr1")) "" "")
  (if (= etype "G")
   (setq placeholder (strcat str1 dpnum str2))
   (setq placeholder (strcat str1 (rtos dpnum 2 2) str2))
  )
  (if (<= (nth 0 p1) (nth 0 p2))
   (command "._text" side p4 (getvar "userr1") 0 placeholder)
   (command "._text" side p4 (getvar "userr1") 0 placeholder)
  )
 )
)
(prin1))

Link to comment
Share on other sites

LEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!! YOU'RE THE MAN! WOW! I wish I was more advanced when it comes to LISP. I completely overlooked that part of the code. Im such a noob!

Link to comment
Share on other sites

Lee I have just sent you a donation. Thanks for all of your support and numerous times you have helped me with code, I truly appreciate you and the work you do. You continue to amaze me. Blessings.

Link to comment
Share on other sites

Lee, I am just noticing I have another issue. I completely forgot there are times where we have multiple data labels within one label (i.e. #50.1, #50.2, #50.3). When I enter #50.1 it doesn't come in as #50.1, it comes in as 50, it is leaving out decimals altogether and rounding. I forgot to mention that when I started this thread and shouldn't have posted the title as "Remove Decimals", that was misleading. The real goal was just to remove the ".00" only when they have no data that exist in the .DAT file when it goes and searches. However when there is in fact data, I need it to insert for example #16.1- or #16.2- but at the same time display #50.1- not #50.10 or #50.00 if there isnt any data built in yet for #50.1- but we still want to show the call out for when we do inspect and insert data for that label. I hope this helps and I appreciate your time helping me with this.

Link to comment
Share on other sites

So in one drawing we may have:

 

#17- PIPE .290 ;; currently built in and has data in the .DAT file

#17.1 - PIPE .220 ;; currently built in and has decimal because its a second data reading within the same location

#50.10- ;; this label has no data and this is what was displayed before we made the change

#50- ;; this label was entered as 50.1 after the change but appears to be rounding. I still need it to display the decimal and number in the tenths column. My apologies for the misleading original post.

 

Again I just need some sort of exception, because the change is all really for the data labels that have no data because we dont like seeing ".00-0.00" or ".00". I would like for the original code to be run as normal on all other data labels that exist in the .DAT file and have data.

Link to comment
Share on other sites

Here is a picture of what I am talking about. The bottom data label #6 is a whole number and has data. Then, label #7 is a whole number without data in the .DAT file. Next is label #7.1 which is a real number with no data. Finally there is label #7.2 which is a real number with data. This is how I need them to display. Regardless of data existing or not we dont like seeing 0.00's and .00's or .00-0.00's all over our drawing when we have dozens of labels called out but havent yet been inspected.

 

attachment.php?attachmentid=56162&cid=1&stc=1

Capture.jpg

Capture.JPG

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...