2 Replies Latest reply on Jul 16, 2011 8:59 AM by Ian Proudfoot

    Changing Element Attribute Values

    cannharvey

      I spent far to long trying to figure out how to change an element attribute value without the FDK's SetAttributes function, so I thought I'd spare someone else the time.

       

      Basically, you still get the attributes using the GetAttributes() function, but now you just set the beg.child.Attributes property to the updated attribute value.


      //starting with a selected element
      elemSelect=app.ActiveDoc.ElementSelection

       

      //get the current attributes
      var childattributes =elemSelect.beg.child.GetAttributes()

       

      //find the attribute and value you want to change, and change it to a new value.
      childattributes[0].values[0] = "New_Value"

       

      //now assign the edited attributes to the selected element.
      elemSelect.beg.child.Attributes=childattributes

       

      Depending on how you selected the element, I assume you could do the above with beg.parent as well, but it wasn't something I needed to consider.

       

      ~Christen

        • 1. Re: Changing Element Attribute Values
          OliverJohn Level 2

          Thanks for this--you've likely saved me a headache.

           

          While I hadn't hit this yet, it does apply to several of the projects on my to-do list. Based on the info in the OMV, I would have expected to be able to simply use a statement like myElement.Attributes[i].value[i] = "New_Value" which, as I'm sure you discovered, has no apparent effect at all.

           

          The other thing I noticed in my quick testing is that defining your attributes variable by using the method (x = myElement.GetAttributes()) or by referenceing the Attributes property (x = myElement.Attributes) seem to be functionally equivalent.

          • 2. Re: Changing Element Attribute Values
            Ian Proudfoot Level 3

            Another potential headache and bug-in-waiting can be caused by selecting an attribute directly by its array index. Always resolve the attribute name to its array index first. The reason for this is that the attribute's index could easily change at any time while the attribute name will remain constant.