Message 1 of 4
Add/Set a System Pipes Custom Parameters
Not applicable
09-08-2013
04:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
Is it possible to add a custom parameter to a System Pipe? I have successfully added many shared parameters to the shared parameter file. And I am also able to set a FamilyInstances' shared parameter (called 'Chainage').
But I am unable to set a System Pipes shared parameter 'Chainage'. It throws the exception:
Object reference not set to an instance of an object
This error has occurred before when I tried to set a parameter that doesn't exist. Is it possible to add and set a custom parameter to a System Pipe? If so how do I do it?
My below code successfully registers some shared parameters, successfully sets a FamilyInstance's shared param but fails when I try to set a System Pipes same shared param:
public static FamilyInstance createPit(Document doc, XmlNode pitNode, XmlNamespaceManager nsmgr)
{
if (!setupSharedParameters(doc))
return null;
// Create family instance and set param: Succeeds
double x = getXmlNodeDouble(pitNode, "ns:x", nsmgr);
double y = getXmlNodeDouble(pitNode, "ns:y", nsmgr);
double z = getXmlNodeDouble(pitNode, "ns:z", nsmgr);
FamilyInstance instance = doc.Create.NewFamilyInstance(new XYZ(x, y, z), pitSymbol, StructuralType.NonStructural);
instance.get_Parameter("Road Name").Set("IRULE");
// Create System pipe and set param: Fails
Pipe pipe = doc.Create.NewPipe(new XYZ(x, y, z), new XYZ(x+10, y, z), pipeType);
// Note pipe exists and is not null
pipe.get_Parameter("Road Name").Set("IRULE"); // ERROR OCCURS HERE
return instance;
}
public static bool setupSharedParameters(Document doc)
{
try
{
if (SHARED_PARAMS_SETUP)
return SHARED_PARAMS_SETUP;
//prepare shared parameter file
String path = Assembly.GetExecutingAssembly().Location;
int index = path.LastIndexOf("\\");
String newPath = path.Substring(0, index);
newPath += "\\RevitParameters.txt";
if (File.Exists(newPath))
File.Delete(newPath);
FileStream fs = File.Create(newPath);
fs.Close();
doc.Application.SharedParametersFilename = newPath;
//Open shared parameter file
DefinitionFile parafile = doc.Application.OpenSharedParameterFile();
//get walls category
Category wallCat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_PlumbingFixtures); // .OST_Walls);
CategorySet categories = doc.Application.Create.NewCategorySet();
categories.Insert(wallCat);
InstanceBinding binding = doc.Application.Create.NewInstanceBinding(categories);
//Create a group
DefinitionGroup apiGroup = parafile.Groups.Create("APIGroup");
//Create a visible "VisibleParam" of text type.
BindingMap bindingMap = doc.ParameterBindings;
Definition visibleParamDef = apiGroup.Definitions.Create("Type", ParameterType.Text, true);
bindingMap.Insert(visibleParamDef, binding);
visibleParamDef = apiGroup.Definitions.Create("Chainage", ParameterType.Number, true);
bindingMap.Insert(visibleParamDef, binding);
visibleParamDef = apiGroup.Definitions.Create("Road Name", ParameterType.Text, true);
bindingMap.Insert(visibleParamDef, binding);
SHARED_PARAMS_SETUP = true;
return SHARED_PARAMS_SETUP;
}
catch (Exception e)
{
return false;
}
}