Update LISP to Rounding Bearings Automatically

Update LISP to Rounding Bearings Automatically

Anonymous
Not applicable
1,148 Views
5 Replies
Message 1 of 6

Update LISP to Rounding Bearings Automatically

Anonymous
Not applicable

Hi,

 

I have a lisp for adding bearings and distances to lines. It works well but I usually have to edit the bearings.

 

The edits I manually make are..

  • I round the seconds to the nearest 5"
  • If the bearing is 95°5'23" I manually change it to 95°05'25" (it's always 2 digits for the minutes unless when it's 0')
  • If the bearing is 90°0'0", I manually change it to 90°0' 

Please can someone help me with the rounding and presentation of the bearings?

 

(defun CHGD(os / ns sl ct lt)
(setq ns "" sl (strlen os) ct 1)
(command "osnap" "none")
(while (<= ct sl)
(setq lt (substr os ct 1))
(if (= lt "d")(setq lt "%%d"))
(setq ct (1+ ct) ns (strcat ns lt)))
)
(defun create_layer (name clr)
(if (null (tblsearch "layer" name))
(command "layer" "new" name "color" clr name "")
)
); change layer

(DEFUN C:OO ()
(setvar "cmdecho" 0)
(command "undo" "begin")

(setq oldosmode (getvar "osmode") )

(SETQ L 0 MID 0 MID 0 AN 0 BRG 0 DIST 0 A 0 B 0 C 0 D 0 MA 0 MB 0 MC 0 MD 0 MID 0 Z 0)
(PROMPT "\nSelect lines to be annotated..")
(setq ss1 (ssget)
n (sslength ss1)
index 0
dim (getvar "DIMSCALE")
ht (* dim 1.8)
)
(while (> n index)
(setq l (ssname ss1 index)
index (+ index 1)
OFFSET (* 0.6 ht)
L (ENTGET L)
ST (CDR (ASSOC 10 L))
END (CDR (ASSOC 11 L))
AN (ANGLE ST END)
BRG (CHGD (ANGTOS AN 1 4))
AN (* AN (/ 180 PI))
dAND AN
dAND (- dAND 90)
dAND (- 360 dAND)
); setq

(IF (> dAND 360)
(SETQ dAND (- dAND 360))
)
(IF (>= dAND 180)
(SETQ dAND (+ dAND 180))
)
(IF (= dAND 540)
(SETQ dAND 0)
)
(SETQ DIST (RTOS (DISTANCE ST END) 2 3)
A (CAR ST)
B (CDR ST)
B (CAR B)
C (CAR END)
D (CDR END)
D (CAR D)
MA (+ A C)
MB (+ B D)
MC (/ MA 2)
MD (/ MB 2)
ANR (* (* (/ AN 360) 2) PI)
MID (LIST MC MD)
); setq
(IF (> dAND 180)
(SETQ MID1 (POLAR MID (- ANR (* 0.5 PI)) OFFSET))
)
(IF (> dAND 180)
(SETQ MID2 (POLAR MID (+ ANR (* 0.5 PI)) (+ OFFSET HT)))
)
(IF (<= dAND 180)
(SETQ MID1 (POLAR MID (+ ANR (* 0.5 PI)) OFFSET))
)
(IF (<= dAND 180)
(SETQ MID2 (POLAR MID (- ANR (* 0.5 PI)) (+ OFFSET HT)))
)
(SETQ Z (+ Z 1))
(IF (= Z 1)
(COMMAND "STYLE" "rjc" "rjc" HT "1.00" "" "" "" "")
)
(COMMAND "TEXT" "C" MID1 dAND BRG)
(create_layer "bearing" 7)
(command "chprop" "si" "last" "layer" "bearing" "")
(COMMAND "TEXT" "C" MID2 dAND DIST)
(setq elist (entget (entlast)))
(entmod (subst (cons '51 (/ pi 9)) (assoc '51 elist) elist))
(create_layer "distance" 1)
(command "chprop" "si" "last" "layer" "distance" "")
); while
(command "undo" "end")
(setvar "cmdecho" 1)

(setvar "osmode" oldosmode)

(princ)
); c:oo

 

Thanks in advance,

 

Ross

0 Likes
1,149 Views
5 Replies
Replies (5)
Message 2 of 6

