September 09, 2007

OSNAP Toggle Macro

There was a request for a macro to toggle the running object snap (OSNAP) settings between "off" and a specific combination of OSNAPs, in a thread in the AutoCAD Architecture 2008 Discussion Group. I posted some AutoLISP code in reply, and thought I would archive the code here and explain how it works.

The OSMODE system variable keeps track of which OSNAP settings are active, and whether running object snap is turned on or off. The value stored in the OSMODE system variable is "bit coded". A bit coded system variable allows multiple, related items that can be either "on" or "off" to be tracked "separately" in one number. If you expressed that number in Base 2, each digit (or "bit") will either be zero (not set, or off) or a one (set, or on). Each OSNAP setting is assigned to a particular digit, and if that bit is "set" (1), that OSNAP is on. If all of the bits are set to zero, then the NONe OSNAP is "set". The decimal value held in the OSMODE system variable is the sum of the associated decimal values of each of the set bits. As noted in the Help, the following indicates the bit with which each OSNAP is associated.
OSNAP
  
Decimal Value
ENDpoint 1
MIDpoint 2
CENter 4
NODe 8
QUAdrant 16
INTersection 32
INSertion 64
PERpendicular 128
TANgent 256
NEArest 512
Clears all object snaps 1024
APParent Intersection 2048
EXTension 4096
PARallel 8192

There is also an additional bit setting for the 16384 bit. If this bit is set, then running object snaps are turned off, but the individual snap settings are retained and can be reactivated by clearing the 16384 bit. So there are two ways in which runnning object snaps can be off: either none are set (OSMODE = 0) or the 16384 bit is set (OSMODE > 16383). These are the tests that my macro code uses to test whether running object snaps are inactive. If inactive, OSMODE is set to the desired combination of OSNAPs - in this example, endpoint (1), intersection (32), perpendicular (128) and nearest (512); otherwise, 16384 is added to the current value to set the 16384 bit and turn off running object snaps. Rather than adding the bit codes and entering that specific number, I used the AutoLISP "+" function to do the adding for me. This may slow down execution a bit, but it makes seeing what OSNAPs are being set by the code much clearer and makes adding or removing a particular OSNAP easier, too.

The macro code could be assigned to a function key or a keyboard accelerator, as the person making the request in the Discussion Group wanted, or it could be assigned to a toolbar button or to a command tool on a Tool palette. Similar code could be put into an AutoLISP function which, when loaded, could be run by any of the above methods or at the Command: prompt by typing in the function name.

MACRO CODE:
(if 
(or
(= (getvar "OSMODE") 0)
(> (getvar "OSMODE") 16383)
)
(setvar "OSMODE" (+ 1 32 128 512))
(setvar "OSMODE" (+ (getvar "OSMODE") 16384))
)


MACRO CODE in an AutoLISP Function:
(defun C:OSM ( / aosmo)
(setq aosmo (getvar "OSMODE"))
(if
(or
(= aosmo 0)
(> aosmo 16383)
)
(setvar "OSMODE" (+ 1 32 128 512))
(setvar "OSMODE" (+ aosmo 16384))
)
(prin1)
)

August 22, 2007

AU 2007: Get Fully Equipped in AutoCAD Architecture

Just a reminder for those of you fortunate enough to be registering for AU, I will be teaching a course called Get Fully Equipped in AutoCAD Architecture (AB114-4), which is scheduled for Tuesday, November 27, from 3:00 pm to 4:30 pm in Murano 3203. It is the only AutoCAD Architecture class currently scheduled in that time slot, and I hope to see you there.

Come see a method of creating and scheduling equipment that I have used for several health care projects and which could easily be used on laboratory projects or adapted to any other project type where you need to show equipment or furniture in plan, with identifying tags and then create a schedule to list those items and related data. Equipment not your thing? Then come to see how to analyze a scheduling task and apply the schedule features in AutoCAD Architecture to meet the needs.

Be sure to check out Matt Dillon's Schedule Anything in AutoCAD Architecture or AutoCAD MEP, on Friday, November 30, from 8:00 am - 11:30 am and leave AU 2007 a scheduling pro!

August 06, 2007

Details: Welding Symbols Layer Key

Those of you using ADT 2005 or later may have discovered the nifty welding symbols tool on the Basic tool palette in the Detailing tool palette group.Running this tool opens the Welding Symbols dialog box, which allows you to select from a number of different welding symbol options, and, for those with attributed blocks, provide values for that block's attributes.
Selecting OK results in the insertion of one or more blocks that form the symbol, and allows you to create one or more leaders to point to the place(s) where the weld symbol applies.

The source file for the "WPLG" plug weld block shown above is WPLG.dwg, which, like the other welding symbol blocks, can be found in the C:\Program Files\AutoCAD Architecture 2008\Welding folder if the default file locations were used on installation. The polyline that forms the linework for this block is drawn on Layer 0, with ByLayer properties, so it will inherit the layer, color, linetype and lineweight of the layer on which the block is placed. The attributes are defined on a layer called WELDTEXT, with ByLayer properties. The way Details blocks work is if the layer name on which an object is drawn matches a Layer Key name in the current Layer Key Style, then that object, when inserted into the drawing, will be put on the layer assigned to that Layer Key.

The overall welding symbol is assigned to the ANNOBJ Layer Key, so the block(s) and leaders are placed on the A-Anno-Note layer for the out-of-the-box AIA (256 Color) Layer Key Style, with no overrides set. Unfortunately, the AIA (256 Color) Layer Key Style that has shipped with the program since ADT 2005 does not contain a Layer Key called WELDTEXT. Nor do any of the other out-of-the-box Layer Key Styles that I have examined.Because of this, ADT/ACD-A simply keeps the attributes on the WELDTEXT layer, as defined in the source file. (As always, click on any "reduced size" image file to see the image full size.)
Fortunately, adding a Layer Key is quite easy, so if you want to get the attributes of your welding symbols on a layer other than WELDTEXT, add a WELDTEXT Layer Key and specify the layer name and properties of the layer on which you want the attributes to be placed. You can edit a Layer Key Style through the Style Manager (Format > Style Manager..., then look in the Multi-Purpose Object folder -OR- Format > Layer Management > Layer Key Styles... from the pulldown menus) or by opening the Layer Manager and selecting the Layer Key Styles button (second from left) on the toolbar at the top of the dialog.



Once you have the Style Manager open and have found and expanded the Layer Key Styles category in the Multi-Purpose Objects folder, select the name of the Layer Key Style you use in the left pane, and then select the Keys tab in the right pane. Left click on the New button at the lower right corner.
In the Name dialog, type WELDTEXT in the edit box and select OK to create a new Layer Key of that name.
Enter a description for the Layer Key, and add a layer name (use the ellipsis button to build a layer name from predefined components in your Layer Standard) and set the layer parameters. I chose color 182, a dark purple, for contrast with the default yellow color. You may wish to choose a different color.One curious "feature" when adding a new Layer Key that I have never understood is that the Allow Overrides toggles for the new Layer Key are not active. You will need to "Apply" your changes, then reselect the name of your Layer Key Style in the left pane. Now the Allow Overrides toggles are active, and you can, if you wish, check them to allow Layer Key Overrides to be applied to the various components of the layer name.
Once you have tested the new Layer Key, you will want to copy the revised Layer Key Style to your auto-import file. You can find the name and location of this file on the Layering tab of the Drawing Set dialog. If you have the "always import" toggle on that tab checked, the updated Layer Key Style will be imported when opening existing drawings and using any feature that involves a Layer Key. If you do not have the "always import" toggle checked, you will need to update the Layer Key Style in any existing drawings manually. I would recommend having the "always import" toggle checked; if you do not, at the very least you should make certain that your template files do not have a Layer Key Style defined within them, so that new files will always inherit the latest version of the Layer Key Style from the auto-import file.

Note also that in any existing files in which you have already placed a particular attributed welding symbol block, the WELDTEXT layer is already built into the block definition, and you would need to redefine the block manually, then use ATTSYNC to update the attributes of the previously existing instances of that block. But for new drawings, or for blocks not already defined, that have the new Layer Key Style with the WELDTEXT Layer Key, the attributes will now be placed on the layer assigned to the WELDTEXT Layer Key.

August 05, 2007

Command Tool: Open a Specific File

If you have bought into the tool palette workflow in AutoCAD® Architecture/Autodesk® Architectural Desktop, you may find yourself wanting to move other customizations that you formerly might have put on a toolbar on a tool palette. Fortunately, there is a tool type just for this occasion, the Command Tool. You can find a "blank" version of the Command Tool in the Stock Tool Catalog that ships with ACD-A/ADT, in the Helper Tools category.
A post in the AutoCAD Architecture 2008 Discussion Group asked if there was a way to have a tool on a tool palette open a specific file. After a little confusion over exactly was wanted got cleared up, I noted that while I was unable to get either the OPEN or NEW commands to work directly in a Command Tool to either open a specific file or start a new file with a specific template without the user interacting with the "Select File" or "Select template" dialogs, I was able to use a script file to run the NEW command at the Command Line and to get the desired template file entered onto the Command Line, only requiring the end user to press the Enter key. I thought I tried addiing a space to the end of the script to force the value to be accepted and end the command, and it did not work, but I was in a bit of a hurry and may have not properly edited and saved the script file. I have taken a second look at this, in ACD-A 2008 and in ADT 2005, and was able to get both the OPEN and NEW commands to fully execute by running a script file from a tool palette tool. While opening most files is probably best done by the user directly with the OPEN command (or through Project Navigator, if you are using that), there may be a few "source files" to which you would like to have direct access, without a lot of navigation in the "Select File" dialog. If you are putting together a palette of tools related to a specific task that requires starting a new drawing with a specific template file - especially if it is not your typical default file - then the New File tool may be of use to you.

The first thing you will need is the script file. Script files, for those who do not know, are plain text files that represent the keystrokes you would type at the Command Line. Notepad is a good choice for creating and editing script files, as you do not have to worry that the saved files will have any of the extraneous formatting information that a word processor can put into a file. The SCRIPT command is then used to open a run a script file, feeding the text in the script file to the Command Line. Many commands, that would normally open a dialog box for user input will run a Command Line version when invoked from a script, even when FILEDIA is set to 1 and including those, such as OPEN and NEW, that no longer have a Command Line version (command name preceded by a "-"). For an OPEN tool, you will need to know the file name and the path where the file will be stored. For a NEW tool, you will need to know the file name and path of the template file you wish to use. The text of the script files I created when testing this tonight follow:
OPEN Tool
_.OPEN
"C:/Documents and Settings/David Koch/My Documents/The Architect's Desktop Blog/Tool Palette Tool To Open File/TargetFile_01.dwg"

NEW Tool
_.NEW
"C:/Documents and Settings/All Users/Application Data/Autodesk/ACD-A 2008/enu/Template/Aec Model (Imperial Stb).dwt"

Two things to note in the samples above. First, there is a single space at the end of the second line; that space acts as the "Enter" after the file name is passed to the OPEN or NEW command, ending the command input and executing the command. Second, the path for the drawing file or template file has forward slashes, rather than the ususal backslashes, to separate folder names. Script files will interpret a backward slash as a pause for user input. The forward slashes will be interpreted correctly; just be aware that you can not simply cut and paste the path from Windows Explorer to the script. The script file then needs to be saved to a location to which everyone running the tool has access.

At this point, I also quickly created two rather crude BMP files to serve as the tool images, by "stealing" the graphics for the OPEN and NEW toolbar buttons on the Standard toolbar. If I had to look at these tools on a regular basis, I probably would have spent a little more time and made much nicer images. You could also just live with the default image for a Command Tool, a white square.

After creating a new tool palette in my current workspace on which to create the new tools (setting an existing, editable tool palette current also works), I opened the Content Browser, found and opened the Stock Tool Catalog, navigated to the Helper Tools category......and i-dropped the Command Tool onto the tool palette.
I right clicked on that tool and made a copy, so I would have two command tools, one for OPEN and one for NEW. I then right clicked on the tool that was to run the OPEN script and chose Properties... from the context menu. I gave the tool a name and a decription. The description is displayed in the tool tip when you hover over a tool, so providing a meaningful description can be helpful to those using the tool. I chose to indicate the command (Open) and the full path and file name of the file to be opened. I then right clicked in the Image area, and chose Specify Image... from the context menu (the only choice). I navigated to the location where I had saved the image file for the Open command and selected that file. The command string entered can be seen in the image below; the SCRIPT command is run, and the script file, with full path, completes the command string. Once again, forward slashes are used to separate folders in the path. Select OK to close the Command dialog and OK again to save and close the changes made to the tool's properties.
Creating the tool for the NEW script followed the same procedure as noted above for the OPEN tool; an image showing the properties dialog with the command string for the NEW tool is shown below.

All that remains is to test the tools (you may want to test the script files manually first, to be certain they work, before testing the tools). Once you are satisfied they work, you can share them with others through the Content Browser, like any other tool.

July 28, 2007

AutoCAD Architecture 2008 as AutoCAD

Although I rarely use the option, as I was installing AutoCAD® Architecture 2008 the other evening, I thought I was carefully making my way through the installation process and was surprised that there was not an unchecked toggle somewhere to add a desktop icon to run the program as AutoCAD®. I went back to modify the installation and still could not find that option, which had been there in the last few releases.

I was not too worried, having remembered that Matt Dillon had posted an article in his blog giving a method of creating such a shortcut without the need to go into the installation program. I opened up the program and after getting through the authorization process, opened up the Options dialog to begin making my usual changes to the out-of-the-box settings. While there, I noticed that a profile called "AutoCAD" had been created and found that profile was set up to run AutoCAD Architecture (ACD-A) "as AutoCAD". (And, yes, I did install all of the content options. Someday when I have some "extra" time, I will see whether there is any cool stuff in the content for countries other than the US.)

Rather than creating a shortcut that calls a previously undefined profile, as Matt suggested for the 2007 release, I chose to make use of the AutoCAD profile that was already there. The following outlines what I did. The first step was to find the icon of the shortcut I would normally use to start ACD-A 2008, right click, copy and then paste a copy on the desktop.
I then right clicked on the copied shortcut and selected Properties from the context menu. On the Shortcut tab, in the Target edit box, after the "/p" switch, I changed the name of the profile to be used when launching ACD-A to "AutoCAD".Then, since my desktop has quite a few ADT/ACD-A shortcuts, I edited the comment, which is the text that appears in the tool tip when hovering over a desktop shortcut, to reflect the function of this shortcut, as shown in the image below.
I also wanted to give this shortcut a distinctive icon, one my aging eyes would have no trouble distinguishing, so I selected the Change Icon... button, which opened a "Change Icon" dialog showing the current icon as the only choice. A click on the Browse... button in that dialog opened another "Change Icon" dialog that would allow selecting a different source file for the icon, starting in the folder in which the current icon's source file was located.Fortunately, the vanilla AutoCAD icon was also in that folder, and I chose that file and accepted that as the new icon.

The final step was to select the General tab and change the name of the shortcut, as seen below.I chose OK to dismiss the Properties dialog and I now have a desktop shortcut that will launch ACD-A 2008 as AutoCAD.

July 25, 2007

Pasting Formulas

Perhaps you have found the code for a formula property in a posting in an Autodesk Discussion Group or an AUGI Forum, and you wanted to add that formula to a Property Set Definition of your own. Someone else has already done all of the typing - why not just cut and paste the code and move on to your next task? Even if you already had - or just created - all of the other properties referenced by the sample code, you will find that cutting and pasting code from another source does not work. That is because property references have to be created by selecting them from the pane below the formula editing pane; you can not simply type in the name of the property, enclosed in square brackets: [MyPropertyReference]. Cut and paste will not work even if the source is another formula property, that has working property references!
The image above shows a formula property being edited, with text cut from Notepad and pasted into the edit pane. As you can see, the property references (text enclosed in square brackets) do not have the tell-tale gray background of a working property reference. (For ADT 2004 and 2005, the working property references appear in bold type.) After pasting, you could individually highlight each property reference and then double click on the corresponding property in the lower pane to replace the text with a working reference. In my simple example, that would only require three operations and would not be all that onerous. But for a more complex formula, there could be many more references, and the chore more tedious.

Fortunately, there is an alternative. You will need to scan through the code you intend to paste and identify all of the property references, but you would have to do that anyway, to make certain that all of those properties already existed. Keep a count of how many times each property is referenced. (If any one property is referenced more than two times, you may want to consider setting a variable to the value of that property up front, then using the variable in lieu of reading in the value multiple times.) As shown in the image below, add the property references in the code you intend to paste, one reference for each reference in the code, by double-clicking on the corresponding property in the lower pane. The sample code references the [HeightOverride] property twice and the [Height] property once, so that is what was added. Note the gray background behind the property references.
Now position the cursor before/above the property references you added. I like to throw a blank line or two before the references to be certain I am above them, and to make the final cleanup that much easier. Paste your code into the edit window and "presto-chango" - the code reference text you pasted in is now magically transformed into working code references, and the code references added prior to pasting are now plain text, as seen below.
All that remains is to highlight the extra lines and now useless text at the end of the formula and delete it.
Note: If the names of the properties in the code to be pasted are different from the equivalent properties in your Property Sets, you will need to paste the code to Notepad or a similar program and edit the name text to match your names before pasting it into the formula property, or this technique will not work.

July 01, 2007

Anchor Property Sample

In response to a question in the Schedule PSD thread in the AutoCAD Architecture 2008 Discussion Group, I posted a file done in ADT 2007 that demonstrates that an Anchor property can be used in a Property Set Definition attached to to a Window object to read in property data from the Wall object and use that to calculate the necessary window opening.

Two different options are given, one that assumes a style-naming convention that has the name of all stud wall styles starting with the letters "stud", and another that assumes that a manual property attached to the wall style contains the string "STUD" for all stud walls. The formulas associated with each method pass through the value of the automatic WidthUnformatted property for stud walls and add 3" to the width for all other wall types.

Use of a Anchor property, introduced in the 2007 release, makes this task much easier. Previous releases would have required a formula property to dig through the drawing database, to find the associated value.

June 17, 2007

Free Webcast - ACA Details


Steve Bennett, of LA CAD and tireless AUGI volunteer, is offering a free, one-hour webcast on Wednesday, June 20, 2007, titled Utilizing the Detail Engine in AutoCAD Architecture. See the details and find a link to the registration site in this article in his blog.

7/7/2007 Update: Steve is offering another webcast, this time on Project Management, on Wednesday, July 25, 2007. Get the details and a link to the registration site here.

June 16, 2007

Rounded Values and the Quantity Column

Many times you may have objects and associated data that you would like to document in a Schedule Table, but there are large numbers of "identical" objects - all the data in each objects row is the same - and you really do not need to show each line. This is just the situation that the quantity column was meant to handle - check the box on the Columns tab when creating or editing your Schedule Table Style to add a Quantity column, as shown in the image below.With a quantity column in your schedule table, all identical rows will "collapse" into a single row, with the total number of objects represented listed in the quantity column. If you do not want to display the actual quantity, simply hide the quantity column.

An interesting question came up in this thread in the Autodesk Architectural Desktop 2007 & Prior Discussion Group. The images in this blog post were taken from the ADT 2006 drawing file I posted in reply. The goal was to list spaces and their areas in a schedule table, using a quantity column to collapse spaces of the same type and area onto one line. Unfortunately, there were slight differences in the actual areas of the spaces, such as those in my sample file, as illustrated by the schedule table below. I created an "unformatted" automatic property to which I assigned a Property Data Format that is a copy of the Standard Property Data Format, with the precision set to eight decimal places.There are two different types of spaces: offices, at a nominal 100 square feet, and conference rooms, at a nominal 150 square feet. Intentional (in my case) stretching of the spaces by varying small amounts resulted in the slightly different areas shown, and preventing any lines from collapsing. Given the obviously different values, this is not surprising.

The discussion group poster noted that he had created a Property Data Format for his area properties that rounded the values to the nearest whole number, but this still was not allowing the rows to collapse, despite the apparently identical values. As shown below, I was able to reproduce that in my sample file. ADT is using the raw automatic property value, before the application of the Property Data Format, to determine whether rows are identical, as can be seen in the schedule table shown below.
Fortunately, there is a way to achieve the desired result, other than insisting on precise drafting. And while that is something of a pet peeve of mine, there certainly could be situations where there are legitimate small variations in a given value, that disappear when rounded to the desired accuracy for reporting the value. I can think of two ways to achieve the desired result, both of which involve the use of a formula property. Which works best for you will depend upon the specifics of your situation.

The first formula uses the unformatted automatic property and applies the Round function to get the desired precision, as seen below. For whole number precision, the Fix function may also work, although that will simply truncate any fractional amount, rather than round it.The advantage of using an unformatted property to get a numeric value, then applying the Round function in a formula property is that you can control the desired precision, and, with a little math, can even get a precision greater than whole number. For example, if you wanted to have the area value rounded to the nearest 50 square feet, you could do something like this:
Round( [NetAreaUnformatted]/50, 0 ) * 50
By dividing the value by 50, rounding, then multiplying the value by 50, you will get the value, rounded to the nearest 50. One thing to note for the Round function is that if the value of the digit beyond the one being rounded is exactly 5, the digit being rounded will round up if the digit is odd and down if the digit is even (that is, the result will always be an even digit). The results of using that formula in the schedule table can be seen below - the values for all four offices and all four conference rooms are now the same, so they collapse onto two lines, one for each type.
The second formula assumes that you can achieve the desired rounding with a Property Data Format, and simply takes the formatted version of the automatic property and passes it through the formula, enclosed in double quotation marks, to convert it to a string value, like this:
"[NetArea]"
Since the Property Data Format made the displayed values for each space type the same, the string will be the same, and the rows will collapse, as seen in the image below.
If you are interested, you can download the sample file I posted to the thread and take a look at the formulas "live".

June 15, 2007

AU 2007

Having attended three of the last four Autodesk Universities - I missed the 2005 edition in Orlando - I can attest to the fantastic opportunities to learn from and network with the best of the best. Even if you could afford to have Matt Dillon or Paul Aubin fly in and give you three-and-one-half days of one-on-one training, you would still miss out on all of the informal learning opportunities and the chance to meet fellow users, any one of whom might have a solution to an issue that has been giving you problems. Not to mention being able to "corner" members of the AutoCAD® Architecture development team, and provide some direct feedback.

If were thinking about going this year, but you have not yet started laying the groundwork, there is no better time than the present to start. Registration opens in "August", according to the Autodesk AU website. That is likely to be early in August, going by past years. If you need to make the case to your employer or a spouse, you will want to do so well before October 8, when the fees go up $500. Many of the more popular classes may be filled by that time, anyway.

If you need an additional incentive, and were hoping to be able to take a class that goes beyond the basics of the ACA Schedule feature, I am pleased to announce that my class proposal titled Get Fully Equipped in AutoCAD Architecture (90-minute class) has been accepted. I will be presenting a method of creating and scheduling equipment that I have used for several health care projects and which could easily be used on laboratory projects or adapted to any other project type where you need to show equipment or furniture in plan, with identifying tags and then create a schedule to list those items and related data. If that sounds interesting to you, and you are going to AU this year, I would appreciate you taking this class into consideration when selecting your classes.

If you are looking for a course that covers the basics of the ACA Schedule feature, Matt Dillon will be presenting Schedule Anything in AutoCAD Architecture or AutoCAD MEP in a 3 1/2 hour tutorial. If you have never taken Matt's Schedule Anything class before and are looking to master the basics of the Schedule feature, I can assure you that it will be well worth your time.

I do not know where on the schedule either of these classes fall at this time, but I hope that Matt's class is offered first, so that anyone wanting to take both, but who would benefit most by learning about the overall feature first, can do so.