Add/Set a System Pipes Custom Parameters

Add/Set a System Pipes Custom Parameters

Anonymous
Not applicable
1,168 Views
3 Replies
Message 1 of 4

Add/Set a System Pipes Custom Parameters

Anonymous
Not applicable

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; } }

 

0 Likes
1,169 Views
3 Replies
Replies (3)
Message 2 of 4

ollikat
Collaborator
Collaborator
Hi

Yes you can have shared parameter for pipes. You just need to use BuiltInCategory.OST_PipeCurves category in the binding.
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for the reply 🙂

 

I altered my code so that the plumbing fixture category is used in the binding. And then finally altered/set a pipes params but the parameter is not appearing in the properties tab (when I select the pipe).

 

Note: the shared parameters are visible and the error I mentioned above still occurs.

 

Any ideas what I am doing wrong?

 

My code:

 

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();

		Category plumbCat       = doc.Settings.Categories.get_Item(BuiltInCategory.OST_PlumbingFixtures);
		Category pipeCat        = doc.Settings.Categories.get_Item(BuiltInCategory.OST_PipeCurves);
		CategorySet categories  = doc.Application.Create.NewCategorySet();
		//categories.Insert(plumbCat);
		categories.Insert(pipeCat);

		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("Name", ParameterType.Text, true);
		bindingMap.Insert(visibleParamDef, binding);
		SHARED_PARAMS_SETUP = true;
		return SHARED_PARAMS_SETUP;
	}
	catch (Exception e)
	{
		return false;
	}
}

 

0 Likes
Message 4 of 4

Anonymous
Not applicable
Actually there error I get is different. The error is:

This element does not support assignment of a user specified-name
0 Likes