Creating a IUpdater that triggers when I change pipe diameter

Creating a IUpdater that triggers when I change pipe diameter

Bruno_Neves_Pires_Silva
Advocate Advocate
1,865 Views
15 Replies
Message 1 of 16

Creating a IUpdater that triggers when I change pipe diameter

Bruno_Neves_Pires_Silva
Advocate
Advocate

Hello,

 

   How can I create a IUpdater that triggers when I change a pipe diameter?

 

 

I tried this:

 

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

ElementClassFilter filter = new ElementClassFilter(typeof(Pipe), true);
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter,
Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER)));

 

But it didnt fire.

 

and this other option:

Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM))

 

and this:

Element.GetChangeTypeGeometry()

 

but nothing worked, it didnt fire.

 

This worked: Element.GetChangeTypeAny(), but I can't start a transaction (looks like in read-only mode), so I cant change the parameter I need.

 

 

Some more pieces of my code:

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
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, "teste");
}
public void Execute(UpdaterData data)
{
Document doc = data.GetDocument();
using (Transaction t = new Transaction(doc, "Atualizar diametro tubos"))
{
t.Start();

t.Commit();
}

}
public string GetAdditionalInformation()
{
return "";
}
public ChangePriority GetChangePriority()
{
return ChangePriority.MEPSystems;
}
public UpdaterId GetUpdaterId()
{
return _updaterId;
}
public string GetUpdaterName()
{
return "";
}
}

 

 

Can someone help me ?

 

Thanks in advance.

 

0 Likes
Accepted solutions (1)
1,866 Views
15 Replies
Replies (15)
Message 2 of 16

Revitalizer
Advisor
Advisor

Hi,

 

no need to start a transaction in IUpdater.Execute method since it is part of the triggering transaction.

 

No ideas so far; only: it is ChangePriority.MEPAccessoriesFittingsSegmentsWires, isn't it ?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

Hi, Revitalizer.

 

   Indeed, there was no need to start a new transaction, thank you.

 

I dont know if is ChangePriority.MEPAccessoriesFittingsSegmentsWires, but I changed  to it 🙂

 

About the triger: I still didnt find out what is the right one, but trying Element.GetChangeTypeAny(), it fired the IUpdater, but it returned 3 elements instead of just the pipe I changed the diameter. One of this 3 is the right pipe.

 

But the funny thing about it is that I couldnt get the ElementType to get my desired parameter:

 

ElementType type = doc.GetElement(el.GetTypeId()) as ElementType;

 

It returned null, but in other functions I created to do the same thing (not using IUpdater), it did not returned null, and I coud get the ElementType, after that the parameter, and after that, set the desired value of the parameter.

 

Any thoughts about that ?

 

Thank you again,

 

Bruno Neves Pires Silva

 

0 Likes
Message 4 of 16

Revitalizer
Advisor
Advisor

Hi,

 

wow, another strange phenomenon...

 

I think your first described problem is related to this issue:

http://forums.autodesk.com/t5/revit-api/getchangetypeparameter-not-triggered-for-instance-length-par...

 

In fact, it should work with BuiltInParameter.RBS_PIPE_OUTER_DIAMETER or BuiltInParameter.RBS_PIPE_DIAMETER, too.

 

It seems to be a defect in the API...

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 16

Aaron.Lu
Autodesk
Autodesk

Dear Bruno,

I can confirm it is a problem, so I logged it as an issue in our system, the number is:  REVIT-84212

thanks for reporting this.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 6 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

What is a problem, Aaron ? 

 

  The fact that IUpdater is not triggering or the fact that ElementType is returning null ? Or both ?

 

Thank you.

0 Likes
Message 7 of 16

Aaron.Lu
Autodesk
Autodesk
The IUpdater is supposed to be triggered by change pipe diameter (RBS_PIPE_DIAMETER_PARAM), but it is not.

another problem is: even if you use ChangeTypeAny, you can not get the pipe from IUpdater.Execute's parameter, did you see this problem?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 8 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

Hi, Aaron.

 

   I can confirm the trigger bug.

 

  But I can get the pipe using ChangeTypeAny, what I can not get is the ElementType of the pipe. I can get the ElementType using the event document_change, but then I cannot change anything because its read only.

 

Can you give me an idea ? I need to change a parameter in the pipe if the user changes its diameter.

 

 

Thanks for your reply.

0 Likes
Message 9 of 16

Aaron.Lu
Autodesk
Autodesk
Hi Bruno,

DMU should be allow us to modify document, in that case you can use External Event, which can be executed as next operation cycle of Revit.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 10 of 16

Aaron.Lu
Autodesk
Autodesk
Sorry, I was wrong,


DMU should allow us to modify document, but you can't start a transaction, because it is already within the scope of a transaction. So you just change the parameter without starting any transaction.

There maybe some limitations, e.g. you can't Edit family or call PickObject, but in that case you can use External Event, which can be executed as next operation cycle of Revit.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 11 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

Dear Aaroon, 

 

 

    Thank you for your reply. But maybe I am not understanding what you mean.

 

     Isnt this DMU (Dynamic Model Updating) that you are sugesting  the IUpdater that I am already using and is not working  ?

 

     How can I get the parameter to change if I can't get the ElementType to get this parameter  (using MDU)? Please read the previous messages, when I am using the doc change event I can get the elementType, and with the ElementType I can get the parameter, but I cant change it because its read only.

   With DMU I cannot get the ElementType to get the parameter, the following code returns null:

 

ElementType type = doc.GetElement(el.GetTypeId()) as ElementType;

 

 

0 Likes
Message 12 of 16

Accepted solution

I've made it!!

 

   Combining the two events: appDocChange and the Iddling event.

 

appDocChange to collect then params, and the Iddling event to change then !!

   

0 Likes
Message 13 of 16

Aaron.Lu
Autodesk
Autodesk
That should be a problem if el.GetTypeId() not working for DMU, can you confirm the el is the same as what you get from DocumentChangedEvent?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 14 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

In DMU el.GetTypeId() returns invalid ( -1 ),

0 Likes
Message 15 of 16

Revitalizer
Advisor
Advisor

Hi,

 

you could try to get the ElementType by a parameter.

 

el.get_Parameter(SYMBOL_ID_PARAM).AsElementId();

or more common

el.get_Parameter(ELEM_TYPE_PARAM).AsElementId();

 

Just an idea.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 16 of 16

Bruno_Neves_Pires_Silva
Advocate
Advocate

Thank you, Revitalizer.

 

   I will try this sometime, but as stated above, I have found another solution.

0 Likes