Jump to content

HOW TO MAKE result NUMBER 300,000,000㎟ -> 300㎡ ?


nestation

Recommended Posts

Posted (edited)
(defun c:BB ( / ss index asum e obj tmparea msp spt txtobj )
  (if (setq ss (ssget (list (cons 0 "CIRCLE,ARC,LWPOLYLINE,ELLIPSE,SPLINE"))))
    (progn
      (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
      (setq index 0 asum 0)
      (repeat (sslength ss)
    (setq e (ssname ss index))
    (setq obj (vlax-ename->vla-object e))
    (setq tmparea (vla-get-area obj))
    (setq asum (+ asum tmparea))
    (setq index (1+ index))
      )
      (prompt (strcat "\nTotal area = " (rtos asum 2 2)))
      (initget 1)
      (setq spt (getpoint "\nText start point: "))
      (setq txtobj (vla-addtext msp (rtos asum 2 2) (vlax-3d-point spt) (getvar "textsize")))
    )
  )
  (princ)
)
(vl-load-com)
(prompt "\n[ ASUM ]")
(princ)

 

 

 

hi there.    i'm a Autolisp biginner.  I would like to get your help.

 

The result value of the above Autolisp is in this form.

      234,234,243                   (maybe ㎟)

 

But I want this form as a result value. 

     234㎡

 

I look forward to your earnest help.

 

 

 

 

 

 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

Please use Code Tags for your code in the future. (<> in the editor toolbar)

Link to comment
Share on other sites

you can use (cvunit asum "sq_mm" "sq_m") to convert it.
Additionally you could read insunits to check if that unit is actually used.
 

(defun c:BB ( / ss index asum e obj tmparea msp spt txtobj dwgunit)
  (if (setq ss (ssget (list (cons 0 "CIRCLE,ARC,LWPOLYLINE,ELLIPSE,SPLINE"))))
    (progn
      (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
      (setq index 0 asum 0)
      (repeat (sslength ss)
        (setq e (ssname ss index))
        (setq obj (vlax-ename->vla-object e))
        (setq tmparea (vla-get-area obj))
        (setq asum (+ asum tmparea))
        (setq index (1+ index))
      )
      (if (not (setq dwgunit (cdr (assoc (getvar "insunits") '((4 . "sq_mm")(5 . "sq_cm")(6 . "sq_m")))))) (progn (princ "\nError with dwg unit")(exit)))
      (setq asum (cvunit asum dwgunit "sq_m"))
      (prompt (strcat "\nTotal area = " (rtos asum 2 2) " m²"))
      (initget 1)
      (setq spt (getpoint "\nText start point: "))
      (setq txtobj (vla-addtext msp (strcat (rtos asum 2 2) " m²") (vlax-3d-point spt) (getvar "textsize")))
    )
  )
  (princ)
)

 

  • Agree 1
Link to comment
Share on other sites

Posted (edited)

sq mm to sq m is just a division.

 

(/ 234234234 1e6)
234.234234

(/ 234234234 1000000)
234

(/ 224234234 1000000.)
224.234234


(setq str (strcat "Area is " (rtos area 2 2) "m" (chr 178)))
"Area is 123.45m²"

The chr 178 can be different in some text fonts.

Edited by BIGAL
  • Agree 1
Link to comment
Share on other sites

On 7/4/2024 at 9:26 PM, SLW210 said:

Please use Code Tags for your code in the future. (<> in the editor toolbar)

 

Oh, I'm sorry. I was confused because it's been a while ~ Thank you

 

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...