Jump to content

Recommended Posts

Posted

Hi guys! :D

I'm using that excellent code from Mr. Lee Mac.

And I need a help to make a little modification in that code.

I'd like to control the text size. That code doesn't have any option for that.

 

Anybody Can help me out, please?

 

Thank in advance

 

;;-------------------=={ Areas 2 Field }==--------------------;;
;;                                                            ;;
;;  Creates an MText object containing a Field Expression     ;;
;;  referencing the area, or sum of areas, of one or more     ;;
;;  selected objects.                                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.2    -    26-05-2013                            ;;
;;------------------------------------------------------------;;

(defun c:a2f ( / *error* fmt inc ins lst sel str )

   (setq fmt "%lu6%qf1%ds44%th46") ;; Field Formatting

   (defun *error* ( msg )
       (LM:endundo (LM:acdoc))
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (if
       (and
           (setq sel (ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))
           (setq ins (getpoint "\nPick Point for Field: "))
       )
       (progn
           (if (= 1 (sslength sel))
               (setq str
                   (strcat
                       "%<\\AcObjProp Object(%<\\_ObjId "
                       (LM:ObjectID (vlax-ename->vla-object (ssname sel 0)))
                       ">%).Area \\f \"" fmt "\">%"
                   )
               )
               (progn
                   (repeat (setq inc (sslength sel))
                       (setq lst
                           (vl-list*
                               "%<\\AcObjProp Object(%<\\_ObjId "
                               (LM:ObjectID (vlax-ename->vla-object (ssname sel (setq inc (1- inc)))))
                               ">%).Area>%" " + "
                               lst
                           )
                       )
                   )
                   (setq str
                       (strcat
                           "%<\\AcExpr "
                           (apply 'strcat (reverse (cdr (reverse lst))))
                           " \\f \"" fmt "\">%"
                       )
                   )
               )
           )
           (LM:startundo (LM:acdoc))
           (vla-addmtext
               (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
               (vlax-3D-point (trans ins 1 0))
               0.0
               str
           )
           (LM:endundo (LM:acdoc))
       )
   )
   (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems

(defun LM:ObjectID ( obj )
   (eval
       (list 'defun 'LM:ObjectID '( obj )
           (if
               (and
                   (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                   (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
               )
               (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
              '(itoa (vla-get-objectid obj))
           )
       )
   )
   (LM:ObjectID obj)
)

;; Start Undo  -  Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
   (LM:endundo doc)
   (vla-startundomark doc)
)

;; End Undo  -  Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
   (while (= 8 (logand 8 (getvar 'undoctl)))
       (vla-endundomark doc)
   )
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
   (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (LM:acdoc)
)

(vl-load-com) (princ)

;;------------------------------------------------------------;;
;;                        End of File                         ;;
;;------------------------------------------------------------;;

Posted

Hi

 

Read Lee's instruction page for this LISP.

 

Also

 

(setq fmt "%lu6%qf1%ds44%th46") ;; Field Formatting

 

If I recall the th refers to text height. I'm sure Lee will confirm.

Posted

Hi Spaj,

Thanks for the quick replay

 

I was thinking if possible to create a input for the text size instead of modify inside the code.

Posted

Hi Madruga,

 

Since the program is creating an MText Field, the text height will be determined by the value of the TEXTSIZE system variable at the time of running the program.

 

However, here is a quick mod to include an additional prompt for the height:

;;-------------------=={ Areas 2 Field }==--------------------;;
;;                                                            ;;
;;  Creates an MText object containing a Field Expression     ;;
;;  referencing the area, or sum of areas, of one or more     ;;
;;  selected objects.                                         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2013 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Version 1.2    -    26-05-2013                            ;;
;;------------------------------------------------------------;;

;; Modified to prompt for text height  -  Lee Mac 2013-12-18

(defun c:a2f ( / *error* fmt hgt inc ins lst sel str )

   (setq fmt "%lu6%qf1%ds44%th46") ;; Field Formatting

   (defun *error* ( msg )
       (LM:endundo (LM:acdoc))
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   ;; <Modified>
   (initget 6)
   (if (setq hgt (getdist (strcat "\nSpecify text height <" (rtos (getvar 'textsize)) ">: ")))
       (setvar 'textsize hgt)
       (setq hgt (getvar 'textsize))
   )
   ;; </Modified>

   (if
       (and
           (setq sel (ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))
           (setq ins (getpoint "\nPick Point for Field: "))
       )
       (progn
           (if (= 1 (sslength sel))
               (setq str
                   (strcat
                       "%<\\AcObjProp Object(%<\\_ObjId "
                       (LM:ObjectID (vlax-ename->vla-object (ssname sel 0)))
                       ">%).Area \\f \"" fmt "\">%"
                   )
               )
               (progn
                   (repeat (setq inc (sslength sel))
                       (setq lst
                           (vl-list*
                               "%<\\AcObjProp Object(%<\\_ObjId "
                               (LM:ObjectID (vlax-ename->vla-object (ssname sel (setq inc (1- inc)))))
                               ">%).Area>%" " + "
                               lst
                           )
                       )
                   )
                   (setq str
                       (strcat
                           "%<\\AcExpr "
                           (apply 'strcat (reverse (cdr (reverse lst))))
                           " \\f \"" fmt "\">%"
                       )
                   )
               )
           )
           (LM:startundo (LM:acdoc))
           (vla-put-height ;; mod
               (vla-addmtext
                   (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
                   (vlax-3D-point (trans ins 1 0))
                   0.0
                   str
               )
               hgt ;; mod
           ) ;; mod
           (LM:endundo (LM:acdoc))
       )
   )
   (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems

(defun LM:ObjectID ( obj )
   (eval
       (list 'defun 'LM:ObjectID '( obj )
           (if
               (and
                   (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                   (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
               )
               (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
              '(itoa (vla-get-objectid obj))
           )
       )
   )
   (LM:ObjectID obj)
)

;; Start Undo  -  Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
   (LM:endundo doc)
   (vla-startundomark doc)
)

;; End Undo  -  Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
   (while (= 8 (logand 8 (getvar 'undoctl)))
       (vla-endundomark doc)
   )
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
   (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (LM:acdoc)
)

(vl-load-com) (princ)

 

@Spaj, thank you for your responses + suggestions, appreciated.

Posted

Wow!

many Thanks Mr. Lee,

 

The modification improved the code. Make it better!

 

Regards

:notworthy:

  • 3 weeks later...
Posted

Hi guys,

How Can I put the text area only 2 decimal units?

 

I'd like to learn which part of the code I can do that.

Anybody Can teach me, please?

 

Best Regards

Posted
Hi guys,

How Can I put the text area only 2 decimal units?

 

I'd like to learn which part of the code I can do that.

Anybody Can teach me, please?

 

Best Regards

 

Change the LUPREC system variable to your desired one ;)

Posted

Thank for the quick replay Tharwat,

 

I'd like to put it inside the code. I mean always been 2 decimal units

Because I know how change it through LUPREC, but today I forgot to change it and I plot the wrong text.

:(

Posted
Thank for the quick replay Tharwat,

 

Because I know how change it through LUPREC, but today I forgot to change it and I plot the wrong text.

:(

 

No worries :D

 

Add the following line at the top of the routine and you'd get it equal to two all the time .

 

(setvar 'LUPREC 2)

Posted

I've already calculate all areas in my project with 2 decimal units.

But today when I opened the project, I didn't realize that LUPREC was 3 and plot the wrong area.

 

I was wondering if there is any way to lock the area showing always 2 decimal units.

 

Thank in advance

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