Auto title block update using "Diesel" Fields - AutoCAD Electrical

  • Controlling the Machine is no longer being updated. Don't worry, though, you can still follow Nate Holt at his new blog, AutoCAD Electrical Etcetera. You'll find it at http://nateholt.wordpress.com. Or you can subscribe to his feed to get latest words of wisdom automatically: http://nateholt.wordpress.com/feed/. You also can continue to view the Controlling Machine archives for Nate's AutoCAD Electrical tips and tricks.

    About Nate

Latest Post

  • Auto title block update using "Diesel" Fields - AutoCAD Electrical
    December 13, 2008, 10:55 AM Nate Holt

    The Challenge

    A new AutoCAD Electrical user has a spot in his title block where he wants to show the last three characters of the current layout tab name. Having this come in automatically would be awesome. He asked if he could somehow make use of the AutoCAD "Field" concept and somehow have this information automatically fill into this spot on his title block.

    A field is an updatable text entity that is set up to display variable data. A field can be embedded into a block along with attribute definitions. The field is linked to some data element. There are lots of possibilities. Here is the field definition dialog box with the possible, linkable field names in the left-hand column.

    The currently selected layout tab name is stored in the AutoCAD "system variable" called CTAB. It looks like we could easily create a "Field" that links to this system variable (shown above). This field would then automatically update to show whatever tab is currently selected. So when we create our title block, along with ATTRIBUTE definitions we push into the block, we would also type FIELD at the AutoCAD command prompt and add in a field text entity tied to "SystemVariable" --> "ctab" as shown above. It will automatically update to whatever layout tab name is current. Cool... but...

    The Complication

    We have a problem. We don't want the whole layout name. We just want the last three characters of this layout name to show up in this title block field. If we could embed an AutoLISP expression into our field, we could strip out all but the last three characters. But an AutoLISP expression is not one of the field-link options in the dialog.

    Diesel to the Rescue

    Wow! Looks like a Field can be linked to a "Diesel" expression!

    I have to admit that it's been a very long time since I played around with this vintage Diesel stuff that's been in AutoCAD forever. It seems to parallel AutoLISP but with a goofy syntax (as if AutoLISP syntax doesn't seem goofy too, at first!).

    To get the current select layout tab name, it looks like Diesel supports the "getvar" function to get the system variable "CTAB" which carries the full layout tab name.

    Then we need to look at the length of this layout name and just pull out the last three characters. Assuming the layout name could be variable length, we'll need to use the Diesel function "strlen" to get the length, "substr" to get just a part of the overall layout name string, and the Diesel "-" subtract function to calculate where our substring is to begin to get just the last three characters.

    The Solution

    After some trial and error, I finally figured out the right syntax for the title block's field definition. Here it is...

    It Works!!!

     

     

     

    0 Comment | Add Comment Controlling the Machine >

Comments



You must be logged in to post a comment.

Subscribe to Blog

Want to keep up with the latest? Subscribe to the RSS feed today.

RSS

Tags

You must be logged in to add a tag.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback