Are you taking advantage of Fields?

What is a Field?

Fields are placeholders in a text string that are sourced from a data element or property value. Many of us have gotten accustomed to seeing a Drawing number automatically set in the Title Block, based on the file name. As shown below.

Sample Title Block using a Filename Field element to auto populate the Drawing number.

This is extremely useful for making sure you have the right drawing number in your title block. There are a number of advantages this offers. It prevents people from making a copy of the file and updating it instead of the actual drawing. Well it doesn’t actually prevent them from doing that, but then when they plot their file it stands out that it is a copy.

So if the file gets a new name, the drawing number automatically updates. Cuts down on confusion. It is pretty frustrating when you have two prints, that are different drawings but share the same drawing number. That will happen if someone copied the file and then failed to update the Title block Drawing number Attribute. What happens when you issue two different drawings with the same Drawing number? Ouch. That is a mess and I hope your Document control group catches that before sending it out to your client.

I think most of us can agree, that is a pretty cool feature. Fields have been around for a number of years now, 2005 I believe. That’s 15 years ago!

What else are they good for?

Fields can be expanded to use Sheet Set information and help keep more of your title block information more consistent. Project Name, Site Name, Project Site Location. All of those could be tied to an element in a sheet set or other property. I won’t dive to deeply into Sheet Sets or the other external properties you can take advantage in this Post, but recommend you look into what else you can do to take advantage of this feature. I will however talk about how you can take advantage of them in your drawing.

You can link data from one entity to another.

Sample Block Diagram using Field Data pulled from hidden text elements.

Above you can see the highlighted field area that are controlled by something else. These attributed blocks are automatically updated when a simple text string is updated. This will take your template to a whole new level, if done right.

So how do you set that up?

Fields are just another part of AutoCAD. The interface is not the most conducive for setting this up, but you can use AutoCAD straight out of the box and set this up. I have created some useful AutoLISP routines to make it more efficient, but I’ll show you how to do this with just AutoCAD.

First you will need the Source and the Destination AutoCAD entities present in your drawing.

S1 = The Instrument Type
S2 = The Tag Number Prefix
S3 = the Tag Number (minus prefix)

First lets get the S1 field Data to go into the ATTRIBUTE spot. Run the Field Command.

