Change units of existing lisp

Change units of existing lisp

allebana13
Enthusiast Enthusiast
1,510 Views
10 Replies
Message 1 of 11

Change units of existing lisp

allebana13
Enthusiast
Enthusiast

Hi everyone!
I have this routine from kimprojects, that sum up length of polylines and label as a text. Works very good but i need to change the units from meters to centimeters and i couldn't do it so far. Any helps?

(defun c:LPL (/ e ss l p i)
(if
(setq l 0.0 ss (ssget '((0 . "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE"))))
(progn
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
l (+ l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
)
)
(if
(setq p (getpoint "\nSpecify a point to insert text: "))
(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbText")
(cons 10 (trans p 1 0))
(cons 40 (/ 0.2 (getvar 'cannoscalevalue)))
(cons 1 (rtos l))
)
)
(princ (strcat "\nTotal length = " (rtos l)))
)
)
)
(princ)
)

0 Likes
Accepted solutions (2)
1,511 Views
10 Replies
Replies (10)
Message 2 of 11

pbejse
Mentor
Mentor
Accepted solution

@allebana13 wrote:

 need to change the units from meters to centimeters and i couldn't do it so far. Any helps?


Add this line

...
)
(setq l (* 100 l))
(if
 (setq p (getpoint "\nSpecify a point to insert text: "))
  (entmake
...

 

0 Likes
Message 3 of 11

allebana13
Enthusiast
Enthusiast

Thank you! it works perfectly.

0 Likes
Message 4 of 11

allebana13
Enthusiast
Enthusiast

i have another question. How do i set the precision of the unit so that returns a non-decimal number?
If total lenght is 12.031, i want to get 12 instead.
Sorry for my bad english, I really appreciate your help.

0 Likes
Message 5 of 11

pbejse
Mentor
Mentor

Change (rtos l ) to (rtos l 2 0 )

0 Likes
Message 6 of 11

allebana13
Enthusiast
Enthusiast

Hi! Thank you! I tried this and doesn't work, i keep getting a result with 4 decimal. What can be wrong?

(defun c:LPL (/ e ss l p i)
(if
(setq l 0.0 ss (ssget '((0 . "LINE,SPLINE,LWPOLYLINE,POLYLINE,ARC,CIRCLE,ELLIPSE"))))
(progn
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i)))
l (+ l (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)))
)
)
(setq l (* 100 l))
(if
(setq p (getpoint "\nSpecify a point to insert text: "))
(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbText")
(cons 10 (trans p 1 0))
(cons 40 (/ 0.15 (getvar 'cannoscalevalue)))
(cons 1 (rtos l))
)
)
(princ (strcat "\nTotal length = " (rtos l 2 0)))
)
)
)
(princ)
)

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

You changed the prompt, but not also the part that sets the text content:

(cons 1 (rtos l))

should be

(cons 1 (rtos l 2 0))

Kent Cooper, AIA
0 Likes
Message 8 of 11

allebana13
Enthusiast
Enthusiast

Thank you Kent! I'm very new at this.
Do you have any suggestions to start learning code language for be able to read and write lisp? I'm interested. Thank you.

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant

@allebana13 wrote:

....
Do you have any suggestions to start learning code language for be able to read and write lisp? ....


Search this Forum for terms like "learn Lisp" or "learn AutoLisp" or "tutorial" or related wordings, and you will find a lot of suggestions for website links, videos, books, etc.

Kent Cooper, AIA
Message 10 of 11

suarez_residence
Community Visitor
Community Visitor

Hi everyone, how to change my unit from ' to m in my lisp

 

0 Likes
Message 11 of 11

suarez_residence
Community Visitor
Community Visitor

(DEFUN CHGD(OS / NS SL CT LT )
(SETQ NS "" SL (STRLEN OS) CT 1)
(WHILE (<= CT SL)
(SETQ LT (SUBSTR OS CT 1))
(IF (= LT "d")(SETQ LT "%%d"))
(SETQ CT (1+ CT) NS (STRCAT NS LT))))

(DEFUN C:BEARINGS( / P1 P2 P3 P4 DSTR DIST ASTR ANG TMP ENT LEN SS FLG KW1 TH KW )
(SETVAR "OSMODE" 0)
(SETVAR "ANGBASE" 0)
(SETVAR "CMDECHO" 0)
(command "style" "" "" 0.0 "" "" "" "" "" nil)
(PRINC "Note: ALL DISTANCES are from the X-Y PLANE\n")
(INITGET 1 "LR RL LL RR BL BR DL DR")
(SETQ KW (GETKWORD "LR RL LL RR BL BR DL DR: "))
(initget (+ 2 4))
(SETQ TH (GETDIST (strcat "TEXT HEIGHT <" (rtos (getvar "TEXTSIZE")) "> :")))
(if (= nil TH)(setq th (getvar "textsize")))
(INITGET 1 "Yes No")
(SETQ KW1 (GETKWORD "Reverse the Bearing Direction <Y>es <N>o: "))
(SETQ FLG 0)
(if (= KW1 "Yes")(progn
(IF (and(= KW "LR")(= FLG 0))(SETQ KW "RL" FLG 1))
(IF (and(= KW "RL")(= FLG 0))(SETQ KW "LR" FLG 1))
(IF (and(= KW "LL")(= FLG 0))(SETQ KW "RR" FLG 1))
(IF (and(= KW "RR")(= FLG 0))(SETQ KW "LL" FLG 1))
(IF (and(= KW "BL")(= FLG 0))(SETQ KW "BR" FLG 1))
(IF (and(= KW "BR")(= FLG 0))(SETQ KW "BL" FLG 1))
(IF (and(= KW "DL")(= FLG 0))(SETQ KW "DR" FLG 1))
(IF (and(= KW "DR")(= FLG 0))(SETQ KW "DL" FLG 1))
))
(SETVAR "TEXTSIZE" TH)
(SETQ SS (SSGET))
(SETQ LEN (SSLENGTH SS))
(SETVAR "HIGHLIGHT" 0)
(PRINC "WORKING...\n")
(REPEAT LEN
(SETQ LEN (1- LEN))
(SETQ ENT (SSNAME SS LEN))
(IF (/= "LINE" (CDR (ASSOC '0 (ENTGET ENT))))
(SSDEL ENT SS))
)
(SETQ LEN (SSLENGTH SS))
(REPEAT LEN
(SETQ LEN (1- LEN)
ENT (ENTGET (SSNAME SS LEN))
P1 (CDR (ASSOC '10 ENT))
P2 (CDR (ASSOC '11 ENT))
)
(IF (= KW1 "Yes")(SETQ TMP P2 P2 P1 P1 TMP))
(SETQ ANG (ANGLE P1 P2)
ASTR (CHGD (ANGTOS ANG 4 6))
DIST (DISTANCE P1 P2)
DSTR (RTOS DIST 2 3)
DSTR (STRCAT DSTR "\047")
P3 (POLAR P1 ANG (/ DIST 2.0))
P3 (POLAR P3 (+ ANG (/ PI 2.0))(* TH 1.125))
P4 (POLAR P1 ANG (/ DIST 2.0))
P4 (POLAR P4 (- ANG (/ PI 2.0))(* TH 1.125))
)
(IF (AND (> ANG (/ PI 2.0))(< ANG (* PI 1.5)))(SETQ ANG (- ANG PI)))
(SETQ ANG (ANGTOS ANG 0 8))
(IF (OR (= KW "DL") (= KW "DR"))(SETQ ASTR ""))
(IF (OR (= KW "BL")(= KW "BR"))(SETQ DSTR ""))
(IF (= ASTR "E")(SETQ ASTR "East"))
(IF (= ASTR "N")(SETQ ASTR "North"))
(IF (= ASTR "W")(SETQ ASTR "West"))
(IF (= ASTR "S")(SETQ ASTR "South"))
(IF (OR (= KW "LR")(= KW "BL")(= KW "DR"))(PROGN
(COMMAND "TEXT" "M" P3 "" ANG ASTR)
(COMMAND "TEXT" "M" P4 "" ANG DSTR)
)
)
(IF (= KW "LL") (PROGN
(SETQ ASTR (STRCAT ASTR " " DSTR))
(COMMAND "TEXT" "M" P3 "" ANG ASTR)
)
)
(IF (OR (= KW "RL")(= KW "BR")(= KW "DL")) (PROGN
(COMMAND "TEXT" "M" P4 "" ANG ASTR)
(COMMAND "TEXT" "M" P3 "" ANG DSTR)
)
)
(IF (= KW "RR") (PROGN
(SETQ ASTR (STRCAT ASTR " " DSTR))
(COMMAND "TEXT" "M" P4 "" ANG ASTR)
)
)
)
(SETVAR "HIGHLIGHT" 1)
(SETQ SS nil)(GC)
(SETVAR "FLATLAND" 0)
(PRINC "DONE")
(PRINC)
);close defun

0 Likes