Andy0902 Posted March 30, 2011 Posted March 30, 2011 (edited) Hello, I was wondering if I could use a LISP or macro of some kind to do the following task... I have to take the area of a rectangle Convert it to SqMetres Multiply by a number(different every time) Then type the given answer inside the rectangle This task is for mezzanine floor column loadings onto the floor slab. There are usually many columns with different loading areas. Something like this could save me a lot of time. Could any body advise me that this is possible. I'm completely new at macro's, VBA and LISP, but willing to learn. I'm using Autocad 2007 predominantly but also use 2010 on another machine. Thanks in advance. All the best Andy EDIT - I found half of the required code here - http://www.cadtutor.net/forum/showthread.php?57782-Area-Lisp-Routine-error-in-Autocad-2011-and-Win-7-64bit Edited March 30, 2011 by Andy0902 Quote
SOliver Posted March 30, 2011 Posted March 30, 2011 (vl-load-com) (defun c:ccc ( / ) (setq ms (vla-get-modelspace(vla-get-activedocument(vlax-get-acad-object)))) (setq poly(entsel "\nSelect polyline:")) (setq rec(entsel "Select rectangle for text")) (setq poly (vlax-ename->vla-object (car poly))) (setq rec (vlax-ename->vla-object (car rec))) (setq area(/(vla-get-area poly) 1000000)) (setq textStartPoint(vla-get-coordinate rec 0)) (setq textSecondPoint (vla-get-coordinate rec 1)) (setq width (abs (- (nth 0(vlax-safearray->list(vlax-variant-value textSecondPoint)) ) (nth 0 (vlax-safearray->list(vlax-variant-value textStartPoint)) )))) (setq height (* 0.25(abs (- (nth 0(vlax-safearray->list(vlax-variant-value textSecondPoint)) ) (nth 0 (vlax-safearray->list(vlax-variant-value textStartPoint)) ))))) (setq textStartPoint(append (vlax-safearray->list(vlax-variant-value textStartPoint))(list 0.0))) (setq mText (vla-addMtext ms (vlax-3d-point textStartPoint) width (rtos area 2 2)) ) (vla-put-height mText height) ) The above code should give you an idea of how to go about what you're trying to achieve. While for all intensive purposes this code works please don't use it as production, it's literally just a poorly conceived list of actions solely to provide you with some starting ground for writing the awesome version. For what it's worth it gave me something to do during my coffee break lol. Quote
Andy0902 Posted March 30, 2011 Author Posted March 30, 2011 Thanks very much SOliver I'll give that a go. Quote
SOliver Posted March 30, 2011 Posted March 30, 2011 You're welcome. Because I'm too lazy to include it I'd recommend using while statements with embedded conditional statements around the select entities methods otherwise the remaining code will fail if you accidentally miss the item you are selecting. [EDIT} Too lazy, but apperently to obsessive about coding my words. For example (while (= poly nil) (select poly (entsel "\nSelect polyline:")) (if(= poly nil) (princ "\nPolyline not selected")) ) ) (while (= rec nil) (select poly (entsel "\nSelect rectangle for text:")) (if(= rec nil) (princ "\nRectangle not selected")) ) ) Remember to localise your variables or it'll only work once lol [code c:localise ( / .. ..) ;CODE ) Quote
SOliver Posted March 30, 2011 Posted March 30, 2011 (edited) Doesn't seem to work (gives 0)? Hmm that's strange I've tried it here prior to posting. What units are you using metres, millimetres etc? The above is set for millimetres If you're working with metres ;Replace (setq area(/(vla-get-area poly) 1000000)) ;With (setq area(vla-get-area poly)) Edited March 30, 2011 by SOliver Typo Quote
Andy0902 Posted March 30, 2011 Author Posted March 30, 2011 Works great for typing the SqM. I'll be able to figure out the rest. Much appreciated. I think this has kick started me writing my own/more LISP routines. I'm sat dreaming of all the possibilities Quote
SOliver Posted March 30, 2011 Posted March 30, 2011 Works great for typing the SqM. I'll be able to figure out the rest. Much appreciated. I think this has kick started me writing my own/more LISP routines. I'm sat dreaming of all the possibilities No problem just to round it off 'cause I forgot it (strcat (rtos area 2 2) "SqM") That'll add the "SqM to the string; you may want to decrease the height value though. Quote
SOliver Posted March 30, 2011 Posted March 30, 2011 (edited) Why not use a field? I agree. An attribute would be better for future use. Edited March 30, 2011 by SOliver Typo Quote
Lee Mac Posted March 30, 2011 Posted March 30, 2011 (edited) Simplifying the code I posted here: (defun c:AreaField ( / LM:Select LM:GetObjectID acdoc acspc e i p ) (vl-load-com) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)) acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace)) ) (defun LM:Select ( msg pred fun / e ) (setq pred (eval pred)) ;; © Lee Mac 2011 (while (progn (setvar 'ERRNO 0) (setq e (car (fun msg))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\n** Missed, Try again **") ) ( (eq 'ENAME (type e)) (if (and pred (not (pred e))) (princ "\n** Invalid Object Selected **") ) ) ) ) ) e ) (defun LM:GetObjectID ( doc obj ) ;; © Lee Mac 2011 (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false) (itoa (vla-get-Objectid obj)) ) ) (if (and (setq e (LM:Select "\nSelect Object to Retrieve Area: " (function (lambda ( x ) (vlax-property-available-p (vlax-ename->vla-object x) 'Area)) ) entsel ) ) (setq p (getpoint "\nSpecify Point for Field: ")) ) (vla-AddText acspc (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId " (LM:GetObjectID acdoc (vlax-ename->vla-object e)) ">%).Area \\f \"%lu6%qf1%ps[, m²]%ct8[1e-006]\">%" ) (vlax-3D-point (trans p 1 0)) (getvar 'TEXTSIZE) ) ) (princ) ) Or there's this or this from my site. Edited March 30, 2011 by Lee Mac Quote
Andy0902 Posted March 30, 2011 Author Posted March 30, 2011 Thanks Lee! Your website is full of great LISP's. I especially like the slinky text. Quote
Lee Mac Posted March 30, 2011 Posted March 30, 2011 Your website is full of great LISP's. I especially like the slinky text. Thanks Andy, I enjoyed writing that one too Quote
amarcon Posted March 31, 2011 Posted March 31, 2011 Lee , this command is useful, however, what if you need to subtract an area. For example a floor plan with a stairwell hole in it? Your commands sum areas well, but how can we deal with an overall area with 'holes'? Quote
Lee Mac Posted March 31, 2011 Posted March 31, 2011 Lee , this command is useful, however, what if you need to subtract an area. For example a floor plan with a stairwell hole in it?Your commands sum areas well, but how can we deal with an overall area with 'holes'? How about something like the attached: Areas2Field2.lsp Quote
amarcon Posted March 31, 2011 Posted March 31, 2011 Great work as usual Lee, exactly what I need :wink: I will replace my old 'region' based routines with this. Creating a field is brilliant. Thanks for your time and expertise Quote
Lee Mac Posted April 1, 2011 Posted April 1, 2011 You're very welcome Amarcon, I enjoyed writing this one Glad it helps! 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.