Manila Wolf Posted January 9, 2015 Share Posted January 9, 2015 That very helpful chap Lee Mac compiled a very good lisp for me called Dim2Att. (See Code below). It links a dimension text to an attribute as a field. Can this lisp be easily modified to link a dimension text to a 2nd dimension text as a field? Hopefully Lee or indeed somebody else may be able to help. This process can be done manually in the following way, but a lisp would of course be so much quicker: - 1. Using "DDEDIT" select your target dim. 2. DELETE the original text (the dimension value). 3. Click the "Insert Field" button or press "Ctrl F". 4. Under field category choose "Objects" and under field names choose "Object". 5. Under object type, Select your source dimension. 6. Under property, choose "Measurement". 7. Under format chose "Current Units". 8. Under additional format, choose to "Suppress trailing Zero's". ;; Link Dimension to Attribute - Lee Mac ;; Prompts for selection of a Dimension and references the Dimension ;; value using a Field located in a selected block attribute. ;; http://www.cadtutor.net/forum/showthread.php?66989-Highligting-a-selection&highlight=dim2att.lsp ;; Minor mod by Mark D to suppress trailing Zero's (defun c:Dim2Att ( / *error* ad at el en g1 g2 gr ms ob p1 st ) (defun *error* ( msg ) (if en (redraw en 4)) (if ad (vla-endundomark ad)) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (redraw) (princ) ) (while (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect Dimension to Link: "))) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, try again.") ) ( (eq 'ENAME (type en)) (if (not (wcmatch (cdr (assoc 0 (entget en))) "*DIMENSION")) (princ "\nObject is not a Dimension.") ) ) ) ) ) (if en (progn (setq ad (vla-get-activedocument (vlax-get-acad-object)) el (entget en) p1 (trans (cdr (assoc 11 el)) en 1) ob (vlax-ename->vla-object en) st (strcat "%<\\AcObjProp Object(%<\\_ObjId " (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-method-applicable-p (vla-get-utility ad) 'getobjectidstring) ) (vla-getobjectidstring (vla-get-utility ad) ob :vlax-false) (itoa (vla-get-objectid ob)) ) (if (eq "" (cdr (assoc 1 el))) ;">%).Measurement \\f \"%lu6\">%" ">%).Measurement \\f \"%lu6%zs8\">%"; <<< This line repaces the line above to suppress trailing Zero's - By Mark D. ">%).TextOverride>%" ) ) ) (vla-startundomark ad) (redraw en 3) (princ (setq ms "\nSelect Attribute to Link to Dimension: ")) (while (progn (setq gr (grread t 13 2) g1 (car gr) g2 (cadr gr) ) (cond ( (= 5 g1) (redraw) (grdraw p1 g2 3 1) t ) ( (= 3 g1) (redraw) (if (setq at (car (nentselp g2))) (if (eq "ATTRIB" (cdr (assoc 0 (entget at)))) (progn (vla-put-textstring (vlax-ename->vla-object at) st) (vl-cmdf "_.updatefield" at "") (princ ms) ) (princ (strcat "\nObject is not an Attribute." ms)) ) (princ (strcat "\nMissed, try again." ms)) ) t ) ) ) ) (redraw en 4) (redraw) (vla-endundomark ad) ) ) (princ) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
pBe Posted January 9, 2015 Share Posted January 9, 2015 (edited) To clarify, You are wanting to override the dimension value of a dimension entity with a field value from another dimension? ..Missing variable AD... see post#4 for updated code Edited January 10, 2015 by pBe Quote Link to comment Share on other sites More sharing options...
Manila Wolf Posted January 10, 2015 Author Share Posted January 10, 2015 Hi pBe, Thanks for responding. Rather than try and explain in words, I created a quick sample drawing to try and explain the requirement more clearly. See the attached drawing "Dim2Dim" On the drawing, Detail A shows what I am hoping to achieve. Detail B shows a possible but more cumbersome method of achieving the same end result. There are various others ways to achieve a result i.e. Exploding dims, using a Dynamic block or with multiple viewports, but I am trying to simplify the process as much as possible. Dim2Dim.dwg Quote Link to comment Share on other sites More sharing options...
pBe Posted January 10, 2015 Share Posted January 10, 2015 (edited) Oh i see, for one thing there's a missing variable on the code i posted. First, the dimension style OBLIQUE needs to change to "0" precision at "Primary units" tab on Dimstyle to get rid of the decimal values. ... writing code.. Try this code, then we will do a code clean-up after you give the A-OK. Edited January 10, 2015 by pBe Quote Link to comment Share on other sites More sharing options...
Manila Wolf Posted January 10, 2015 Author Share Posted January 10, 2015 Hi pBe, Wow...Nearly there I think. Thank you. I did change one line of the code and it seems to work very well. The precision problem has gone away after this change. The line I changed is now: - ">%).Measurement \\f \"%lu6%zs8\">%" I am wondering if the "rubber band" affect that is in Dim2Att.lsp can be incorporated into this one? Cheers. (defun c:demo ( / en target ad el p1 ob ad) (while (and (setq en (car (entsel "\nSelect Source Dimension Value:"))) (setq target (car (entsel "\nSelect Target Dimension Value:"))) ) ;;; snippet from LM c:Dim2Att ;;; (setq ad (vla-get-activedocument (vlax-get-acad-object)) el (entget en) p1 (trans (cdr (assoc 11 el)) en 1) ob (vlax-ename->vla-object en)) (setq st (strcat "%<\\AcObjProp Object(%<\\_ObjId " (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE") ) (vlax-method-applicable-p (vla-get-utility ad) 'getobjectidstring ) ) (vla-getobjectidstring (vla-get-utility ad) ob :vlax-false ) (itoa (vla-get-objectid ob)) ) (if (eq "" (cdr (assoc 1 el))) ">%).Measurement \\f \"%lu6%zs8\">%";<<<<<[b]AMENDED HERE[/b] ">%).TextOverride>%" ) ) ) (setq target (vlax-ename->vla-object target)) (vla-put-TextOverride target st) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted January 10, 2015 Share Posted January 10, 2015 Hi pBe, Wow...Nearly there I think. Thank you. I did change one line of the code and it seems to work very well. The precision problem has gone away after this change. The line I changed is now: - ">%).Measurement \\f \"%lu6%zs8\">%" Good for you Manila Wolf I am wondering if the "rubber band" affect that is in Dim2Att.lsp can be incorporated into this one? Also, can a "Regen" be incorprated at the end of the code? Cheers. Yes we can do that. Question: will there be more two or more "link" to one dimension value similar to LM_Dim2Att ? or one pair at a time? Quote Link to comment Share on other sites More sharing options...
Manila Wolf Posted January 10, 2015 Author Share Posted January 10, 2015 Thanks pBe, I really appreciate your help. For this lisp I envisage only linking one pair of dims at each run. Many thanks. Quote Link to comment Share on other sites More sharing options...
pBe Posted January 10, 2015 Share Posted January 10, 2015 Thanks pBe, I really appreciate your help. For this lisp I envisage only linking one pair of dims at each run. Many thanks. OK, hang on... Quote Link to comment Share on other sites More sharing options...
Jhun Posted September 16, 2020 Share Posted September 16, 2020 I'm a newbie in AutoLisp. How can I save your lisp to work on my PC? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 17, 2020 Share Posted September 17, 2020 Open Notepad copy the lisp from here then paste into notepad. Save as say Dimtxtlink.lsp note the .lsp as file name not txt. You need to save some where you can find it. I suggest a directory like c:\Mylisps. You can use Appload to load the program, a menu or toolbar to load, drag and drop from windows explorer. To make life easier in Autocad you can use shorthand version for loading a lisp as Autocad knows where to look. OPTIONS FILES Add the directory using ADD Repeat for Trusted paths 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.