GMANSQUARE Posted August 20, 2007 Posted August 20, 2007 Is there anyway to utilize the field command using lisp, I have a program that draws a rectangle or pline and outs the area inside the room. I would like to have the lisp program put the area from the field, but evertime I try, it opens up the dialog box, Quote
Hedgehog Posted August 20, 2007 Posted August 20, 2007 Not sure, but the Field command is just a collection of data available elsewhere amongst the system variables & settings... the Area command works fine or use Setvar/Area & it gives out a read only figure. HTH Quote
pefi Posted August 20, 2007 Posted August 20, 2007 Hi, You may access area directly... (defun c:GetArea(/) (vl-load-com) (vla-Get-Area (vlax-ename->vla-object (car (entsel)))) ) Przemo Quote
fixo Posted August 20, 2007 Posted August 20, 2007 Here is lisp I wrote for one guy from another forum, it will label plines with fields in sq. meters Not a big problem to convert them accordingly to your units and precision tested on A2007eng only ;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:laf (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (setq ins (getvar "insunits")) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setvar "insunits" 4) ; displayed in meters to 3 decimal place. (setq txt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ) ) ; add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, default = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need (decimal) ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (setvar "insunits" ins) (princ) ) (princ "\n Type LAF to label objects with area field") (princ) ~'J'~ Quote
redsand Posted January 12, 2008 Posted January 12, 2008 I am relatively new to lisp routines and I have been searching for some time now for a lisp the does exactly what you have created below....except I have no idea how to modify this to give me sq ft as a text output. can you possibly give me any suggestions or pointers to do this? Thanks Redsand Here is lisp I wrote for one guy fromanother forum, it will label plines with fields in sq. meters Not a big problem to convert them accordingly to your units and precision tested on A2007eng only ;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:laf (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (setq ins (getvar "insunits")) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setvar "insunits" 4) ; displayed in meters to 3 decimal place. (setq txt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ) ) ; add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, default = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need (decimal) ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (setvar "insunits" ins) (princ) ) (princ "\n Type LAF to label objects with area field") (princ) ~'J'~ Quote
fixo Posted January 13, 2008 Posted January 13, 2008 Try this instead ;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:laf (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setq txt ; displayed in meters to 3 decimal place: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ;;; ) ; displayed in engineering to 2 decimal place: (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%pr2%lu2%ct4%qf1\">%");<--pr2 means 2 decimal places, change to your suit ; displayed in engineering to 2 decimal place with addition SQ. FT.: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%") ) ; add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, optional = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (princ) ) (princ "\n Type LAF to label objects with area field") (princ) ~'J'~ Quote
redsand Posted January 13, 2008 Posted January 13, 2008 That is exactly what I need but I do have one other question....actually two. One - how can I get the sqft at the end of my area number. Two - where can I go to get more information on how lisp actually works and how the notation is set up. thanks alot redsand Quote
fixo Posted January 13, 2008 Posted January 13, 2008 Use this one that was commented in my post above: (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%") Sorry I can't explain you more because of my poor English Hope somebody else will do it I finished my work on today, we have here The Old New Year by our russian tradition ~'J'~ Quote
nejcek Posted November 6, 2008 Posted November 6, 2008 I was using similar method found in this thread: h t t p://discussion.autodesk.com/forums/thread.jspa?threadID=484315* which I change to work with my own block with fields. But since I started to use autocad 2009 I am not able to use it: I am also not able to use lisp shown above. Instead of numbers where should be area I get #### Does anybody knows what is the problem? *as I am a new user I am unable to insert links Quote
Xsoldier2000 Posted August 26, 2009 Posted August 26, 2009 ...which I change to work with my own block with fields. But since I started to use autocad 2009 I am not able to use it: I am also not able to use lisp shown above. Instead of numbers where should be area I get #### Does anybody knows what is the problem? +1 I have searched and searched for this, and thought I might be the only one. Are you using the x64 version of AutoCad? This seems to be the problem for me. Anyone know why this won't work for AutoCad 2009 (64 bit)? I will post my lisp. AreaLAF.lsp Quote
Xsoldier2000 Posted August 27, 2009 Posted August 27, 2009 It is working again in 2010. Well, the lisp works correctly in 2009, 32 bit. Are you using 2010 (64 bit)? Quote
Mattinahat Posted April 5, 2010 Posted April 5, 2010 Hello all, I've been browsing this forum for about a week and I've found this thread particularly helpful. The lisp file is invaluable; however, there is just one tweak I am trying to make but I'm unsure of how to go about. I was hoping to be able to have a popup dialog for text height instead of a set height. Either part of the previous 'laf' lisp file or even separately to resize all text in the drawings. Thanks in advanced! p.s. I know this thread is old, but I"m hoping someone can just take a quick look back for me! Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 Hi, Would this help you? I could update it if necessary http://www.cadtutor.net/forum/showpost.php?p=311693&postcount=20 Quote
Mattinahat Posted April 12, 2010 Posted April 12, 2010 wow thanks for the quick response! Sorry for my delay; and ya thats what i've been trying to do, but the only information I need is area which makes it even simpler. This is what I've been using: ;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:laf (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setq txt ; displayed in meters to 3 decimal place: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ;;; ) ; displayed in engineering to 2 decimal place: (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%pr0%lu2%ct8[0.006944444444444444]%qf1\">%");<--pr0 means 0 decimal places, change to your suit ; displayed in engineering to 2 decimal place with addition SQ. FT.: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%") ) ; add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, optional = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (princ) ) (princ "\n Type LAF to label objects with area field") (princ) Although, your code works great too! So I guess what I need help updating is recieving a prompt for text height where I can punch in a number instead of relying on the drawings default scale. Thanks for all your help! Quote
Lee Mac Posted April 12, 2010 Posted April 12, 2010 Try this: (defun c:GetA (/ *error* lst->str DOC IDS PT SS UFLAG UTIL) (vl-load-com) ;; Lee Mac ~ 18.03.10 (defun *error* (msg) (and uFlag (vla-EndUndomark doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun lst->str (lst d1 d2) (if (cdr lst) (strcat d1 (car lst) d2 (lst->str (cdr lst) d1 d2)) (strcat d1 (car lst)))) (defun GetObjectID (obj) (setq util (cond (util) ((vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object)))))) (if (vl-string-search "X64" (strcase (getvar 'PLATFORM))) (vlax-invoke-method util 'GetObjectIdString obj :vlax-false) (itoa (vla-get-Objectid obj)))) (princ "\nSelect Objects to Retrieve Total Area...") (if (and (ssget '((0 . "CIRCLE,ARC,ELLIPSE,HATCH,REGION,LINE,*POLYLINE"))) (setq hg (cond ((getdist (strcat "\nSpecify Text Height <" (rtos (getvar 'TEXTSIZE)) "> : "))) ((getvar 'TEXTSIZE)))) (setq pt (getpoint "\nPick Point for Field: "))) (progn (setq uFlag (not (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))))) (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc)) (setq Ids (cons (GetObjectID Obj) Ids))) (vla-delete ss) (vla-put-height (vla-AddMText (if (or (eq AcModelSpace (vla-get-ActiveSpace doc)) (eq :vlax-true (vla-get-MSpace doc))) (vla-get-ModelSpace doc) (vla-get-PaperSpace doc)) (vlax-3D-point pt) 0. (if (= 1 (length Ids)) (strcat "Area: %<\\AcObjProp Object(%<\\_ObjId " (car Ids) ">%).Area \\f \"%lu6%qf1\">%") (strcat "Area: %<\\AcExpr" (lst->str Ids " %<\\AcObjProp Object(%<\\_ObjId " ">%).Area >% +") ">%).Area >% \\f \"%lu6%qf1\">%"))) hg) (setq uFlag (vla-EndUndomark doc)))) (princ)) Quote
alanjt Posted April 12, 2010 Posted April 12, 2010 (setq height (getdist "\nSpecify text height: ")) wow thanks for the quick response! Sorry for my delay; and ya thats what i've been trying to do, but the only information I need is area which makes it even simpler. This is what I've been using: ;; local defun ;; get center of closed object (defun getcenter (obj / acsp cen rgn) (setq acsp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) rgn (car (vlax-invoke acsp 'Addregion (list obj))) cen (vlax-get rgn 'Centroid) ) (vla-delete rgn) cen ) ;; main part ;; label [plines w]/area field in sq. meters (defun c:laf (/ acsp adoc axss cpt ins ss txt mtxtobj) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object) ) ) ) (or acsp (setq acsp (vla-get-modelspace adoc ) ) ) (if (setq ss (ssget (list (cons 0 "*POLYLINE,*CONTOUR")))) (progn (setq axss (vla-get-activeselectionset adoc)) ;; iterate through the active selection set collection (vlax-for obj axss ; get a curve center (setq cpt (trans (getcenter obj) 0 1)) (setq txt ; displayed in meters to 3 decimal place: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%lu2%pr3%ps[, m2]%ct8[1e-006]\">%" ;;; ) ; displayed in engineering to 2 decimal place: (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get obj 'ObjectID)) ">%).Area \\f \"%pr0%lu2%ct8[0.006944444444444444]%qf1\">%");<--pr0 means 0 decimal places, change to your suit ; displayed in engineering to 2 decimal place with addition SQ. FT.: ;;; (strcat "%<\\AcObjProp Object(%<\\_ObjId " ;;; (itoa (vlax-get obj 'ObjectID)) ;;; ">%).Area \\f \"%pr2%lu2%ct4%qf1 SQ. FT.\">%") ) ; add mtext object to model space (setq mtxtobj (vlax-invoke acsp 'AddMText cpt ;insertion point 0.0 ; mtext width, optional = 0 txt ;string (field value) )) ; change mtext height accordingly to current dimension style text height: (vlax-put mtxtobj 'Height (getvar "dimtxt")); change (getvar "dimtxt") on text height you need ; set justifying to middle center (vlax-put mtxtobj 'AttachmentPoint acAttachmentPointMiddleCenter) ) ) ) (vla-regen adoc acactiveviewport) (princ) ) (princ "\n Type LAF to label objects with area field") (princ) Although, your code works great too! So I guess what I need help updating is recieving a prompt for text height where I can punch in a number instead of relying on the drawings default scale. Thanks for all your help! Quote
Recommended Posts
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.