Parameters and .NET Core Webinar

Let's end this year with some notes on parameters and a reminder of the upcoming shift to .NET Core:

.NET Core Migration Webinar

Before we end for the year, let's recapitulate the announcement of the Autodesk Desktop API Updates: .NET Core Migration Webinar end of next month:

Do you have an application running on one of the Autodesk desktop products or on Design Automation, such as AutoCAD/Revit/Inventor? If so, please join the upcoming webinar where we will discuss next major releases of hero desktop product APIs moving to .NET Core.

Tentative Agenda:

To join this webinar, you will need to agree to a non-disclosure agreement NDA. To do so, please sign up through one of feedback portal projects for the respective products or the ADN extranet:

If you haven't already, please join the feedback projects now, and start testing your application against the preview/beta releases.

Reminder: ADN members can join the feedback portal through the ADN extranet by selecting SOFTWARE >> "Beta Portal." This will take you to the Autodesk feedback portal, Autodesk Developer Network Beta Program. Go to "Product Beta Access" and join the AutoCAD, Revit, or Inventor feedback project there.

Adding a Parameter with a Specific GUID

Adrian Crisan of Studio A International, LLC shared a very nice solution in both Python and C# for adding parameters with a specific GUID:

Question: I have a requirement to add parameters and bind them to most if not all elements in a model (and one parameter to be bound to a type instead; the blog was most helpful with that), but I'm running into a few issues.

Currently, my code creates a shared parameter file if not found, creates a group, and then adds the parameters to it. The problem comes as follows:

Am I missing something in the API that allows me to specify a GUID? What are the best practices around this? Does the Revit API have some way to modify the shared parameter file or only the binding functions?

I found a related issue on editing SharedParameterFile/deleting shared parameter entry; however, it does not answer nor is it exactly my problem.

Answer: Is this what you are looking for?

The GUID to use for this parameter definition. If not explicitly set, a random GUID is used.

We use this day in / day out for our new shared parameters.

You can use either the Visual Studio Tools Create GUID or the Python code below to generate the GUID:


import uuid
yourGuid = str(uuid.uuid4())
# Your GUID will be like 8-4-4-4-12
yourGuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

We do not recommend, but of course if you want to change the GUID as you want, make the changes.

Keep in mind the algorithms to create global unique id are developed to prevent as much as possible duplicates in large dynamic systems.

Then you can use the following Python code to create a new Shared Parameter definition with your own GUID:


app = DocumentManager.Instance.CurrentUIApplication.Application
yourSharedParamDefFile = r"yourDefinitionFile.txt"
app.SharedParametersFilename = yourSharedParamDefFile
sharedParametersFileName = app.OpenSharedParameterFile().Filename
paraGroup = app.OpenSharedParameterFile().Groups.get_Item("YourParameterGroup") # verify in your Definition File the name of the Group under which you want to create the Shared Parameter
newParaOptions = ExternalDefinitionCreationOptions("yourSharedParaName", ParameterType.Text) # Text, Integer, Number, Length, Area, Volume, etc. - look at the API for Parameter Type enumerations
newParaOptions.UserModifiable = False # Users cannot modify it, only Revit API
newParaOptions.Visible = False # Users cannot see it in the properties, but the parameter appears in schedules, etc.
newParaOptions.GUID = Guid(yourGuid) # set the Guid
createYourNewParameter = paraGroup.Definitions.Create(newParaOptions)

Here is the agnostic method in C#.


public void createSharedParameterDefinition()
{
  // Code provided courtesy of:
  // Studio A International, LLC
  // http://www.studio-a-int.com
  // The below code creates a new Shared Parameter in an existing Definition File
  // If a Shared Parameter with the same name is already in the Definition File,
  // the execution code will end with an error
  // You can generate your own GUID to assign it to the Shared Parameter
  // Use either Visual Studio Tools -> Create GUID
  // Or Python code to generate the GUID
  // import uuid
  // yourGuid = str(uuid.uuid4())
  // or other programming tools of your choice
  System.Guid yourGuid = new Guid("2778bb70-c715-4a9d-bdc1-76add223f228");
  // Shared Parameters Definition file
  string yourSharedParamDefFile = @"YourDrive\YourSharedParametersDefinitionFile.txt";
  // Shared Parameter name
  string yourSharedParaName = "NewSharedParaNameUnitTesting";
  // Initialize a StringBuilder to collect execution results/errors.
  StringBuilder sbCreateSharedParameterDefinition = new StringBuilder();
  try
  {
    Autodesk.Revit.DB.Document activeDoc = CreateSharedParameterDefinitionCommand.doc;
    Autodesk.Revit.ApplicationServices.Application app = activeDoc.Application;
    app.SharedParametersFilename = yourSharedParamDefFile;
    // Open the Shared Parameters File
    Autodesk.Revit.DB.DefinitionFile sharedParametersFile = app.OpenSharedParameterFile();
    string sharedParametersFileName = app.OpenSharedParameterFile().Filename;
    // Select under which Definition Group the new Shared Parameter will be placed
    DefinitionGroup paraGroup = app.OpenSharedParameterFile().Groups.get_Item("YOURGROUP");
    // Create new Options for the Shared Parameter
    // older APIs uses below method
    // Autodesk.Revit.DB.ExternalDefinitionCreationOptions newParaOptions = new ExternalDefinitionCreationOptions(yourSharedParaName, ParameterType.Text); // # Text, Integer, Number, Length, Area, Volume, etc. - look at the API for Parameter Type enumerations
    // newer APIs uses below method
    Autodesk.Revit.DB.ExternalDefinitionCreationOptions newParaOptions = new ExternalDefinitionCreationOptions(yourSharedParaName, SpecTypeId.String.Text);
    newParaOptions.UserModifiable = false; // Users cannot modify it, only Revit API can modify this parameter
    newParaOptions.Visible = false; // Users cannot see it in the properties, but the parameter appears in schedules, etc.
    newParaOptions.GUID = yourGuid; // set the above GUID to this new Shared Parameter
    paraGroup.Definitions.Create(newParaOptions);
  }
  catch (Exception ex)
  {
    sbCreateSharedParameterDefinition.AppendLine(ex.Message.ToString());
  }
  if (sbCreateSharedParameterDefinition.Length < 1)
  {
    System.Windows.Forms.MessageBox.Show("Shared Parameter Definition:" +
    "\r\n" +
    "\r\n" + " " + yourSharedParaName +
    "\r\n" +
    "\r\n" + "was created.", "Task complete");
  }
  else if (sbCreateSharedParameterDefinition.Length > 0)
  {
    System.Windows.Forms.MessageBox.Show("Shared Parameter Definition was not created because:" +
    "\r\n" +
    "\r\n" + " " + sbCreateSharedParameterDefinition.ToString(), "Error");
  }
}

Thank you very much, Adrian, for kindly implementing and sharing this solution!

Getting Started with the Parameter Service

Archi shared a nice series of articles describing step by step how get started with the parameter service:

... a much anticipated cloud service from Autodesk that spreads across the entire ecosystem, not just Revit, and comes to improve parameter management and collaboration for teams. For BIM managers with access to the Autodesk Construction Cloud, you can now say goodbye to the old shared parameter txt files, and instead use a centralized cloud service that allows bulk operation, tagging and search capabilities.

Many thanks to Archi for putting together this comprehensive tutorial!

Parameter Service

Happy Holidays!

I wish you a peaceful end of the year, calm twelve nights and restful holidays!

Dino in snow