PDA

View Full Version : Create Parameter Problem



michael.montagne
2008-03-05, 10:06 PM
I'm getting inconsistent results with this code. It is ripped right out of the SDK and should add a shared parameter to the project file. If I open a new project it works great. But on subsequent tries, it fails to add the parameter at all.

public bool SetNewParameterToRooms (string sNewParam)
{
//Open the shared parameters file
// via the private method AccessOrCreateExternalSharedParameterFile
DefinitionFile informationFile = AccessOrCreateExternalSharedParameterFile();
System.Diagnostics.Debug.WriteLine("Setting Parameter " + sNewParam);
if (null == informationFile)
{
return false;
}

// Access an existing or create a new group in the shared parameters file
DefinitionGroups informationCollections = informationFile.Groups;
DefinitionGroup informationCollection = null;

informationCollection = informationCollections.get_Item("Rooms");

if (null == informationCollection)
{

System.Diagnostics.Debug.WriteLine("Rooms group not found in sharedparams.txt");
return false;
}

// Access an existing or create a new external parameter definition
// belongs to a specific group
Definition information = informationCollection.Definitions.get_Item(sNewParam);

if (null == information)
{
informationCollection.Definitions.Create(sNewParam, Autodesk.Revit.Parameters.ParameterType.Text);
information = informationCollection.Definitions.get_Item(sNewParam);
}

// Create a new Binding object with the categories to which the parameter will be bound
CategorySet categories = m_revit.Create.NewCategorySet();
Category roomsClassification = null;

// use category in instead of the string name to get category

roomsClassification = m_revit.ActiveDocument.Settings.Categories.get_Item(BuiltInCategory.OST_Rooms);
categories.Insert(roomsClassification);

InstanceBinding caseTying = m_revit.Create.NewInstanceBinding(categories);

// Add the binding and definition to the document
bool boundResult = m_revit.ActiveDocument.ParameterBindings.Insert(information, caseTying);

return boundResult;
}

GuyR
2008-03-05, 10:33 PM
So is the boundResult returning true or false? If it works on a new project but not an existing project could it be there is already a parameter with the same name in that category?

HTH,

Guy

michael.montagne
2008-03-05, 10:42 PM
boundResult is returning false. Not sure what it returns during successful tries. It should return false if there is already a param in the project. Although I have ended up with dupes...not sure how that happened. I can recreate the issue by opening a NEW project and running the routine. All params are added (whether TEXT or INTEGER or NUMBER...seems odd that should work). Then I'll delete a few run it again. Nothing is added. So i'll close and save and open it again. Try again....nothing added. I'm stumped.

-mjm

GuyR
2008-03-05, 10:53 PM
Debug the project, stepping through and see where the problem occurs. Either that or post the project . How are you deleting? if you undo operations on a new project and then run again does it still happen?

Guy

michael.montagne
2008-03-05, 11:01 PM
Stepping thru provides no insight. But boundResult DOES return true upon success. To delete I'm using the Parameters dialogue box in Revit. An undo immediately afterward remove the parameter and does allow me to add it again thru code. I've attached the project. There is a database component that won't work obviously but I've pretty well isolated that function and can see that it has issues.
Thanks for all your help.

-mjm