I had the opportunity to update some AutoCAD toolbars recently and looking through other's code is always a good time to either enhance something or learn from it. I chose to enhance the code and streamline it for future expansion.
The code itself is classic AutoCAD toolbar stuff. Lots of semicolons, back slashes, command line commands and options, and unfortunately, lots of hardcoded values associated with each scale. The tools worked, mostly, but trying to extend them or re-use them for new tools was problematic at best and hair-wrenching at times. As I looked through the toolbar code and built a table of the values for various scales, an opportunity to use some good old diesel code presented itself.
Let me give you a little background on the tools: The menu consisted of a series of toolbars, each one intended to be used for a particular drawing scale, providing a common method of inserting tags, dimensions, text, symbols, etc. The toolbars were wrapped up in flyouts, so that when a scale change was required, you simply picked it from the flyout and the correct associated tools were exposed and ready for use.
Anyway, as I started to build the tables to better understand the code and define patterns so that I could migrate this functionality for a Meter based metric project, I began to see how painstaking this process was going to become. To resolve the issues and simplify the maintenance, I changed all the hardcoded values into variables that could be multiplied by the current dimscale value. In doing so, I was able to create 10 new metric based toolbars from one master toolbar that only required two search and replace operations. Rather than copying each toolbar 10 times and then searching and replacing 22 different values for each scale, I reduced the effort to three operations, copy, search & replace, saveas.
Here is the tip: When does 8=37?
When you replace hard coded values with flexible diesel code!
Example code: $M=$(*,-0.0015875,$(getvar,dimscale))
Don't use hardcoded values in your menu macros, rather generate a value based on a variable and use diesel to retrieve it. So when does 8=37?
When you build a diesel macro to retrieve a value multiplied by the dimscale variable. The best thing about using diesel is it is evaluated so the 37 characters are not counted against your character limit. Only the number of characters represented in the value returned by the function is counted against the character limit. And variables make your tools more flexible. Instead of creating 40 new toolbars for the new metric tool menu, I was able to create 4 instead....now back to migrating legacy code with you!!!