Jump to content

Insert Dimension Measurement Field


RyanAtNelco

Recommended Posts

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!

Link to comment
Share on other sites

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))))

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Alan> Lazy indeed, after all why type "leader" when I can just type "*"... :P

 

Ryan>

 

Yes it replaces the text - how would I know whether you wanted it at the beginning or end :geek:o:) ?

 

Different positions can indeed be incorporated just by altering the field string.

Link to comment
Share on other sites

Alan> Lazy indeed, after all why type "leader" when I can just type "*"... :P

 

Ryan>

 

Yes it replaces the text - how would I know whether you wanted it at the beginning or end :geek:o:) ?

 

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.

Link to comment
Share on other sites

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 :thumbsup:

Link to comment
Share on other sites

  • 5 years later...

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 by mdbdesign
try to wrap....
Link to comment
Share on other sites

  • 3 years later...

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; }

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...