PDA

View Full Version : Setting a shared parameter with API



consultskc
2008-02-25, 12:44 AM
Hi all,

I hope someone can help me. I need to set a shared parameter attached to a Room object using the API. I have been using the Room Schedule project from the SDK as a reference. The code in the SDK is parameter specific (External ID) and I need a general way to set a single parameter or a series of parameters. Does anybody have the C# technique to set a shared parameter?

Each room has a Target Area shared parameter that has been added previously. Data is read in from Excel with the value to be set in each room. Here is an example from the SDK:

private void SetExternalRoomIdToRoomId(Room room)
{
ElementId elemId = room.Id;
Room updateRoom = m_commandData.Application.ActiveDocument.get_Element(ref elemId) as Room;
foreach (Parameter sharedParam in room.Parameters)
{
if (String.Compare(sharedParam.Definition.Name, RoomsData.SharedParam) == 0)
{
// It's safer to encapsulate shared parameter update in transaction.
m_commandData.Application.ActiveDocument.BeginTransaction();
sharedParam.Set(room.Id.Value.ToString());
m_commandData.Application.ActiveDocument.EndTransaction();
return;
}
}
}

I am not sure if this example can help me. Any opinions and tricks I could use?

Sean Campbell

P.S. Is it just me or is the documentation for the Revit API really poor compared to AutoCAD?

consultskc
2008-02-25, 01:32 PM
I found my answer. It was actually easier than I thought. To set the value of a shared parameter, I used the following code:

case RoomsData.TargetArea:
Parameter targetAreaParam = newRoom.get_Parameter(m_TargetAreaDef);
if (null != targetAreaParam)
{
Double TA = System.Convert.ToDouble(colValue); // Data types must match
TargetAreaParam.Set(TA);
}
break;

Works great, but now I have a problem that I can only have 3 shared parameters attached to the rooms and I need 6. Any ideas?

I will look into the problem more later on.

Sean