stlo Posted December 1, 2011 Posted December 1, 2011 Hi everyone, first of all I want to say that this site is very interesting! I started to work with Autocad since 1 year now! I'm am working in the granit countertops industry. I don't know a lot about lisp programs, I just discovered that it exist. My question is ... I would like to calculate the total square footage for every of my jobs! The fastest way for me would be to click on two dimensions and the next click would write the result where I click in the drawing (in square feet, for one piece). (I need to click on only 2 dimensions even if the pieces are crooked sometimes, it is because we multiply the maximum length by the maximum width of each pieces!) After that, I would re-click on two other dimensions and the next click would write the result in the drawing! After that, when I would press the space bar (meaning that there is no other piece to calculate), the program would ask me to click somewhere in the drawing and by doing so, it would write the total of every pieces I've calculated in that drawing (still in square feet)! Is that possible by clicking only on the DIMENSIONS and not on the lines or polylines! That would be a lisp program I guess but maybe it is possible to do that differently by using the standard tools? (I've attached an autocad drawing to show exactly what I need) Thanks! stlo surfacelisprequest.dwg Quote
Lee Mac Posted December 1, 2011 Posted December 1, 2011 Welcome to the forum stlo This was fun to write, hopefully it will help you: [color=GREEN];; Dimension Area - Lee Mac - 2011 - www.lee-mac.com[/color] [color=GREEN];; Displays the area calculated from the selection of two Dimensions in an[/color] [color=GREEN];; MText Field Expression using the formatting specified at the top of the code.[/color] ([color=BLUE]defun[/color] c:DimArea ( [color=BLUE]/[/color] *error* _SelectIf _ObjectID acdoc acspc d1 d2 fieldformatting msg predicate pt ) ([color=BLUE]setq[/color] fieldformatting [color=MAROON]"%lu2%ct4%qf1 SQ. FT."[/color]) [color=GREEN];; Field Formatting[/color] ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg) [color=MAROON]"*BREAK,*CANCEL*,*EXIT*"[/color])) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] _SelectIf ( msg pred ) ( ([color=BLUE]lambda[/color] ( f [color=BLUE]/[/color] e ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'ERRNO 0) ([color=BLUE]setq[/color] e ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] msg))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'ERRNO)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]eq[/color] 'ENAME ([color=BLUE]type[/color] e)) ([color=BLUE]if[/color] ([color=BLUE]and[/color] f ([color=BLUE]null[/color] (f e))) ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid Object."[/color]) ) ) ) ) ) e ) ([color=BLUE]eval[/color] pred) ) ) ([color=BLUE]setq[/color] acdoc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) acspc ([color=BLUE]vlax-get-property[/color] acdoc ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) 'paperspace 'modelspace)) ) ([color=BLUE]setq[/color] _ObjectID ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]lambda[/color] '( obj ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]vl-string-search[/color] [color=MAROON]"64"[/color] ([color=BLUE]getenv[/color] [color=MAROON]"PROCESSOR_ARCHITECTURE"[/color])) ([color=BLUE]vlax-method-applicable-p[/color] ([color=BLUE]vla-get-utility[/color] acdoc) 'getobjectidstring) ) ([color=BLUE]list[/color] '[color=BLUE]vla-getobjectidstring[/color] ([color=BLUE]vla-get-utility[/color] acdoc) 'obj '[color=BLUE]:vlax-false[/color]) '([color=BLUE]itoa[/color] ([color=BLUE]vla-get-objectid[/color] obj)) ) ) ) ) ([color=BLUE]setq[/color] predicate ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( x ) ([color=BLUE]and[/color] ([color=BLUE]eq[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] x ([color=BLUE]entget[/color] x)))) [color=MAROON]"DIMENSION"[/color]) ([color=BLUE]member[/color] ([color=BLUE]boole[/color] 4 ([color=BLUE]+[/color] 128 64 32) ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 x))) '(0 1)) ) ) ) ) ([color=BLUE]while[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] d1 (_SelectIf [color=MAROON]"\nSelect 1st Dimension <Exit>: "[/color] predicate)) ([color=BLUE]setq[/color] d2 (_SelectIf [color=MAROON]"\nSelect 2nd Dimension <Exit>: "[/color] predicate)) ([color=BLUE]setq[/color] pt ([color=BLUE]getpoint[/color] [color=MAROON]"\nPoint for Result <Exit>: "[/color])) ) ([color=BLUE]vla-addmtext[/color] acspc ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]trans[/color] pt 1 0)) 0.0 ([color=BLUE]strcat[/color] [color=MAROON]"%<\\AcExpr "[/color] [color=MAROON]"%<\\AcObjProp Object(%<\\_ObjId "[/color] (_ObjectID ([color=BLUE]vlax-ename->vla-object[/color] d1)) [color=MAROON]">%).Measurement>% * "[/color] [color=MAROON]"%<\\AcObjProp Object(%<\\_ObjId "[/color] (_ObjectID ([color=BLUE]vlax-ename->vla-object[/color] d2)) [color=MAROON]">%).Measurement>% "[/color] [color=MAROON]"\\f \""[/color] fieldformatting [color=MAROON]"\">%"[/color] ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Will display resultant area as a FIELD linked to the two selected Dimension measurements, formatted using the formatting code displayed at the top of the program. Lee Quote
stlo Posted December 2, 2011 Author Posted December 2, 2011 Oh wow!!! Thank you very much, this is amazing!!! I was looking for that since a while now! It's exactly what I was looking for! I guess if I want to change text size I have to ply in the field formatting area in the program? This is completely new to me, there is so much things to learn!!! Is there a way when I'm done calculating every single piece by pressing the space bar that the program would ask me to click where I want and it would give me the sum of all the pieces? Hey Thanks again, it is very useful!!! stlo Quote
stlo Posted December 2, 2011 Author Posted December 2, 2011 Sorry mistype .... play instead of ply Quote
Lee Mac Posted December 2, 2011 Posted December 2, 2011 Oh wow!!! Thank you very much, this is amazing!!! I was looking for that since a while now! It's exactly what I was looking for! I guess if I want to change text size I have to ply in the field formatting area in the program? This is completely new to me, there is so much things to learn!!! Is there a way when I'm done calculating every single piece by pressing the space bar that the program would ask me to click where I want and it would give me the sum of all the pieces? Hey Thanks again, it is very useful!!! Thanks, you're welcome The Textsize should be controlled by the value of your TEXTSIZE System Variable. As for summing the results, this is possible, but would take quite a bit more modification to the code. Lee Quote
stlo Posted December 2, 2011 Author Posted December 2, 2011 Instead of changing the code, is there a separate lisp that would calculate the sum of every field by clicking on each one, would that be easier? Maybe that code already exists? I just found a lisp that if we click on every dimensions, it is calculating the total of it, if we change the dimension for field, would it work? I not sure if it is that simple! Can you have a look at it? Thanks add dimensions.lsp Quote
stlo Posted December 2, 2011 Author Posted December 2, 2011 I just tried to look at the code and just realized that this is from you... You did that in 2010!!! I think that you are THE reference in lisp program, am I right!! Quote
Lee Mac Posted December 2, 2011 Posted December 2, 2011 I just tried to look at the code and just realized that this is from you... You did that in 2010!!! I think that you are THE reference in lisp program, am I right!! lol, I post too much Give this a try: [color=GREEN];; Add Fields - Lee Mac - 2011 - www.lee-mac.com[/color] [color=GREEN];; Creates an MText Field displaying the result of summing selected MText fields,[/color] [color=GREEN];; formatted using the field formatting code specified at the top of the program.[/color] [color=GREEN];; Selected fields must reference numerical data.[/color] ([color=BLUE]defun[/color] c:AddFields ( [color=BLUE]/[/color] _SelectIf fieldformatting fld fldexpr items mtx pos pt ) ([color=BLUE]setq[/color] fieldformatting [color=MAROON]"%lu2%ct4%qf1 SQ. FT."[/color]) [color=GREEN];; Field Formatting[/color] ([color=BLUE]defun[/color] _SelectIf ( msg pred ) ( ([color=BLUE]lambda[/color] ( f [color=BLUE]/[/color] e ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'ERRNO 0) ([color=BLUE]setq[/color] e ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] msg))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'ERRNO)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]eq[/color] 'ENAME ([color=BLUE]type[/color] e)) ([color=BLUE]if[/color] ([color=BLUE]and[/color] f ([color=BLUE]null[/color] (f e))) ([color=BLUE]princ[/color] [color=MAROON]"\nInvalid Object."[/color]) ) ) ) ) ) e ) ([color=BLUE]eval[/color] pred) ) ) ([color=BLUE]setq[/color] fldexpr [color=MAROON]"%<\\AcExpr "[/color] items 0 ) ([color=BLUE]while[/color] ([color=BLUE]setq[/color] mtx (_SelectIf [color=MAROON]"\nSelect Numerical MText Field: "[/color] ([color=BLUE]function[/color] ([color=BLUE]lambda[/color] ( x ) ([color=BLUE]and[/color] ([color=BLUE]eq[/color] [color=MAROON]"MTEXT"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] x)))) (LM:HasField-p x) ) ) ) ) ) ([color=BLUE]setq[/color] fld ([color=BLUE]vla-fieldcode[/color] ([color=BLUE]vlax-ename->vla-object[/color] mtx))) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] pos ([color=BLUE]vl-string-search[/color] [color=MAROON]"\\f"[/color] fld)) ([color=BLUE]setq[/color] fld ([color=BLUE]strcat[/color] ([color=BLUE]substr[/color] fld 1 pos) [color=MAROON]">%"[/color])) ) ([color=BLUE]setq[/color] fldexpr ([color=BLUE]strcat[/color] fldexpr fld [color=MAROON]" + "[/color]) items ([color=BLUE]1+[/color] items) ) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]<[/color] 0 items) ([color=BLUE]setq[/color] pt ([color=BLUE]getpoint[/color] [color=MAROON]"\nPoint for Result: "[/color])) ) ([color=BLUE]vla-addmtext[/color] ([color=BLUE]vlax-get-property[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) 'paperspace 'modelspace ) ) ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]trans[/color] pt 1 0)) 0.0 ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 items) ([color=BLUE]strcat[/color] ([color=BLUE]substr[/color] fldexpr 11 ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] fldexpr) 13)) [color=MAROON]" \\f \""[/color] fieldformatting [color=MAROON]"\">%"[/color]) ([color=BLUE]strcat[/color] ([color=BLUE]substr[/color] fldexpr 1 ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] fldexpr) 2)) [color=MAROON]"\\f \""[/color] fieldformatting [color=MAROON]"\">%"[/color]) ) ) ) ([color=BLUE]princ[/color]) ) [color=GREEN];; HasField-p - Lee Mac[/color] [color=GREEN];; Returns T if the supplied entity contains a Field Expression[/color] ([color=BLUE]defun[/color] LM:HasField-p ( en ) ([color=BLUE]and[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] en ([color=BLUE]entget[/color] en)))) [color=MAROON]"TEXT,MTEXT,ATTRIB"[/color]) ([color=BLUE]setq[/color] en ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 360 en))) ([color=BLUE]setq[/color] en ([color=BLUE]dictsearch[/color] en [color=MAROON]"ACAD_FIELD"[/color])) ([color=BLUE]setq[/color] en ([color=BLUE]dictsearch[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 en)) [color=MAROON]"TEXT"[/color])) ) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Not fully tested, so check the field expression that is being created as a result. Quote
stlo Posted December 3, 2011 Author Posted December 3, 2011 Right on! This is working perfectly!!! It's amazing! Thank you very much, I really appreciate it! It is way less complicated than transfer all the lenghts and widths into an excel calculating sheet! A lot of time saved! I have one more question (sorry, haha) In the ADD DIMENSION lisp (the original that you just modified) that I send you, is it possible to take the final result and divide it by 12 to have linear feet and to write the answer like the two lisp that you just created for me? Exemple 2.3453 (4 numbers after the dot) Thanks again! Incredebly useful!!!! stlo Quote
Lee Mac Posted December 3, 2011 Posted December 3, 2011 Right on! This is working perfectly!!! It's amazing! Thank you very much, I really appreciate it! It is way less complicated than transfer all the lenghts and widths into an excel calculating sheet! A lot of time saved! You're welcome I have one more question (sorry, haha) In the ADD DIMENSION lisp (the original that you just modified) that I send you, is it possible to take the final result and divide it by 12 to have linear feet and to write the answer like the two lisp that you just created for me? Exemple 2.3453 (4 numbers after the dot) Sorry, I didn't modify the 'Add Dimensions' program, I wrote the above from scratch - I suspect it requires a difference field formatting code with a conversion factor, but will see what I can do if I get some time. Lee Quote
Lee Mac Posted December 3, 2011 Posted December 3, 2011 Try something like this: [color=GREEN];; Add Dimensions - Lee Mac - 2011 - www.lee-mac.com[/color] [color=GREEN];; Creates an MText Field displaying the summation of selected Dimension values,[/color] [color=GREEN];; formatted using the field formatting code specified at the top of the program.[/color] ([color=BLUE]defun[/color] c:AddDims ( [color=BLUE]/[/color] *error* _ObjectID acdoc acspc fieldformatting fld pt spc ss ) ([color=BLUE]setq[/color] fieldformatting [color=MAROON]"%lu4"[/color]) [color=GREEN];; Field Formatting[/color] ([color=BLUE]defun[/color] *error* ( msg ) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] msg) [color=MAROON]"*BREAK,*CANCEL*,*EXIT*"[/color])) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nError: "[/color] msg)) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]setq[/color] acdoc ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) acspc (([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'CVPORT)) [color=BLUE]vla-get-paperspace[/color] [color=BLUE]vla-get-modelspace[/color]) acdoc) ) ([color=BLUE]setq[/color] _ObjectID ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]lambda[/color] '( obj ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]vl-string-search[/color] [color=MAROON]"64"[/color] ([color=BLUE]getenv[/color] [color=MAROON]"PROCESSOR_ARCHITECTURE"[/color])) ([color=BLUE]vlax-method-applicable-p[/color] ([color=BLUE]vla-get-utility[/color] acdoc) 'getobjectidstring) ) ([color=BLUE]list[/color] '[color=BLUE]vla-getobjectidstring[/color] ([color=BLUE]vla-get-utility[/color] acdoc) 'obj '[color=BLUE]:vlax-false[/color]) '([color=BLUE]itoa[/color] ([color=BLUE]vla-get-objectid[/color] obj)) ) ) ) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"*DIMENSION"[/color]))) ([color=BLUE]setq[/color] pt ([color=BLUE]getpoint[/color] [color=MAROON]"\nSpecify Point for Result: "[/color])) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] fld [color=MAROON]"%<\\AcExpr "[/color]) ([color=BLUE]vlax-for[/color] obj ([color=BLUE]setq[/color] ss ([color=BLUE]vla-get-activeselectionset[/color] acdoc)) ([color=BLUE]setq[/color] fld ([color=BLUE]strcat[/color] fld [color=MAROON]"%<\\AcObjProp Object(%<\\_ObjId "[/color] (_ObjectID obj) [color=MAROON]">%).Measurement>% + "[/color] ) ) ) ([color=BLUE]vla-addmtext[/color] acspc ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]trans[/color] pt 1 0)) 0.0 ([color=BLUE]strcat[/color] ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]vla-get-count[/color] ss)) ([color=BLUE]substr[/color] fld 11 ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] fld) 15)) ([color=BLUE]substr[/color] fld 1 ([color=BLUE]-[/color] ([color=BLUE]strlen[/color] fld) 3)) ) [color=MAROON]" \\f \""[/color] fieldformatting [color=MAROON]"\">%"[/color] ) ) ([color=BLUE]vla-delete[/color] ss) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) 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.