Parameter not updating!

Parameter not updating!

Bruno_Neves_Pires_Silva
Advocate Advocate
1,718 Views
5 Replies
Message 1 of 6

Parameter not updating!

Bruno_Neves_Pires_Silva
Advocate
Advocate

I am trying to update a parameter in some pipes, but its not working, what I am doing wrong ? Please see my code below.

 

I've saw this post:

http://forums.autodesk.com/t5/revit-api/parameters-not-updating/m-p/4311799#M4140

But the solution provided by Augusto did not work for me, using the method "Set" instead of "SetValueString".

 

The parameter type is string.

 

 

public void app_Doc_Change(object sender, DocumentChangedEventArgs args)
{
Document doc = args.GetDocument();
ElementFilter filtro = new ElementClassFilter(typeof(Pipe));
ICollection<ElementId> col = args.GetModifiedElementIds(filtro);

if (col.Count == 0)
return;

string cod_str = "INTT:COD_MAT_COMPLETO",
cod_pre_str = "INTT:COD_PRE_MAT";

bool flag = false;
using (Transaction t = new Transaction(doc, "Atualizar diametro tubos"))
{
foreach (ElementId id in col)
{
Element el = doc.GetElement(id);
Parameter prm1 = el.LookupParameter("Size");
if (prm1 != null)
{
Parameter prm2 = el.LookupParameter(cod_str);
if (prm2 != null)
{
ElementType type = doc.GetElement(el.GetTypeId()) as ElementType;
Parameter prm3 = type.LookupParameter(cod_pre_str);
if (prm3 != null)
{
string valor = prm3.AsString() + "-" + prm1.AsString();
if (prm2.UserModifiable)
{
prm2.SetValueString(valor); //<= Value not updating!
//prm2.Set(valor); //<= I tried this and didnt work too.
flag = true;
}
}
}
}
}
if (flag)
t.Commit();
else
t.Dispose();
}
}

0 Likes
Accepted solutions (1)
1,719 Views
5 Replies
Replies (5)
Message 2 of 6

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

Arnost said:


"Documents are always read-only during DocumentChanged events, thus no elements can be changed."

http://forums.autodesk.com/t5/revit-api/cannot-change-currently-created-element-parameters/m-p/57965...

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 6

Bruno_Neves_Pires_Silva
Advocate
Advocate

Oh my God! Thank you, Revitalizer. Of course, it makes all sense. 

 

  But do you have any sugestion to me ? I need to change a parameter in the pipe if the diameter changes.

0 Likes
Message 4 of 6

Revitalizer
Advisor
Advisor

Hi,

 

you could use an IUpdater which reacts to geometry changes, to change a non-geometric parameter (which wouldn't trigger the IUpdater itself).

 

 

Cheers,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 6

Bruno_Neves_Pires_Silva
Advocate
Advocate

Thank you again, Revitalizer.

 

   I am trying to implement this IUpdater, but is not triggering. Can you help me do find out why ?

 

public Result OnStartup(UIControlledApplication app)
{

 

TDiamChanger updater = new TDiamChanger(app.ActiveAddInId);
UpdaterRegistry.RegisterUpdater(updater);

ElementClassFilter filter = new ElementClassFilter(typeof(Pipe), true);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter,
Element.GetChangeTypeGeometry());


return Result.Succeeded;

}

 

class TDiamChanger : IUpdater
{
static AddInId _appId;
UpdaterId _updaterId;
FailureDefinitionId _failureId = null;

public TDiamChanger(AddInId addInId)
{
_appId = addInId;
_updaterId = new UpdaterId(_appId, new Guid("6f453eba-4b9a-40df-b637-eb72a9ebf008"));
_failureId = new FailureDefinitionId(new Guid("33ba8315-e031-493f-af92-4f417b6ccf70"));
FailureDefinition failureDefinition = FailureDefinition.CreateFailureDefinition(_failureId, FailureSeverity.Error, "");
}
public void Execute(UpdaterData data)
{
 //Do something...
}
public string GetAdditionalInformation()
{
return "";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.MEPSystems;
}
public UpdaterId GetUpdaterId()
{
return _updaterId;
}
public string GetUpdaterName()
{
return "";
}
}

0 Likes
Message 6 of 6

Well, the main post about the parameter is solved, I will create another post about the IUpdater, and set this one as solved. 

 

Thank you again, Revitalizer.

0 Likes