Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IUpdater Trigger based on parameter change

39 REPLIES 39
Reply
Message 1 of 40
adeuley
2850 Views, 39 Replies

IUpdater Trigger based on parameter change

I writing an API to do some calculations whenever a certain parameter is changed. I have gotten it to work using the .GetChangeAny trigger but can not figure out how to get it to change only if a certain parameter has been changed. I currently it being registered during startup and I think that is my problem since I can't find the parameter since there isn't any document open. I even tried hard coded the element ID and that didn't seem to work either. Any insight would be greated appreciated.

 

Thanks

39 REPLIES 39
Message 21 of 40
adeuley
in reply to: arnostlobel

Won't that filter for just a specific type? It would seem like I need to specify the element ID for each type that contains the parameter and that doesn't make sense because a new type may be made during design and then I would need to add that element ID. Maybe I'm wrong I'm still fairly new to the API. Would you be able to give me a code example of how you would create a trigger for a type parameter. Even if it is a built in one. I should be able to figure out from there how to use a shared parameter. Thanks again for all of your help.

Message 22 of 40
Ning_Zhou
in reply to: arnostlobel

i did quick test w/ Harry's code, here's my finding:
1) for non-shared parameters, works OK for both instance and type parameter
2) for shared parameters, works OK for type parameter only
very odd, can anyone confirm it? perhaps i did something wrong.
Message 23 of 40
adeuley
in reply to: Ning_Zhou

Did you have to change yoru filter to get it to work with type parameters or did it work with them just the way it is written?

Message 24 of 40
Ning_Zhou
in reply to: adeuley

filter is OK, just follow what arnostlobel suggested
Message 25 of 40
adeuley
in reply to: Ning_Zhou

Maybe its the fact that I am still fairly new to the Revit API but I am having trouble understanding how to use the GetTypeID() that arnostlobel suggested in the IUpdater. I don't understand where it should be used at. Can you explain a little more please. Thank you.

Message 26 of 40
Ning_Zhou
in reply to: adeuley

Parameter instanceParam = e.get_Parameter(paramName);
Parameter typeParam = doc.GetElement(e.GetTypeId()).get_Parameter(paramName);
Message 27 of 40
adeuley
in reply to: Ning_Zhou

I'm still confused sol et me try and explain what I am trying to do and show you the code I have been trying and changing based on your suggestion and maybe you can enlighten me to what I am doing wrong.

 

I am trying to create something that will run when a project is opened and look for a specific parameter within the family types of what is loaded and then create an updater based on that parameter. I have hacked some code together from Harry's webpage that I referenced and the help files.

I have tested the code after changing the element class filter from FamilySymbol to FamilyInstance while also changing the parameterName from a shared parameter name ("Image Height") to a built in parameter name, using Model for type parameter and Comments for the instance parameter). It will work with both ,a shared parameter or a built in parameter, if I set the class filter to Family Instance. If I set the class filter to FamilySymbol it only works with a built in parameter. I have checked element Id of the "Image Height" parameter as both a type parameter and an instance parameter and it is the same, so whether I get the parameter id from a type or an instance doesn't seem to matter.

 

Here is the code that I am using now:

 

public void Test_2()
        {
            UIDocument UIdoc = this.ActiveUIDocument;
             Document doc = UIdoc.Document;
             ParameterUpdater pUpdater = new ParameterUpdater(Application.ActiveAddInId);
             UpdaterRegistry.RegisterUpdater(pUpdater);
            
            FilteredElementCollector eCollector = new FilteredElementCollector(doc);
            eCollector.OfCategory(BuiltInCategory.OST_CommunicationDevices);
            
            String parameterName = "Image Height";
            
            foreach (Element e in eCollector){
                foreach (Parameter p in e.Parameters){
                    if (p.Definition.Name == parameterName) {
                        UpdaterRegistry.AddTrigger(pUpdater.GetUpdaterId(),new ElementClassFilter(typeof(FamilySymbol)), Element.GetChangeTypeParameter(p));
                    }
                }
                        
            }
        }

 

I really appreciate all of your help and sorry that I am just not getting how to make this work with a type shared parameter. I am intrigued that you were able to though. I understand how GetTypeId() would work if I was selecting the elements and look just for a certain parameter by name but what I am doing is iterating through all of the parameters of the element. Would you be able to show me  what i would need to change in my code and also explain why?

 

