Cannot change currently created element parameters

Cannot change currently created element parameters

Anonymous
Not applicable
1,038 Views
5 Replies
Message 1 of 6

Cannot change currently created element parameters

Anonymous
Not applicable

Hello world!) Need your help.

I`m creating macro with subscribtion on DocumentChanged event on startup. One of newly created element`s parameter should change immediately after element`s creation. But  parameter value couldn`t be set, because the document is still read only.

How could I bypass it?

0 Likes
1,039 Views
5 Replies
Replies (5)
Message 2 of 6

arnostlobel
Alumni
Alumni
Hello Wrath_!

Documents are always read-only during DocumentChanged events, thus no elements can be changed. If you need to change elements in effect of them getting changed (or other elements getting changed) you need to use a Dynamic updater. With a DU you subscribe to whatever kind of changes you want to react to, and when such changes happen your DU will get invoked and you'll be able to apply your additional changes.

However, perhaps you do not want to subscribe to DocumentChanged at all. I am having a feeling that what you actually want is either the DocumentCreated or DocumentOpened event, which are events that occur when a document is created or opened, respectively. The DocumentChanged event, on the other hand is invoked when the model gets modified (like when some elements change).
Arnošt Löbel
Message 3 of 6

Anonymous
Not applicable

Thanks a lot for your answer.

I`ve begun with DU, but then decided to try "easier way".)

I think, I need DocumentChanged event exactly - parameter of newly created element should be changed immediately after element creation.

Is it possible to register updater, if document contains no elements of needed category? Or I should register updater in DocumentChanged event handler?

0 Likes
Message 4 of 6

Revitalizer
Advisor
Advisor

Hi Wrath_,

 

DocumentChanged event would be triggered again if you were able to change parameter values at that time.

It would result in an endless loop.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 6

Anonymous
Not applicable
Thanks everybody. I`ve got needed result with DMU.
0 Likes
Message 6 of 6

Anonymous
Not applicable

Hello. I know this is after such a long time. So I created a ViewSection Instance and want to set a string value to a parameter (pre-created by me) of the newly created section. I used IUpdater interface. And the catch told me that the parameter is read-only. Can you please look at this piece of my code and tell me what I did wrong? 

 

public class CreateViewSections : IExternalCommand
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// I do something here

tUp = new TUpdate(commandData.Application.ActiveAddInId, field);
                UpdaterRegistry.RegisterUpdater(tUp, doc);
                UpdaterRegistry.RemoveAllTriggers(tUp.GetUpdaterId());
                UpdaterRegistry.AddTrigger(tUp.GetUpdaterId(), allSections, Element.GetChangeTypeElementAddition());

                using (Transaction t = new Transaction(doc, "Create View Sections"))
                {
                    t.Start();
                    // Create sections
                    t.Commit();
}


public class TUpdate : IUpdater
    {
        static UpdaterId _updaterId;
        static AddInId Id;
        private FieldClass _field;

        public TUpdate (AddInId aId)
        {
            Id = aId;
            _updaterId = new UpdaterId (Id, new Guid("75674032-EE16-481B-B9F5-46E878DF3F12"));
        }

        public void Execute(UpdaterData data)
        {
            try
            {
                int i = 0;
                foreach (ElementId id in data.GetAddedElementIds())
                {
                    Document doc = data.GetDocument();
                    Element e = doc.GetElement(id);
                    e.LookupParameter("View Name").Set(i.ToString());
                    e.LookupParameter("TMark").Set(i.ToString());
                    i++;
                }
            }
            catch (Exception e)
            {
                TaskDialog.Show("TUpdate", e.Message);
            }
           
            
        }

        public string GetAdditionalInformation()
        {
            return "Additional Info";
        }

        public ChangePriority GetChangePriority()
        {
            return ChangePriority.Structure;
        }

        public UpdaterId GetUpdaterId()
        {
            return _updaterId;
        }

        public string GetUpdaterName()
        {
            return "TUpdate";
        }
    }
0 Likes