Select Object on the left side of the dialog.
Select the Select Object Button and then select the PT (Instrument Type) Attribute.
Next Select Value in the Middle (Property Column – Wow notice all those properties!) Then select Uppercase in the Right Column (Format – See the Preview). Highlight all the Text in the Field Expression Box, Right Click and Copy. Then Pick Cancel. (If you select OK AutoCAD will start placing an Mtext entity with the Field Expression as the text value. (you can hit cancel if you accidently hit OK)

Double Click on the ATTRIBUTE (Attribute Tag inside the Cable Tag Block) to edit the Value. and paste the value inside of it.

Notice the Value shows a Shaded PT in the Value Spot. That’s part 1 complete.

Next we need to repeat the process to get the other two parts of the CABLE Tag.

This one is slightly different as this entity is TEXT, so the Dataa we want is in the CONTENTS Property. Select Uppercase and Then highlight the Field Expression and right Click Copy.

Double click the Cable Tag Attribute (Currently showing PT).

Click in the Value Area and then make sure you are at the end of the text string type in a separator “-” and then paste the Field Value. Should now look like it appears above.

Let’s now get the third part of the Tag. Run the Fields Command and do the same steps but now pick the S3 (Source 3) Text Entity.

Now we have the Last part of the Cable Tag. Right Click and Copy. Make sure that Preview shows what you expect it to be “S3”

Double Click the Cable Tag Attribute and add the suffix (aka part 3).

Be sure to click to the end of the Value or you may erase the other two parts you worked so hard to get to. Add a separator “-” and then paste the next Field Expression (Ctl+C)

While we have the Last part Tag Number, we can go ahead and update the Instrument bubble to link to that value as well. Double Click on the ATT of the Instrument Bubble. and paste the value into the attribute.

Paste the same thing in this Attribute of the Instrument Bubble.

Ok That’s neat and all but that was a lot of work for two text values.

Yes it actually is. It would be way easier just to edit the values and be done. Would it? As we all know, change is inevitable. Copying is what we do a lot of, and consistency is king! Let’s copy 4 more instruments down. Update the Instrument Types to as shown below.

Make sure you copy the Instrument Tag, Cable and Tag as a group. Copying as a group creates new links associated with the new copies. Notice the Cable Tags have not changed. If you copied them right they will however actually be linked to the right Instrument Tag. If you copy something that has a link to another entity and that entity is being copied as well. AutoCAD will set the field data to be associated to the new entities. Pretty awesome feature. If you copy something that has a link to an entity that is not in the selection, then it leaves the field data association as is.

Why aren’t my cable tags updated?

There are a few things to understand about Fields. One the update based on the settings in the FIELDEVAL AutoCAD Variable.

Screen capture of the AutoCAD 2019 Help System for the FIELDEVAL System Variable. This is a Bitcode value so it means you can add the values together and make it work with multiple things considered. I Typically set mine to 31.

Once you have the FIELDEVAL set to Evaluate to at least include “Updated on regeneration,” Then you can simply do a REGEN or REGENALL to get the fields to evaluate the expressions.

Notice the Cable Tags are all updated properly.

Still more benefits. Change! The Project Just came back and updated the Site’s Prefix and the tag number for the instruments is now known. Site prefix is “PA-01” and the Tag Number the instruments share is 2003. Update the S2 Text string to “PA-01” ad the S3 Text String to “2003”. Regen and look at the results.

That was easy!

Now imagine if you used this in a wiring diagram and all your wire tags were linked to the instrument’s tag.

I hope this opens your eyes to some of the benefits FIELDS provide. If you do find you would like to start using fields, let me know and I can send you over a few useful routines for managing the field links much better than they FIELDS command.

CAD Advanced AutoLISP Teaser

So far I have discussed a few things about improving our industry through sharing of knowledge. AutoLISP has been around since I started with AutoCAD in 89’. AutoLISP continues to be a strong API for AutoCAD. This Post will just be a little bit of a teaser to see how interested you actually are in AutoLISP. I will show you a few quick things you can do at the command line inside AutoCAD that will hopefully pique your interest enough to come back for more.

First a couple of things to note. AutoLISP uses Parenthesis to enclose code segments. Some special things to pay attention to are for every opening parenthesis there needs to be a closing one. Similarly for every opening double quote, signifying a string, there needs to be a closing one.

Try this out (in typical programming tradition)

(defun C:HELLOLISP() (princ “\nHello World!”))

The above AutoLISP code will create a command called HELLOLISP that is now available within the AutoCAD Dwg Session you loaded it in. So give it a try. Type HELLOLISP at the command prompt.

Congratulations you just typed in and executed your first AutoLISP defined command!

That’s great and all, but what good does that do me? Well, it basically shows you how easy AutiLISP is to use inside AutoCAD directly from the command prompt. Let’s do some more, but directly with AutoCAD commands.

Open a drawing, any drawing that has something in it, hopefully a good collection of entity types, circles, lines, blocks, polylines, wipeouts, text… Make sure it is a copy of the drawing and not one you care to keep.

Once inside your drawing lets erase all the text in your drawing. There are a few ways to do it, but this is after all an AutoLISP lesson. So let’s use AutoLISP.

Start the Erase command, then when you are at the Select objects prompt, type in the following. (pay attention there is a single quote char and is special to the AutoLISP interpreter.

Select objects: (ssget “X” ‘((0 . “TEXT“)))
18 found
Select objects: [Enter]

All text (excluding MTEXT, Attributes, and any text inside blocks) should now be deleted.

Try it with other entity types. (“LINE” ; “CIRCLE”; “INSERT” (Block inserts); “LWPOLYLINE”)

In this intro we will not dig into what each things means, but we will show you some easy stuff to try.

Let’s move on.

AutoLISP can be used as an In line calculator. Take for instance those Scale Factors we talked about in the Scale Factors Post. With AutoLISP you can enter them directly at the command line instead of using a calculator. Say you want to scale something down to 1/48th of its original size. Start the SCALE command and select your object to scale, pick your base point and then when prompted for the scale factor input the following:

(/ 1.0 48.0)

Make sure you use the decimals. We will discuss why in later lessons.

You can use this even without a command. Try it:

(+ 37 2.5)

(- 20 19)

(/ 1.0 2)

(* 12 12)

You can use AutoLISP to access system variables. Imagine you are inserting symbol into a drawing and you don’t actually know the scale factor. Is it 64 or is 96. Assuming it is a scaled drawing and we are in Modelspace. Start the insert command, pick one of your symbols to insert and then when prompted for a scale factor try the following input.

(getvar “DIMSCALE“)

This will retrieve the current dimstyle’s scale factor setting. If you only use dimensions in Paper space this will basically be one. Again this is just to show some quick things to try.

What if you are working and you have two versions of the same file opened from different file paths. You can look it up using AutoLISP at the command line.

(getvar “DWGPREFIX“)

The result is your drawing file’s path.

AutoLISP is AutoCAD’s version of LISP. LISP Stands for List Processing, so it means we can’t have a in intro to AutoLISP without processing a list or two.

Find a circle in your drawing and let’s work with it. Type the following at the command line, then pick the circle.

(setq myCircle (entget (car (entsel “\nSelect Circle: “))))

The result is a list of all the DXF data for that Circle. Now let’s look at the parts. Type the following at the command prompt:

(foreach dxfitem myCircle (princ “\n”) (princ dxfitem))

You should see something like this:

(-1 . <Entity name: 7ffffb05f70>)
(0 . CIRCLE)
(330 . <Entity name: 7ffffb039f0>) 
(5 . 1EF) 
(100 . AcDbEntity) 
(67 . 0)
 (410 . Model) 
(8 . MyLayer) 
(100 . AcDbCircle) 
(10 20.5482 9.05521 0.0) 
(40 . 0.854867) 
(210 0.0 0.0 1.0) 
(210 0.0 0.0 1.0)

What is all that? (You may need to hit F2 to see)  It is the data that makes up the circle. The AutoCAD drawing is a VECTOR format and not a RASTER format. In other words it’s data and not dots. Let’s wrap up with a quick discussion of what some of these things are.

(0 . CIRCLE)

0 is the DXF code for entity type. This entity happens to be a CIRCLE, Hopefully you picked a circle.

(67 . 0)

67 is the DXF code for space, ZERO means Model Space, ONE means Paperspace.

(8 . MyLayer)

8 is the DXF code for Layer. This entity is on the MyLayer Layer.

(10 20.5482 9.05521 0.0)

10 is the code for coordinate, a circle on has one coordinate at the center.

(40 . 0.854867)

40 is the code for Radius. This one has a radius of 0.854867

Now you see how easy it is to use AutoLISP. Now looking at the above, note that using AutoLISP you can change all those values. You could change it’s Radius, it’s Layer, it’s center point…. And so much more.

I hope you have enjoyed this AutoLISP Teaser. If you would like to see more, let me know in the comments section.