Update Element location based on parameter value

Update Element location based on parameter value

sensiblehira
Advocate Advocate
245 Views
2 Replies
Message 1 of 3

Update Element location based on parameter value

sensiblehira
Advocate
Advocate

I have created X,Y,Z parameters for my family Instances and I want to update the location of my elements if values of my parameters are changed (without having to click anywhere else).

Is there a way to do this?

I am trying to trigger an event from OnStartUp, but since it is a custom parameter I can use GetChangeTypeParameter

GetChangeTypeAny is not responding to the changes in my case

I do not want to call the trigger for externalcommand

(the end user doesn't want to click anywhere else after modifying the parameter)

0 Likes
Accepted solutions (1)
246 Views
2 Replies
Replies (2)
Message 2 of 3

scgq425
Advocate
Advocate

Hi @sensiblehira :

is like a monitor document changed issue , if the element changed or modify-location , u can use the interface `DocumentChangedEventArgs`  to get document changed , and then monitor the target element which need to update location-paramaters.

 /// <summary>
        /// events about revit document changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AppChangedDocumented(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
        {
            var doc = e.GetDocument();
            try
            {
                var addElems = e.GetAddedElementIds();
            }
            catch (NullReferenceException)
            {

            }


            try
            {
                var modifyElems = e.GetModifiedElementIds();
            }
            catch (Exception)
            {

            }

            try
            {
                var deletedElems = e.GetDeletedElementIds();
                foreach (var deletedElem in deletedElems)
                {

                    var deleted = new DeletedJsonStruct()
                    {
                        ElementId = deletedElem.ToString(),
                        Locate = "(1,2,3),(3,4,5)",
                        MatchName = "Deleted"
                    };

            }
            catch (NullReferenceException)
            {

            }

        }

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 3

sensiblehira
Advocate
Advocate
Accepted solution

So here is how I solved my problem:

I was creating my Parameters from my code so

1- I firstly shifted the creation of my project parameters to the OnDocumentOpened Event

2- I returned the GUID of the parameter being created as the return type of my parameter creation method

3- using the Guid i got the parameter and its element id

4- Registered my updater in OnDocumentOpened Event (since I cannot create parameters in OnStartup I cannot register the updater without creating the parameter first)

0 Likes