RyanAtNelco Posted August 21, 2009 Share Posted August 21, 2009 Hello, I am looking for a macro or lisp routine that allows me to insert a field in a text box that automatically takes a dimension's measurement. I am looking to skip all the dialouge boxes that go along with inserting fields. Any help would be great, Thanks! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 Something like this? (defun c:dimF (/ ent txt) (vl-load-com) (and (setq ent (car (entsel "\nSelect Dimension: "))) (eq "DIMENSION" (cdr (assoc 0 (entget ent)))) (setq txt (M-Text '(0 0 0) (strcat "%<\\AcObjProp Object(%<\\_ObjId " (vl-princ-to-string (vla-get-ObjectId (vlax-ename->vla-object ent))) ">%).Measurement \\f \"%lu2\">%"))) (command "_.move" txt "" '(0 0 0) pause)) (princ)) (defun M-Text (pt val) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 val)))) Quote Link to comment Share on other sites More sharing options...
RyanAtNelco Posted August 21, 2009 Author Share Posted August 21, 2009 I can make that one work, but is there a way to insert it into an existing mleader and/or mtext. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 Like this? (defun c:dimF (/ ent dtxt) (vl-load-com) (and (setq ent (car (entsel "\nSelect Dimension: "))) (eq "DIMENSION" (cdr (assoc 0 (entget ent)))) (setq dtxt (car (entsel "\nSelect Destination: "))) (wcmatch (cdr (assoc 0 (entget dtxt))) "*TEXT,MULTI*") (vla-put-TextString (vlax-ename->vla-object dtxt) (strcat "%<\\AcObjProp Object(%<\\_ObjId " (vl-princ-to-string (vla-get-ObjectId (vlax-ename->vla-object ent))) ">%).Measurement \\f \"%lu2\">%"))) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 21, 2009 Share Posted August 21, 2009 Like this? (defun c:dimF (/ ent dtxt) (vl-load-com) (and (setq ent (car (entsel "\nSelect Dimension: "))) (eq "DIMENSION" (cdr (assoc 0 (entget ent)))) (setq dtxt (car (entsel "\nSelect Destination: "))) (wcmatch (cdr (assoc 0 (entget dtxt))) [color=Red]"*TEXT,MULTI*"[/color]) (vla-put-TextString (vlax-ename->vla-object dtxt) (strcat "%<\\AcObjProp Object(%<\\_ObjId " (vl-princ-to-string (vla-get-ObjectId (vlax-ename->vla-object ent))) ">%).Measurement \\f \"%lu2\">%"))) (princ)) laaaazy, lol Quote Link to comment Share on other sites More sharing options...
RyanAtNelco Posted August 21, 2009 Author Share Posted August 21, 2009 Lee, This works with the exception that it erases the previous text when i select the destination and replaces it. I would like to just insert it either on the end or beginning of an existing text string. Also, is it difficult to make one version for decimal dimension with a precision of 0.00 and one version for fractional with a precision of 1/16? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 Alan> Lazy indeed, after all why type "leader" when I can just type "*"... Ryan> Yes it replaces the text - how would I know whether you wanted it at the beginning or end :geek: ? Different positions can indeed be incorporated just by altering the field string. Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 21, 2009 Share Posted August 21, 2009 Alan> Lazy indeed, after all why type "leader" when I can just type "*"... Ryan> Yes it replaces the text - how would I know whether you wanted it at the beginning or end :geek: ? Different positions can indeed be incorporated just by altering the field string. oh, i know. i just wanted to poke fun. however, you should stray from "*TEXT" because rtext can be selected, and doesn't work the same way as text and mtext. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 oh, i know. i just wanted to poke fun. however, you should stray from "*TEXT" because rtext can be selected, and doesn't work the same way as text and mtext. oh good point sir Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 21, 2009 Share Posted August 21, 2009 oh good point sir always happy to nit pick. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2009 Share Posted August 21, 2009 always happy to nit pick. Sure, no worries... I'm sure I can return the favour Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 21, 2009 Share Posted August 21, 2009 Sure, no worries... I'm sure I can return the favour lol, i think you just accomplished it when the entmakeX. Quote Link to comment Share on other sites More sharing options...
mdbdesign Posted October 22, 2014 Share Posted October 22, 2014 (edited) Five years later... Lee, one question: is possible to update this routine to work with attribute (field) in BOM? Need to create something that will read: largest dimension (horizontal) and largest dimension (vertical) and write value in to selected attribute(s). Attaching sample dwg with "CUT SIZE:" row that contain attribute with manually inserted two fields separated with "x". It works, but, each time drawing is created, need to repeat all procedure to link field with dimension. Perfectly, I imagine it work like that: ############ -...magic is looking for largest horizontal and vertical dimension -hard coded destination to tag name attribute -done. ############ or ############ -select first dimension -select second dimension -select destination attribute ...magic, magic, magic -done. ############ (sorry wrapping not working) Thank you. FIELD TEST.dwg Edited October 22, 2014 by mdbdesign try to wrap.... Quote Link to comment Share on other sites More sharing options...
mdbdesign Posted October 28, 2014 Share Posted October 28, 2014 I know it is not very nice but: bump Quote Link to comment Share on other sites More sharing options...
capocad Posted May 15, 2018 Share Posted May 15, 2018 When I try to use this routine, all I get in MTEXT is "####". Will it have something to do with the new version of autocad? I am using AutoCAD 2018. The field content is "% %). Measurement \ f"% lu2 ">%" when I think it should be something like "% %). Measurement \ f "% lu2">% " #s3gt_translate_tooltip_mini { display: none !important; } Quote Link to comment Share on other sites More sharing options...
ronjonp Posted May 15, 2018 Share Posted May 15, 2018 Use Lee's updated version of lm:getobjectid from HERE. You'll also need to include lm:acdoc as well. Quote Link to comment Share on other sites More sharing options...
capocad Posted May 15, 2018 Share Posted May 15, 2018 Thank you ronjonp! I do not know anything about lisp, but touching the code a bit, I managed to make it work. I attach the routine in case someone finds it useful. All the credit for Lee Mac. dimf.lsp Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2018 Share Posted May 15, 2018 You'll also need my LM:ename->objectid and LM:hex->decstr functions if you are working in AutoCAD 2008 64-bit (which doesn't support the getobjectidstring method). Quote Link to comment Share on other sites More sharing options...
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.