Thanks again for helping this newbie out.

Message 28 of 40
adeuley
in reply to: adeuley

Well I've finally gotten this to work. It only took me learning C#. I don't know why I couldn't get it to work in vb.net but I used an online translator to switch from vb.net to C# and cleaned up the code a little bit and it work right away. So I can say that it does work with both shared and built in parameters regardless of whether or not they are type or instance parameters. Thank you everyone for your help.

Message 29 of 40
Ning_Zhou
in reply to: adeuley

does it also work for shared instance parameter? i did testing months ago, as i said i may miss something simple.
Message 30 of 40
adeuley
in reply to: Ning_Zhou

I must admit I jumped the gun on admiting that it was the solution. I did some further testing and I still can't get it to work with the type parameters but can get it to work with the instance parameters and I need the type parameters to work. I am going to do some more investigating today.

Message 31 of 40
gopinath.taget
in reply to: adeuley

Hello,

 

Do you have any new info for us? If not, can you summarize the issues and discussions so far. I will take it to the engineering team if necessary.

 

Thanks

Gopinath

Message 32 of 40
adeuley
in reply to: gopinath.taget

I do not have any new information but to summarize. I am trying to trigger code based on when a shared parameter is changed. I can get it to work with an instance parameter but not with a type parameter. Another contributor, Ning Zhou, can get it to work with a type parameter but not a shared parameter. 

 

Now let me explain overall what I am trying to do. I would like to have a program run that everytime a specific parameter is changed that a piece of code is run that informs my designers that they need to look at that element again to make sure that it is right. So I would like the program to determine the parameter ID when the project is opened and trigger some code when it is changed. I can get the parameter ID when the project opens but am having trouble getting a type parameter to trigger that code. It will trigger with an instance parameter though. At one point I was able to get a built in parameter that was a type parameter to trigger the code so it makes me believe that a shared parameter that is a type parameter should work also. I think that pretty much sums up where we are at. I have ideas for several APIs if I can get this one feature to work.

 

Thanks for your help.

Message 33 of 40
gopinath.taget
in reply to: adeuley

Hi Adeuley,

 

My understanding of Ning Zhou's response is slightly different. He says, he is able to get the trigger to work for shared parameter that is also a type parameter: "for shared parameters, works OK for type parameter only". So he does seem to get it to work that will meet your needs.

 

Hi Ning Zhou,

 

Can you please share code on how you got this working?

 

Thanks

Gopinath

Message 34 of 40
adeuley
in reply to: gopinath.taget

So I've been doing some more testing and gave up on finding a solution. I figured I would just add some instance parameters and set them with a formula equal to the type parameters I want to monitor. The issue now is that when I update the type parameter the instance parameter doesn't update. Any idea why that is? I think if I can figure that out all my problems will be solved. Thanks for your help.

Message 35 of 40
gopinath.taget
in reply to: adeuley

Does this happen both through the API and the UI or just the API? If its UI too, I might have to log a change request with the engineering team.

 

Cheers

Gopinath

Message 36 of 40
adeuley
in reply to: gopinath.taget

It happens through the UI. I have a feeling that it is the reason I am having an issue with the API though.

Message 37 of 40
Ning_Zhou
in reply to: gopinath.taget

sorry for late reply gopinath.taget, super busy and not in API mode recently.
as I mentioned early, I just did quick and dirty test using Harry's code months ago, something weird but not sure if I missed something simple.
Message 38 of 40
gopinath.taget
in reply to: adeuley

Yes, if the same problem exists in both API and UI, then it will have to log a change request with the engineering team. Would you mind providing a set of UI steps to reproduce the problem. I will then go ahead and log the change request.

 

Thanks
Gopinath

Message 39 of 40
adeuley
in reply to: gopinath.taget

Its actually quite simple. I added two shared parameters to a family. One was a type parameter and one was an instance parameter. I then set the instance parameter equal to the type parameter with a formula. I then loaded the family into a project. I changed the type parameter and the instance parameter didn't update like you think it would.

Message 40 of 40
gopinath.taget
in reply to: adeuley

Hello,

 

I have logged a change request with the Revit engineering team and emailed you separately about this with the details.

 

Best Regards

Gopinath

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community