Jump to content

Bearing and Dimension lisp routine questions


drafting1768

Recommended Posts

Hi.  I have a lisp routine that I use all the time but I'm wondering if someone could please tell me how the routine sets the following variables:

1. The number of decimal places (precision) that the distance displays at.  It currently displays it to 2 decimal places, I'd like to have 3 eg. 0.000

2. The text offset distance from the line.

 

Thank you all in advance!  😊

 

 

(defun get_endpts (/ a b)
     (COMMAND "OSNAP" "ENDP")
     (setq a (getpoint "\nEnter first point: "))
     (setq b (getpoint "\nEnter second point: "))
     (COMMAND "OSNAP" "NONE")
     (list a b)
 )

(defun c:setdim ()
   ;(initget (+ 1 2 4))
   ;(setq scalefactor (getreal "\nEnter scale factor: "))
   (if (not setmap)
       (load "setmap")
   )
   (setmap)
   (setq scalefactor #mapsc)
   ;(initget 1 "Y y N n")
   ;(setq angflg (question "Do you want azimuths printed?"))
   (setq angflg "Y" angmessage "WILL")
   ;(cond (angflg
   ;      (if (not (setq dimrotation (getangle "\nEnter angular rotation: ")))
   ;          ;(setq dimrotation #mapang )
   ;    (setq DIMROTATION 0)
   ;      )
   ;      (initget 1 "1 5")
   ;      (setq secprec (atoi (getkword "\nRound off seconds to nearest <1 or 5> ")))
   ;   )
   ;)
   (setq dimrotation 0 secprec 5 secsmessage "5")
   (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
           "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown.\n\nTo change other settings type SETDIM2."))
   (setq dimset T)
   (princ)
   ;(chgsize (* (/ scalex 1000) 1.95))
);defun setdim

(defun c:setdim2 ()
   (initget (+ 1 2 4))
   ;(setq scalefactor (getreal "\nEnter scale factor: "))
   (if (not setmap)
          (load "setmap")
   )
   (setq scalefactor #mapsc)
   (initget 1 "Y y N n")
   (setq angflg (question "Do you want azimuths printed?"))
   (if angflg
       (progn         
         (setq DIMROTATION 0 angMessage "WILL")    
             (initget 1 "1 5")
             (setq secsMessage (getkword "\nRound off seconds to nearest <1 or 5> "))
             (setq secprec (atoi secsmessage))
         )
         (setq angMessage "WON'T" )
   )
   (alert (strcat "DIMLINE SETTINGS: \n\nScale Factor set to: " (rtos scalefactor 2 6) "\nAzimuths " angmessage " print." "\nSeconds rounded off to " secsmessage "\""
           "\n\n\nTo change the Scale Factor use MAP SETTINGS CSF \+ ROTATION \non the LISP pulldown."))
   (setq dimset T)
   ;(chgsize (* (/ scalex 1000) 1.95))
)


(defun c:dimline (/ L A B ucsflg)
     (load "F1")
     (cond ((not dimset) (c:setdim)))
     (if (/=(getvar "WORLDUCS") 1)
             (progn
                 (command "UCS" "W")
                 (setq UCSflg T)
             );progn
     );if
     (setq L (getline))
     (dimfunc (getassoc 10 L) (getassoc 11 L)
              (placetxt (getassoc 10 L) (getassoc 11 L))
     )
     (if UCSflg
           (COMMAND "UCS" "P")
     )
)

(defun c:dimpts (/ ENDPTS ucsflg)
     (load "F1")
     (cond ((not dimset) (c:setdim)))
     (if (/=(getvar "WORLDUCS") 1)
              (progn
                  (command "UCS" "W")
                  (setq UCSflg T)
              );progn
     );if
     (dimfunc (car(setq ENDPTS(get_endpts))) (cadr ENDPTS)
              (placetxt (car ENDPTS)(cadr ENDPTS))
     )
     (if UCSflg
                (COMMAND "UCS" "P")
     )
)
(defun dimfunc (a b below / angab distab ctrpt d)
     (setq angab (angle a b))
     (setq distab (distance a b))
     (setq ctrpt (polar a angab (/ distab 2)))
     (setq d  (/ distab scalefactor))
     (cond
       (below
          (cond
             ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
                (writedim d angab ctrpt (+ angab A90) (- angab PI) 1.20 2.85)
             )
             (T (writedim d angab ctrpt (+ angab A270) angab 1.20 2.85))
          )
       )
       (T (cond
             ((and (> angab (+ NORTH 0.1744)) (<= angab (+ SOUTH 0.1744)))
                (writedim d angab ctrpt (+ angab A270) (- angab PI) 1.20 2.85)
             )
             (T (writedim d angab ctrpt (+ angab A90) angab 1.20 2.85))
          )
       )
     )
 )
(defun writedim (d azimuth ctrpt perpang orientation sp1 sp2 / textpt scalept)
     ;(switchl "DIMENSION")
     (setq textpt (polar ctrpt perpang (* (getxtht) sp1)))
     (setq scalePt ctrpt)
     (COMMAND "TEXT" "M" textpt  (angtos orientation)  (rtos d 2 2))
     (cond (angflg
        (setq textpt (polar ctrpt perpang (* (getxtht) sp2)))
        (COMMAND "TEXT" "M" textpt (angtos orientation)
                      (writeang (+ angab (dtr dimrotation)))
         )
     ))
     (if (= (substr (getvar "CLAYER") 1 2) "34")
         (progn
             (findDetailScale)
             (if (and (/= nil detTxtScl)(/= 0.0 detTxtScl))           
                 (command "SCALE" (lastn 2) "" scalept detTxtscl)
                 (command "SCALE" (lastn 2) "" scalept theRatio) 
             )
         )
     )
             
          
    ; (switchl nil)
)


(defun findDetailScale ( / detLayer detLen det7thLast undScr)
    (if (not c:lastn)
        (load "LASTN")
    )
    (if (null theRatio)
        (progn
            (load "labelling")
            (c:detail)
        )
    )
    (setq detLayer (getvar "CLAYER"))
    (setq detlen (strlen detLayer))
    (setq det7thLast (substr detLayer (- detLen 6)))
    (setq undScr (st_scan "_" det7thlast))
    (setq detTxtScl  (/ (* 0.001 (atoi (substr det7thLast (+ 1 undScr)))) plscale))
)
    
    

(defun writeang (azimuth)
  (setq azimuth (angtos azimuth 1 4))
  (if (= "d" (substr azimuth 3 1))
      (strcat (deg_format azimuth 3))
      (if (= "d" (substr azimuth 4 1))
          (strcat (deg_format azimuth 4))
          (strcat (deg_format azimuth 2))
      )
  )
  (cond ((= 5 secprec)
           (cond
              ((< 7 (last_digit seconds))
                 (setq seconds (additostr seconds (- 10 (last_digit seconds))))
              )
              ((< 2 (last_digit seconds))
                 (setq seconds (additostr seconds (- 5 (last_digit seconds))))
              )
              (T (setq seconds (additostr seconds (- 0 (last_digit seconds)))))
           )
           (if (= (strlen seconds) 1) (setq seconds (strcat "0" seconds)))
           (if (= "60" seconds) (progn
               (setq seconds "00")
               (setq minutes (additostr minutes 1))
               (if (= (strlen minutes) 1) (setq minutes (strcat "0" minutes)))
               (if (= "60" minutes) (progn
                   (setq minutes "00")
                   (setq degrees (additostr degrees 1))
               ))
           ))
  ))
  (if (/= (strcase (getvar "LOGINNAME")) "Pam.hvizdos")
      (strcat degrees "%%d" minutes "'" seconds "\"")
      (strcat degrees "%%d" minutes "'" seconds "\"")
  )
      
)


(defun deg_format ( str pos)
    (setq degrees (substr str 1 (- pos 1)))
    (min_format (substr str (+ pos 1)))
)
 (defun min_format (str)
    (setq minutes (cond ((= "'" (substr str 2 1))
                         (sec_format (substr str 3))
                         (strcat"0" (substr str 1 1))
                        )
                        (T (sec_format (substr str 4))
                           (substr str 1 2)
                        )
                  )
    )
 )
 
 
(defun sec_format (str)
    (setq seconds (substr (if ( = 2 (strlen str))
                              (strcat "0" str)
                              str
                          )
                          1 2
    ))
)
(defun last_digit(str)
   (atoi (substr str (strlen str)))
)
(defun additostr(str no)
       (itoa (+ (atoi str) no))
)

 

Link to comment
Share on other sites

1 look at help for lisp commands and the rtos function regrading decimal palces, also atof and atoi, I have some www links need to add to my new pc.

 

Its a lot of code to wade through but a guess try changing (/ distab 2) to (/ distab 1.5) if it moves text away then you are on the right path.

Edited by BIGAL
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...