• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing Element Attribute Values

New Here ,
Jul 15, 2011 Jul 15, 2011

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

805

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 15, 2011 Jul 15, 2011

Copy link to clipboard

Copied

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.value = "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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 16, 2011 Jul 16, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines