April 11, 2019

Dynamo: Python Node to Test For Presence of a Parameter on an Object

We have a Dynamo graph that allows the user to search for a user-specified string in the names of Views and, if found, replace it with a second user-specified string. This comes in handy when someone decides that all of the instances of "LEVEL" in the view names should be changed to "FLOOR". The graph worked, but would result in an error condition, because there are, apparently, Views that do not have a "View Name" parameter attached to them. Attempting to retrieve the View Name parameter value from all elements of the Views category using an Element.GetParameterValueByName node resulted in this error:

While this did not appear to interrupt the processing of all Views, I would prefer to not have an error reporting (in both Dynamo and Dynamo Player), so that I do not have to explain to others who might use the graph that having that error is "Ok". I thought it would be simple to construct a BoolMask to filter out the Views without a View Name parameter, and proceeded to try to do so. Perhaps there is an easy way to create that BoolMask with core nodes or with something from a package, but my initial attempts were unsuccessful. The best I could do was get a list with true for the Views with the parameter but null for the Views without it, while throwing additional errors; that result also did not work as a mask in the List.FilterByBoolMask node. I quickly ran out of patience and decided to generate the mask list using a Python node, which turned out to be fairly easy.

Each Element in the Revit Model has a ParametersMap attribute, which is a map that contains all of the parameters the Element contains, accessible via the parameter Name, using the Contains(key) method for the ParameterMap object, where the key is the name of the parameter of interest. The potential for an error condition for Views without a View Name parameter can be handled by using try: and except: statements to build the mask list, as shown in the image below.

The Python node has two inputs, the first, IN[0], a list of Elements to be tested for the presence of a particular parameter, and the second, IN[1], a string representing the name of the parameter. The Contains method will return True if the Element's ParametersMap contains a parameter whose name matches the string passed to the Python node in IN[1]. If there is not a matching parameter name, it should return False; in testing, some of the Views were throwing an error, in which case the except: statement adds False to the output list.

The output from this Python node worked to remove the Views without a View Name parameter from the list of all elements of the Views category, allowing the rest of the graph to do the renaming of the Views without any error messages.

April 05, 2019

ACA: Import Layer Standard

If you have a custom Layer Key Style that is built on a custom Layer Standard, best practice is to establish a source file for Layer Standards and Layer Key Styles, such as the out-of-the-box AecLayerStd.dwg, that includes your customizations. Then, using the AECDWGSETUP command to open the Drawing Setup dialog, on the Layering tab you can specify that file as the source file for auto-importing your Layer Standard and Layer Key Style and also specify your Layer Key Style in the Default Layer Standard area.

If you save that as your default, it should get your Layer Key Style and Layer Standard into a drawing file. But if you have multiple Layer Standards, or have not set that up, it is important to note that while you can use the Style Manager to copy a Layer Key Style from one drawing to another, doing so does not bring the Layer Standard on which that Layer Key Style is based along for the ride. Without the Layer Standard, Layer Key Overrides will not work (assuming that your Layer Standard is set up with multiple descriptive fields supporting overrides). Here is how to copy a Layer Standard from an external file to the current drawing file.
  1. In the Layer Properties Manager, select the Layer Standard tool, located at the far right side of the tool bar at the top of the palette. The Layer Standards dialog will open.
  2. In the Layer Standards dialog, select the Import/Export button. The Import/Export Layer Standards dialog will appear. On the left side of the dialog, the Current Drawing's Layer Standard(s) will be listed. On the right side, the Layer Standards of an External Drawing will be shown, if one had previously been selected. If not, it will be blank, as in the image below.
  3. If you have an External Drawing selected, and it contains the Layer Standard you want to import, you can skip to Step #4. Otherwise, use the Open button to open a file dialog in which you can navigate to a drawing file that has the Layer Standard you wish to import. Select that drawing file and select the Open button in the file dialog to return to the Import/Export Layer Standards dialog with the desired External Drawing file in place. Or, if the Recent Files drop-down list has any drawings listed, and if one of those has the desired Layer Standard, you can select it from the drop-down list, rather than using the Open button.
  4. In the External Drawing list box on the right side of the dialog, select the Layer Standard(s) you want to import. Then select the <<< Import button to import it/them from the External File to the Current Drawing. The name(s) of the Layer Standard(s) selected should appear in the Current Drawing list box.
  5. Select the OK button in the Import/Export Layer Standards dialog to accept the change. The imported Layer Standard name(s) will be shown in the Layer Standards dialog. Select the OK button to confirm the change, dismiss the Layer Standard dialog and return to the drawing.