In the add-in code, complete the following steps to gain access to the definition file:
The following list provides more information about the classes and methods in the previous diagram.
Because the shared parameter file is a text file, you can create it using code or create it manually.
Code Region 22-3: Creating a shared parameter file |
private void CreateExternalSharedParamFile(string sharedParameterFile) { System.IO.FileStream fileStream = System.IO.File.Create(sharedParameterFile); fileStream.Close(); } |
Because you can have many shared parameter files for Revit, it is necessary to specifically identify the file and external parameters you want to access. The following two procedures illustrate how to access an existing shared parameter file.
Set the shared parameter file path to app.Options.SharedParametersFilename as the following code illustrates, then invoke the Autodesk.Revit.Application.OpenSharedParameterFile method.
Code Region 22-4: Getting the definition file from an external parameter file |
private DefinitionFile SetAndOpenExternalSharedParamFile( Autodesk.Revit.ApplicationServices.Application application, string sharedParameterFile) { // set the path of shared parameter file to current Revit application.Options.SharedParametersFilename = sharedParameterFile; // open the file return application.OpenSharedParameterFile(); } |
The following sample illustrates how to traverse the parameter entries and display the results in a message box.
Code Region 22-5: Traversing parameter entries |
private void ShowDefinitionFileInfo(DefinitionFile myDefinitionFile) { StringBuilder fileInformation = new StringBuilder(500); // get the file name fileInformation.AppendLine("File Name: " + myDefinitionFile.Filename); // iterate the Definition groups of this file foreach (DefinitionGroup myGroup in myDefinitionFile.Groups) { // get the group name fileInformation.AppendLine("Group Name: " + myGroup.Name); // iterate the difinitions foreach (Definition definition in myGroup.Definitions) { // get definition name fileInformation.AppendLine("Definition Name: " + definition.Name); } } TaskDialog.Show("Revit", fileInformation.ToString()); } |
The following sample shows how to change the parameter definition group owner.
Code Region 22-6: Changing parameter definition group owner |
private void ReadEditExternalParam(DefinitionFile file) { // get ExternalDefinition from shared parameter file DefinitionGroups myGroups = file.Groups; DefinitionGroup myGroup = myGroups.get_Item("MyGroup"); if (null == myGroup) return; Definitions myDefinitions = myGroup.Definitions; ExternalDefinition myExtDef = myDefinitions.get_Item("MyParam") as ExternalDefinition; if (null == myExtDef) return; StringBuilder strBuilder = new StringBuilder(); // iterate every property of the ExternalDefinition strBuilder.AppendLine("GUID: " + myExtDef.GUID.ToString()) .AppendLine("Name: " + myExtDef.Name) .AppendLine("OwnerGroup: " + myExtDef.OwnerGroup.Name) .AppendLine("Parameter Group" + myExtDef.ParameterGroup.ToString()) .AppendLine("Parameter Type" + myExtDef.ParameterType.ToString()) .AppendLine("Is Visible: " + myExtDef.Visible.ToString()); TaskDialog.Show("Revit", strBuilder.ToString()); // change the OwnerGroup of the ExternalDefinition myExtDef.OwnerGroup = myGroups.get_Item("AnotherGroup"); } |