cannot update parameter value

cannot update parameter value

Anonymous
Not applicable
297 Views
1 Reply
Message 1 of 2

cannot update parameter value

Anonymous
Not applicable

I tried to update a shared parameter's value using Set() method in my Command. I get the Parameter through its name and set a new value, it should seem very simple but the modification never displays in the property explorer and no error or exception thrown, I've no idea whether the value is changed. I googled a lot and found nothing fix my problem. What I can ensure is:

I set the Transaction Mode to TransactionMode.Automatic

The Document and the Parameter are not read-only when the method executed.

Here's my code snippet, could anyone tell me what's wrong in my code or give me suggestions? Thanks.

 

        private void OnSave()
        {
            if (!CanSave())
            {
                return;
            }
            Saved = false;
            foreach (var id in EditElmentIds)
            {
                var element = _doc.GetElement(id);
                foreach (var item in ChangedItems)
                {
                    var propertyName = CommonData.CodeParamsDic.FirstOrDefault(t => t.Key == item.Key.ToString()).Value;
                    var param = element.get_parameterByName(propertyName);
                    param?.Set(item.Value);
                }
            }
            MessageBox.Show("Completed!");
            EditElmentIds.Clear();
            ChangedItems.Clear();
        }

 

 

0 Likes
298 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous ,

Automatic Transaction Mode is considered obsolete.

Try to set the transactionmode to MANUAL and place your code inside the transaction.

Transaction actrans = new Transaction(doc);
                actrans.Start("Transaction Name");
                //YOUR CODE
                actrans.Commit();
               

 

see this link

https://thebuildingcoder.typepad.com/blog/2012/05/read-only-and-automatic-transaction-modes.html

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes