Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADDING A COMMA

14 REPLIES 14
Reply
Message 1 of 15
CODYAARON2
857 Views, 14 Replies

ADDING A COMMA

How can I get this lisp routine to add a comma.

Ex. 10,000.00

The lisp routine works perfectly but I would like

to have the comma, it makes it easier to read.

Thanks
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: CODYAARON2

Lots of such discussions on the Newsgroup, for example:

http://discussion.autodesk.com/thread.jspa?messageID=5444690
http://discussion.autodesk.com/thread.jspa?messageID=1127640
http://discussion.autodesk.com/thread.jspa?messageID=4247409

Search for "comma" and you'll find these and more.
--
Kent Cooper


wrote...
How can I get this lisp routine to add a comma.

Ex. 10,000.00

The lisp routine works perfectly but I would like

to have the comma, it makes it easier to read.

Thanks
Message 3 of 15
Anonymous
in reply to: CODYAARON2

Here is your program, updated with everyone's suggestions and formatted a bit better.

Ron
Message 4 of 15
CODYAARON2
in reply to: CODYAARON2

Perfect, exactly what I was looking for.

Thanks alot
Message 5 of 15
Anonymous
in reply to: CODYAARON2

Hi Ron,

Pardon me for asking, but is there some reason to use this du variable ?
Don't you think that the expression (or (= du 1)(= du 2)(= du 3)(= du 4)(=
du 5)(= du 6)(= du 7)(= du 8)) means "I don't care about du, whatever the
value is" ? And why 2 (strcat ...) functions ? Here is the function with a
cleaner, tighter code and it works as good as the other one:

[code]
;===========================================
(defun C:POLYAREA (/ area ss n)
(if (setq ss (ssget '((0 . "*POLYLINE"))))
(progn
(setq area 0)
(repeat (setq n (sslength ss))
(command "_.area" "_o" (ssname ss (setq n (1- n))))
(setq area (+ area (getvar "area")))
)
(alert
(strcat
"\n Square Feet = "(rtoc area 3)
"\n Square Yards = "(rtoc (/ area 9.0) 3)
"\n Acres = "(rtoc (/ area 43560.0) 3)
)
)
)
(alert "\nNo polyline(s) selected!")
)
(princ)
)
;===========================================
[/code]

or a ActiveX version (only one variable):

[code]
;===========================================
(defun C:POLYAREA ( / area)
(vl-load-com)
(if (ssget '((0 . "*POLYLINE")))
(progn
(setq area 0)
(vlax-for item
(vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(setq area (+ area (vla-get-area item)))
)
(alert
(strcat
"\n Square Feet = "(rtoc area 3)
"\n Square Yards = "(rtoc (/ area 9.0) 3)
"\n Acres = "(rtoc (/ area 43560.0) 3)
)
)
)
(alert "\nNo polyline(s) selected!")
)
(princ)
)
;===========================================
[/code]

Regards,

Constantin

a écrit dans le message de news:
5493086@discussion.autodesk.com...
Here is your program, updated with everyone's suggestions and formatted a
bit better.

Ron
Message 6 of 15
Anonymous
in reply to: CODYAARON2

DIMUNIT:
Type: Integer
Saved in: Drawing
Initial value: 2
Obsolete. Has no effect in AutoCAD 2000 and later releases except to preserve the integrity of pre-AutoCAD 2000 scripts and AutoLISP routines. DIMUNIT is replaced by DIMLUNIT and DIMFRAC.

Constantin...Where in the following routine is it generating the comma separator?
;===========================================
(defun C:POLYAREA (/ area ss n)
(if (setq ss (ssget '((0 . "*POLYLINE"))))
(progn
(setq area 0)
(repeat (setq n (sslength ss))
(command "_.area" "_o" (ssname ss (setq n (1- n))))
(setq area (+ area (getvar "area")))
)
(alert
(strcat
"\n Square Feet = "(rtoc area 3)
"\n Square Yards = "(rtoc (/ area 9.0) 3)
"\n Acres = "(rtoc (/ area 43560.0) 3)
)
)
)
(alert "\nNo polyline(s) selected!")
)
(princ)
)
;===========================================
Nice bit of code...
Scrutch
Message 7 of 15
Anonymous
in reply to: CODYAARON2

Hi Scrutch,

Yes, I know about DIMUNIT, is effectless, but even if it would have had some
effect, that expression had no logic, it was like "whatever value it has, is
still good", so why not remove it ?

As for the POLYAREA function, I like the ActiveX alternative even more. And
if you want the comma separator, is not in this function, but in a
previously posted message of this same thread. I didn't reposted it because
it didn't change. To spare you the of searching it, here it is:

[code]
;==============================================================
(defun rtoc (num # / p#)
(setq num (rtos num 2 #) # 1)
(while (and (/= (substr num # 1) ".")(<= # (strlen num)))
(setq # (1+ #))
)
(setq # (1- #) p# #)
(if (= (setq # (rem # 3)) 0)(setq # 3))
(while (< # p#)
(setq num (strcat (substr num 1 #) "," (substr num (1+ #))) # (+ 4 #)
p# (1+ p#) )
)
num
)
;===============================================================
[/code]

Regards,

Constantin


a écrit dans le message de news:
5493468@discussion.autodesk.com...
DIMUNIT:
Type: Integer
Saved in: Drawing
Initial value: 2
Obsolete. Has no effect in AutoCAD 2000 and later releases except to
preserve the integrity of pre-AutoCAD 2000 scripts and AutoLISP routines.
DIMUNIT is replaced by DIMLUNIT and DIMFRAC.

Constantin...Where in the following routine is it generating the comma
separator?
;===========================================
(defun C:POLYAREA (/ area ss n)
(if (setq ss (ssget '((0 . "*POLYLINE"))))
(progn
(setq area 0)
(repeat (setq n (sslength ss))
(command "_.area" "_o" (ssname ss (setq n (1- n))))
(setq area (+ area (getvar "area")))
)
(alert
(strcat
"\n Square Feet = "(rtoc area 3)
"\n Square Yards = "(rtoc (/ area 9.0) 3)
"\n Acres = "(rtoc (/ area 43560.0) 3)
)
)
)
(alert "\nNo polyline(s) selected!")
)
(princ)
)
;===========================================
Nice bit of code...
Scrutch
Message 8 of 15
Anonymous
in reply to: CODYAARON2

Constantin,

I saw the comma separator function...but when I load and run the plain lisp routine you provided it places a (or several, depending on the size of the PLines) comma(s) in the text output. I was a bit curious about what and where in the routine the comma was generated.

Cheers,
Scrutch
Message 9 of 15
Anonymous
in reply to: CODYAARON2

It means that somehow it's already loaded and it's just there when needed by
whatever function.

Constantin

a écrit dans le message de news:
5493558@discussion.autodesk.com...
Constantin,

I saw the comma separator function...but when I load and run the plain lisp
routine you provided it places a (or several, depending on the size of the
PLines) comma(s) in the text output. I was a bit curious about what and
where in the routine the comma was generated.

Cheers,
Scrutch
Message 10 of 15
Anonymous
in reply to: CODYAARON2

Seems a bit weird to me...I don't think I have any function like the rtoc loaded. Maybe I already have it defined in some other lisp routine that loads on startup or it's just one of them magic things. :~)

Scrutch
Message 11 of 15
Anonymous
in reply to: CODYAARON2

Scrutch wrote:
> I don't think I have any function like the rtoc loaded.

Type !rtoc at the command prompt, and you'll find out for sure:

Command: !rtoc
#

Command: !fakefunctionname
nil
Message 12 of 15
Anonymous
in reply to: CODYAARON2

Now why didn't I think of that...? Perhaps I'm having a stupid attack right in the middle of a dumb spell.

Command: !rtoc
# SUBR @0246df50 RTOC

:~)
Message 13 of 15
Anonymous
in reply to: CODYAARON2

Oki..., found it. Something I have in a calculation routine for solids that returns the volume...duh !
Message 14 of 15
Anonymous
in reply to: CODYAARON2

You see, I know it's sad, but there's no magic 😞


a écrit dans le message de news:
5493594@discussion.autodesk.com...
Seems a bit weird to me...I don't think I have any function like the rtoc
loaded. Maybe I already have it defined in some other lisp routine that
loads on startup or it's just one of them magic things. :~)

Scrutch
Message 15 of 15
Anonymous
in reply to: CODYAARON2

Well I was counting on the magic to be real...it's a sad day when they tell you there is NO magic !

I did a search here for the rtoc and the one I used was coded by John Unden as well as the one that was posted here today. Thanks John...the routine works so well I though it was magic but Constantin assures me there is no magic but he could be wrong just this once.

Scrutch

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost