Batch Processing and Aspects of AsStringValue

I avoid answering non-confidential questions in private, as I tell everyone who tries to do so.

However, some non-confidential queries still come in via ADN, the Autodesk Developer Network.

Here are two that came in today that might be of general interest and therefore seem worth sharing:

Batch Processing Revit Families and Documents

Question: Revit 2019 is leaking memory when importing families. We need to do this 1000s of times using automation. It is a blocking issue.

Please can you advise?

Answer: Revit on the desktop is an end user product designed for manual use through the manual user interface.

If you are using it to perform any kind of operation thousands of times, you are using it in an unexpected manner.

You should not be surprised if you run into problems eventually.

The standard method to handle such tasks is something like this:

Here is more on the topic of using Revit as a server for batch processing Revit documents.

However, Revit is not designed to be used as a server, and the EULA actually prohibits such use.

A better and more robust alternative nowadays that also saves you the maintenance of a local Revit installation and enables integration of your batch processing into other web-based workflows is to perform your batch processing using the Forge Design Automation API for Revit.

Here are more articles describing specific aspects of DA4R, or Design Automation for Revit

AsString and AsValueString Results Differ

Question: I am running into a problem using AsValuesString and AsString.

They return different values.

For instance, a view has a parameter named "Sheet Number". Its storage type is string. AsValueString returns a blank value for it, whereas AsString returns "---":

Sheet number

Similarly for the Duct Accessory parameter "Loss Method":

Loss method

The same problem occurs with many other element and parameters.

Is there a way to identify which value is correct and to identify which method to use to always to get the correct value?

I am running into the issue exporting schedule data to Excel. In some cases, I export a blank value for a non-blank data item.

When importing back the data, I cannot determine whether the user modified it or it was incorrectly exported.

Answer: The Revit Parameter class has a storage type that can take one of the following values:

Corresponding to the four valid storage types, there are four accessors to read the stored value from the database:

Use those four, and you will have no problem.

AsValueString is a completely different creature that returns the parameter value as a string with units, like the user would see it.

It may perform complex conversions while rendering the string.

Furthermore, a string-valued parameter value can only be retrieved using AsString, and AsValueString returns an empty string for it, as you already noticed.

I would avoid using AsValueString at all in your situation, and keep track of the parameter storage type as well as its value.