Jump to content

Help on Lee Mac's "Areas 2 Attribute"


shakuhachi

Recommended Posts

I've been using this neat routine for couple of months now. How can I change the output into "feet". I always divide the total with 144 to get the value in ft2. Thanks

 

;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:A2A nil (c:Areas2Attribute))

(defun c:Areas2Attribute ( / *error* _StartUndo _EndUndo doc att ss ) (vl-load-com)

 (defun *error* ( msg )
   (if doc (_EndUndo doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (defun _StartUndo ( doc ) (_EndUndo doc)
   (vla-StartUndoMark doc)
 )

 (defun _EndUndo ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
     (vla-EndUndoMark doc)
   )
 )

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (if
   (and (ssget '((0 . "ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE")))
     (setq att
       (LM:Selectif
         (lambda ( x ) (eq "ATTRIB" (cdr (assoc 0 (entget x))))) nentsel "\nSelect Attribute: "
       )
     )
   )
   (progn (_StartUndo doc)
     (
       (lambda ( ss fld )
         (vlax-for obj ss
           (setq fld
             (strcat fld "%<\\AcObjProp Object(%<\\_ObjId "
               (LM:GetObjectID doc obj) ">%).Area>% + "
             )
           )
         )          
         (vla-put-TextString (vlax-ename->vla-object att)
           (setq fld
             (strcat
               (substr fld 1
                 (- (strlen fld) (if (< 1 (vla-get-Count ss)) 3 5))
               )
               " \\f \"%lu6%qf1\">%"
             )
           )
         )
         (vla-delete ss) (vla-regen doc acActiveViewport)
       )
       (setq ss (vla-get-ActiveSelectionSet doc))
       (if (< 1 (vla-get-Count ss)) "%<\\AcExpr " "")
     )
     (_EndUndo doc)
   )
 )
 
 (princ)
)

;;---------------------=={ Select if }==----------------------;;
;;                                                            ;;
;;  Continuous selection prompts until the predicate function ;;
;;  foo is validated                                          ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  foo - optional predicate function taking ename argument   ;;
;;  fun - selection function to invoke                        ;;
;;  str - prompt string                                       ;;
;;------------------------------------------------------------;;
;;  Returns:  selected entity ename if successful, else nil   ;;
;;------------------------------------------------------------;;

(defun LM:Selectif ( foo fun str / e )
 (while
   (progn (setvar 'ERRNO 0) (setq e (car (fun str)))      
     (cond
       ( (= 7 (getvar 'ERRNO))

         (princ "\n** Missed, Try again **")
       )
       ( (eq 'ENAME (type e))

         (if (and foo (not (foo e)))
           (princ "\n** Invalid Object Selected **")
         )
       )
     )
   )
 )
 e
)

;;-------------------=={ Get ObjectID }==---------------------;;
;;                                                            ;;
;;  Returns the ObjectID string for the supplied VLA-Object   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  doc - VLA Document Object (req'd for 64-bit systems)      ;;
;;  obj - VLA Object to query                                 ;;
;;------------------------------------------------------------;;
;;  Returns:  ObjectID string for VLA-Object                  ;;
;;------------------------------------------------------------;;

(defun LM:GetObjectID ( doc obj )
 (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
   (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
   (itoa (vla-get-Objectid obj))
 )
)

Edited by shakuhachi
Link to comment
Share on other sites

  • 6 years later...

Dear Lee,

current version v1-2 does work fine on polylines, but does not work in the attribute TAG option: lisp does not allow me to select blocks with predefined by me attribute "POW", unless I have added "INSERT" to the first setq filter, like below:

(ssget '((0 . "INSERT,ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))

 

...then lisp permits to pick blocks, fine, but when it comes to insert sum into the other attributed block, the sum equals "####". When I look up resulting filed formatting it is a sum of Objects "Block Unit" and not the tag in out case "POW". Lisp picks wrong object property, please correct me where I went wrong.

 

Best regards mate!

Link to comment
Share on other sites

Dear Lee,

current version v1-2 does work fine on polylines, but does not work in the attribute TAG option: lisp does not allow me to select blocks with predefined by me attribute "POW", unless I have added "INSERT" to the first setq filter, like below:

(ssget '((0 . "INSERT,ARC,CIRCLE,ELLIPSE,HATCH,*POLYLINE,REGION,SPLINE"))))

 

I think you have misunderstood how the program operates:

The 'tag' parameter allows you to specify a predefined attribute tag to house the output from the program - you should not modify the ssget filter which is used to obtain the input.

  • Like 1
Link to comment
Share on other sites

Hello Lee!

Thanks for quick replay! In beginning I thought, and sorry my bad, that lisp as an option served to withdraw numeric data from predefined attribute, and then insert the formula sum of that attribute values into the other block attribute picked form list of its attributes.

 

And you see, with the proposed addition of INSERT in ssget line, it almost does the job! :) I believe it is sooooo close!

Could you please try to adjust your program to accept blocks, so in case of blocks it ads the predefined TAG, not the first appearing Object property "Block Units"?

 

That would be very very neat and useful program of yours, don't you agree? Pleeeeease o:)

Cheers Lee!

Link to comment
Share on other sites

May I ask you to explain, how to to change the subfunctions of yours, to adopt this program to the described functionality? To learn from you would be even better approach here, as we are at cadtutor :) Years pass, and I have only basic understanding of lisp programming.

Link to comment
Share on other sites

  • 4 years later...

Hello Lee Mac,

  I know this post is nearly 5 years old, but I thought I'd try anyway.

I'm using your Areas2AttributeV1-2.lsp and it works great, especially adding the total to an attribute, but it's not quite what I need.

I'd like to be able to ADD one polyline, such as a building outline, then SUBTRACT multiple polylines, such as staircases and elevators.

Any help you can provide would be much appreciated.

  Thank you very much.

Link to comment
Share on other sites

  • 2 months later...

I'm checking back in on this thread.
 This LISP works great, but would like the option to ADD one polyline, such as a building outline, then SUBTRACT multiple polylines, such as staircases and elevators.

Thank you.😀

Link to comment
Share on other sites

This was answered in another post maybe on another forum. You can have a room say with say  columns and get floor area.

 

Anyway the simple answer is if you can make a hatch that reflects the correct shape then you can get the area, so would need to edit Lee's code to pick a hatch rather than a pline.

 

image.thumb.png.465d5659e403be6042ad14f5d6d14165.png

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you BIGAL for the response.  I hadn't thought of selecting hatch rather than a polyline.  This seems to solve my question, from a certain point of view :)

 

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