Jump to content

Entmake Fields


Steven P

Recommended Posts

Does anyone know if it is possible to entmake a field text? Cheers

 

 

(working on a little function to create blocks... all done with entmakes and was wanting to look at the borders and title blocks next... which have a field.. but I can't work that one out. The function works via the command line, single word to insert a block, quicker than 'insert' skipping the dialogue box, entmakes because that's how I am doing it.)

Link to comment
Share on other sites

Keep in mind a field is linked to an object in a drawing. You have to insert the block first then create the field for it. If you make copies of that block and the field all those fields will reference the original insertion not the copied insertions. If you copy an object with field to another drawing the field will no longer work because the reference has to be set up in the current drawing.

Plenty of useful code out there for labeling blocks using fields just keep in mind they are limited by being directly linked to a specific object in a specific drawing.

http://www.cadtutor.net/forum/showthread.php?51254-Block-s-name-to-FIELD-(based-on-existing-lisp)&p=347968&viewfull=1#post347968

 

  • Like 1
  • Agree 1
Link to comment
Share on other sites

It's entirely possible.
You simply need to retrieve the ID of the object concerned.
You can rely on the text provided in the dialog box when designing the field in manual mode, you just have to be careful to double the "\" character in the lisp code so that it is correctly interpreted.

In lisp we can even have characteristics not accessible in a dialog box, an example of code to have the volume of a 3D solid (impossible to have this property in a dialog box)

 

(vl-load-com)
(defun c:Label_Volume ( / js htx AcDoc Space n obj ename pt alpha nw_obj)
  (princ "\nSelect solid.")
  (while
    (null
      (setq js
        (ssget
          (list
            '(0 . "3DSOLID")
            (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
            (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          )
        )
      )
    )
    (princ "\nAren't solid!")
  )
  (initget 6)
  (setq htx (getdist (getvar "VIEWCTR") (strcat "\nGive the height of the text <" (rtos (getvar "TEXTSIZE")) ">: ")))
  (if htx (setvar "TEXTSIZE" htx))
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space
    (if (= 1 (getvar "CVPORT"))
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
  )
  (vla-startundomark AcDoc)
  (repeat (setq n (sslength js))
    (setq
      obj (ssname js (setq n (1- n)))
      ename (vlax-ename->vla-object obj)
    )
    (initget 1)
    (redraw obj 3)
    (setq
      pt (getpoint "\nInsertion point?: ")
      alpha 0.0
      nw_obj
      (vla-addMtext Space
        (vlax-3d-point pt)
        0.0
        (strcat
          "{\\fArial|b0|i0|c0|p34;"
          "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
          (itoa (vla-get-ObjectID ename))
          ">%).Volume \\f \"%lu2%pr2%ps[V=,m³]\">%"
        )
      )
    )
    (redraw obj 4)
    (mapcar
      '(lambda (pr val)
        (vlax-put nw_obj pr val)
      )
      (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'Layer 'Rotation)
      (list 5 (getvar "TEXTSIZE") 5 pt (getvar "CLAYER") alpha)
    )
  )
  (vla-endundomark AcDoc)
  (prin1)
)

 

  • Like 1
Link to comment
Share on other sites

Nice, thanks.....

 

So essentially create the text but include the codes in there - that will work

 

From the examples above these are the important lines? I'll have a play with this later

 

(strcat 
  "%<\\AcObjProp Object(%<\\_ObjId "
  (itoa (vla-get-Objectid obj)) ">%).EffectiveName>%"
)

(strcat "
  "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
  (itoa (vla-get-ObjectID ename))">%).Volume>%"
)

 

Link to comment
Share on other sites

I have a handful of drawings that contain a lot of blocks in them arranged to where I can examine them and added a modified version of Lee's code to quickly label the names of each of them with a field and group the field to the block so they select together for moving them around together.

 

When inserting one of the blocks into another drawing I use the newer -INSERTCONTENT (Command) usually in macros for blocks we often import and since groups don't import the group names do not come in. Didn't like AutoCAD's major changes to the INSERT Command but the new command makes up for it.

Examples: 

^C^Cadcnavigate G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg;

that open them in Design Center which displays the blocks with names making them easy to insert or update.

^C^C-INSERTCONTENT G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg;Modified F Curb;

that inserts the block "Modified F Curb" from the drawing "G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg".

 

Easy-peasy with no coding required.

Link to comment
Share on other sites

"single word to insert a block" -Insert use it in a lisp.

 

Another B22 inserts block with a link to name "22" say in a list.

 

I have a reactor code that lets you type say Bz, B22 etc it will remove the B but keep what is after and use that in a defun which may be a -insert defun. No Dcl.

 

I have posted this before, you could do a Bxx.There is say 26 different versions available. I have Offset Circle Fillet in one version.

 

fillet reactor.lsp

 

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

Posted (edited)

I've never looked at reactors really, but could be a thing to look at one day.

 

This is my current amusement, more visual than remembering all the block names - I think you have posted similar before (a few times).

 

image.png.f357c2c4e8adcff92ad98f19442874d3.png

Edited by Steven P
Link to comment
Share on other sites

Thats an image out of a pop menu, nice thing is when screen is full it supports next so a full screen again. Select image or text.

 

Best is that you can use Notepad to make, the images are slides but I made like a 100 in one go. 

 

menu2.png.31566e48b6a2d6983b201aef0e2412c0.png

 

 

Link to comment
Share on other sites

Yes, that the image of the one I made up - very similar layout to the rest though, it is all working, just got to populate the menus now.

 

(doing it for my amusement and to help my memory with block names, thinking I'll make pseudo tabs for fun (Electrical, Civil, Mechanical, Drawing Utilities and so on))

Link to comment
Share on other sites

  • 1 month later...

Coming back to this one again - got distracted and diverted along a couple of other paths but now back on target to make fields in title blocks. The ones I am looking to add are drawing filepath, save date and saved by. This all links back to the DCL ideas above which were the distractions - single word block entries with no more user interface except select insert point.

 

So I have this:

(setq FieldText (entmakex (list
  '(0 . "MTEXT")
  '(100 . "AcDbEntity")
  '(8 . "0")
  '(100 . "AcDbMText")
  '(10 1934.27 1124.51 0.0)
  '(40 . 2.5)
  (cons 1 "%<\\AcVar Filename \\f \"%tc4%fn7\">% %<\\AcVar SaveDate \\f \"MMMM d, yyyy - hh:mm tt\">% %<\\AcVar LastSavedBy \\f \"%tc4\">%")
  '(7 . "Standard")
  '(11 1.0 0.0 0.0)
))) ; end setq, entmakex, list

 

Which results in this on the screen:

 

image.png.6275106e4c48017664e037e964220619.png

 

Double click on that and the filepath, date and last saved by are updated. However only does that when double clicking on the text string. Things like redraw, regen, updatefield, save-close-open aren't updating this... so what do I need to do next or do I need to use a different function for fields as opposed to entmake?  (all the lines, arcs, attributes and so on are all entmakes)

 

Suspect I have to create a Acad_XDictionary - but never done anything with them before (dxf codes 102, and 360 for the dictinary, entmake doesn't like that for me just now)

 

 

Thanks for any more help,

Link to comment
Share on other sites

The issue maybe is that you have 2 variables Savedate and Lastsavedby when you close the dwg these will probably disappear, so no update,

 

I have started using this for saving info in a dwg, rather than variables 1-5,  Userr1, Useri1, Users1.

 

 

(vlax-ldata-put "StevenP" "SAVEDATE" yourdate )

(setq savedate (vlax-ldata-get "StevenP" "SAVEDATE"))

 

  • Like 1
Link to comment
Share on other sites

14 hours ago, Steven P said:

Double click on that and the filepath, date and last saved by are updated. However only does that when double clicking on the text string. Things like redraw, regen, updatefield, save-close-open aren't updating this... so what do I need to do next or do I need to use a different function for fields as opposed to entmake?  (all the lines, arcs, attributes and so on are all entmakes)

 

Suspect I have to create a Acad_XDictionary - but never done anything with them before (dxf codes 102, and 360 for the dictinary, entmake doesn't like that for me just now)

 

 

Thanks for any more help,

Indeed (entmake) does not work entirely with fields.
And you're right about dictionaries, we can do them with entmake, but it's complicated.
With (vla-addMtext), it's much simpler, it takes care of the dictionary itself.

 

((lambda ( / AcDoc Space)
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    Space
    (if (= 1 (getvar "CVPORT"))
      (vla-get-PaperSpace AcDoc)
      (vla-get-ModelSpace AcDoc)
    )
  )
  (initget 1)
  (vla-update 
    (vla-addMtext Space
      (vlax-3d-point (getpoint "\nInsertion point; "))
      0.0
      "%<\\AcVar Filename \\f \"%tc4%fn7\">% %<\\AcVar SaveDate \\f \"MMMM d, yyyy - hh:mm tt\">% %<\\AcVar LastSavedBy \\f \"%tc4\">%"
    )
  )
))

 

  • Like 2
Link to comment
Share on other sites

I added drawing file path, save date and saved by to custom properties in my template files placing them in all our title blocks so they're displayed on every layout on all our drawings automatically.

I added drop-downs in Properties tab for setting custom properties like picking the engineer for the signature block or entering the field book number for the survey notes.

  • Like 1
Link to comment
Share on other sites

Thanks,

 

This is one of those exercises "can I do it" rather than a need to do it - we have the templates etc created, saved away and working OK - but I wanted to see what I can create purely from LISP. Lines and so on are easy enough, but I am getting to the last few complicated pieces now. Big Al, you've given me an idea for something else there.... thanks.... that is another day of "I wonder if this can work".

 

Tsuky, that looks like what I was thinking I'd have to do, thanks, I'll give it a go.

Link to comment
Share on other sites

Like tombu had signature block insert into all layouts etc .Paper copy was signed legal requirement.

  • Like 2
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...