qnologi
Advisor
Advisor

Have you posted this on this forum?

 

Visual LISP, AutoLISP and General Customization

qnologi
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
...

The edits I manually make are..

  • I round the seconds to the nearest 5"
  • If the bearing is 95°5'23" I manually change it to 95°05'25" (it's always 2 digits for the minutes unless when it's 0')
  • If the bearing is 90°0'0", I manually change it to 90°0' 
....

 

It's all in the:
BRG (CHGD (ANGTOS AN 1 4))

 

For your last bullet point, look into the AUPREC and DIMAZIN System Variables.  But I don't know that you'll be able to get everything you want -- if you set AUPREC so as to get 90°0' [without the seconds], or you use 2 instead of the 4 there, then you won't get the ones with the seconds.  Might it involve a routine checking the result first, and then adjusting a setting to suit?

 

A complication is that angular values in AutoCAD are stored in radians.  It's not to hard to round a plain number to the nearest multiple of some round-it-off-to value [Search the Customization Forum for a bunch of routines], but to round an angular value in radians to the nearest multiple of 5 DMS arc-seconds, when the value itself is in radians, will require an unusual roundoff value, but I guess it can be done.

Kent Cooper, AIA
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

@Anonymous wrote:...
  • If the bearing is 90°0'0", I manually change it to 90°0' 
....

 

It's all in the:
BRG (CHGD (ANGTOS AN 1 4))

.... if you set AUPREC so as to get 90°0' [without the seconds], or you use 2 instead of the 4 there, then you won't get the ones with the seconds.  Might it involve a routine checking the result first, and then adjusting a setting to suit?

.... to round an angular value in radians to the nearest multiple of 5 DMS arc-seconds, when the value itself is in radians, will require an unusual roundoff value ....


 

EDIT:

 

Simpler than I thought.  Add these lines [very lightly tested]:

....

    dim (getvar "DIMSCALE")
    ht (* dim 1.8)
    round (/ pi 180 60 12); rounding value for application at each
  ); end setq
  (while (> n index)
    (setq
      l (ssname ss1 index)
      index (+ index 1)
      OFFSET (* 0.6 ht)
      L (ENTGET L)
      ST (CDR (ASSOC 10 L))
      END (CDR (ASSOC 11 L))
      AN (ANGLE ST END)
      ANr (* (fix (/ (+ AN (/ round 2.0)) round)) round); radians rounded to nearest DMS 5" increment
      BRG (CHGD (ANGTOS ANr 1 4)); text-string equivalent in degrees
      BRG (vl-string-subst "'" "'0\"" BRG); lop off 0" if present
      AN (* AN (/ 180 PI))
      dAND AN

....

 

By the way, that rounding function is a simpler one that does not work right with negative values, but since the return of (angle) is never negative, simpler will serve.

 

There are a lot of other things that could be improved in the routine [for example, its way of finding the midpoint of the Line, and the more readable direction for the angle, are far more complicated than necessary], but see whether the above works for you.  [I was getting results with the Text at odd-ball angles in relation to the Line directions, but I didn't dig into why yet -- I was focusing on the bearing-text content questions.]

Kent Cooper, AIA
0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks for that Kent. i really appreciate the time you've spent on it.

 

I've just had a little play with it and the changes are working well.

The rounding to the nearest 5 seconds and changing the bearing from 90°0'0" to 90°0' works great.

 

Is it possible to automate the 161°0'5" to 161°00'05" 

Also with the distances, is it possible to automate 100 to 100.0? When the distance is 100.3, it appears as 100.3 which is what I'm after. It's just when the distance is at a round metre I'd like the .0 after it.

 

I think the reason the text appears at odd ball angles is due to the snaps. The text lines up correctly for me but I've had issues with that in the past.

 

Thanks in advance,


Ross

 

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

Also with the distances, is it possible to automate 100 to 100.0? When the distance is 100.3, it appears as 100.3 which is what I'm after. It's just when the distance is at a round metre I'd like the .0 after it....


 

For that part, the DIMZIN System Variable setting controls whether trailing zeros are included in the return of an (rtos) function.   But with your (rtos) using 3 as its precision argument in setting the DIST variable, you're going to get 100.300 and 100.000.

Kent Cooper, AIA
0 Likes