<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change Attribute Tags together in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650736#M18956</link>
    <description>&lt;P&gt;Thanks Micle,&lt;/P&gt;&lt;P&gt;i will try this, but my case is different.&lt;/P&gt;&lt;P&gt;I want to change the value of 2nd attribute if the 1st attribute value meets the criteria.&lt;/P&gt;&lt;P&gt;For example if &lt;STRONG&gt;Rev tag&lt;/STRONG&gt; is A then i want to change it to &lt;STRONG&gt;B&lt;/STRONG&gt; and also need to change the &lt;STRONG&gt;Date tag&lt;/STRONG&gt; to the &lt;STRONG&gt;new Date&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I think Norman code is what i was looking for.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jul 2020 07:00:25 GMT</pubDate>
    <dc:creator>yoitsarun</dc:creator>
    <dc:date>2020-07-23T07:00:25Z</dc:date>
    <item>
      <title>Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9647777#M18952</link>
      <description>&lt;P&gt;I have code to change attribute tag text value. It is working fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i want to change another tag in the same block attribute.&lt;/P&gt;&lt;P&gt;that is , if i change 1st tag then 2nd tag also should be updated automatically.&lt;/P&gt;&lt;P&gt;Is there any way to do that??&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using (tr)
                {
                    BlockTableRecord btr =(BlockTableRecord)tr.GetObject(btrId,OpenMode.ForRead);                    
                    foreach (ObjectId entId in btr)
                    {
                        Entity ent =tr.GetObject(entId, OpenMode.ForRead)as Entity;
                        if (ent != null)
                        {
                            BlockReference br = ent as BlockReference;
                            if (br != null)
                            {
                                BlockTableRecord bd =(BlockTableRecord)tr.GetObject(br.BlockTableRecord,OpenMode.ForRead);                                
                                if (bd.Name.ToUpper() == blockName)
                                {                                    
                                    foreach (ObjectId arId in br.AttributeCollection)
                                    {
                                        DBObject obj =tr.GetObject(arId,OpenMode.ForRead);
                                        AttributeReference ar =obj as AttributeReference;
                                        if (ar != null)
                                        {
                                        if (ar.Tag.ToUpper() == attbName)
                                        {                                            
                                                //if (ar.TextString == "A") then i need to change another Tag
                                                
                                            ar.UpgradeOpen();
                                            ar.TextString = "B";
                                            ar.DowngradeOpen();                                            
                                        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//if (ar.TextString == "A") then i need to change another Tag&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How i could do this while on another tag? Any suggestions&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 20:38:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9647777#M18952</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2020-07-21T20:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650239#M18953</link>
      <description>&lt;P&gt;You can simply loop through the AttributeCollection twice: the first time, find the first attribute, if found update its value and break the loop. Then you do the loop again to find the second attribute and update it accordingly. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800000"&gt;bool found=false;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;foreach (ObjectId id in br.AttributeCollection)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var att=(AttributeReference)tr.GetObject(id, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (att.Tag.ToUpper()=="A")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; att.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; att.TextString="xxxxxxx";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#800000"&gt;found=true;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800000"&gt;&amp;nbsp; &amp;nbsp; break;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#800000"&gt;if (found)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; foreach (ObjectId id in br.AttributeCollection)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; var att=(AttributeReference)tr.GetObject(id, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if (att.Tag.ToUpper()=="B")&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'' Update it here&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, you can loop through it once to find both attributes and update one or both later:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AttributeReference attA=null;&lt;/P&gt;
&lt;P&gt;AttributeReference attB=null;&lt;/P&gt;
&lt;P&gt;foreach (ObjectId id in br.AttributeCollection)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var att=(AttributeReference)tr.GetObject(id, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (att.Tag.ToUpper()=="A") attA=att;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;if (att.Tag.ToUpper()=="B") attB=att;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (attA!=null)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; attA.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; attA.TextString="xxxxxxx";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (attB!=null)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; attB.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; attB.TextString="yyyyyy";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 22:23:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650239#M18953</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-07-22T22:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650494#M18954</link>
      <description>&lt;P&gt;Thanks Norman,&lt;/P&gt;&lt;P&gt;I will try this.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 02:14:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650494#M18954</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2020-07-23T02:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650616#M18955</link>
      <description>&lt;P&gt;Hi Aruntr&lt;/P&gt;&lt;P&gt;I developed a method for writing the attributes in all blocks of a dwg file.&lt;/P&gt;&lt;P&gt;The new values of attribute's tag are&amp;nbsp; collected in a dictionary &amp;lt;TAG, Value&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This method searches in all paper spaces (if your dwg file has more then one drawing), for all blocks (but you can specify the name of blocks and enter in the last foreach just for the blocks you need).&lt;/P&gt;&lt;P&gt;Hope this can help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void WriteAttributes(string fileName, Dictionary&amp;lt;string, string&amp;gt; drawingsData)
{
	if (!File.Exists(fileName)) return;
	try
	{
		using (var db = OpenSideDatabase(fileName))
		{
			using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
			{ 

				//all papers
				var dic = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);

				foreach (DBDictionaryEntry entry in dic)
				{
					//get the layout
					Layout layout = tr.GetObject(entry.Value, OpenMode.ForRead) as Layout;
					
					//jump if is modelSpace
					if (layout.ModelType) continue;
					
					BlockTableRecord btr = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord;
					foreach (ObjectId id in btr)
					{
						Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
						if (ent == null) continue;

						BlockReference br = ent as BlockReference;
						if (br == null) continue;

						BlockTableRecord bd = (BlockTableRecord)tr.GetObject(br.BlockTableRecord, OpenMode.ForRead);
					   
						foreach (ObjectId arId in br.AttributeCollection)
						{
							AttributeReference ar = tr.GetObject(arId, OpenMode.ForRead) as AttributeReference;
							if (ar == null) continue;

							ar.UpgradeOpen();
							
							//instead of switch could be:
							// ar.TextString = drawingsData[ar.Tag];
							// better drawingsData.TryGetValue(...)
							
							switch (ar.Tag)
							{
								case "TAG1":
									ar.TextString = drawingsData["TAG1"];
									break;
								//other cases
								case....
								default:
									break;
							}
							ar.DowngradeOpen();
						}
					}

				}
			 
			}
			db.SaveAs(fileName, true, DwgVersion.Current, null);
		}
	}
	catch (System.Exception ex)
	{
		//messages...
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 05:15:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650616#M18955</guid>
      <dc:creator>micle.space</dc:creator>
      <dc:date>2020-07-23T05:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650736#M18956</link>
      <description>&lt;P&gt;Thanks Micle,&lt;/P&gt;&lt;P&gt;i will try this, but my case is different.&lt;/P&gt;&lt;P&gt;I want to change the value of 2nd attribute if the 1st attribute value meets the criteria.&lt;/P&gt;&lt;P&gt;For example if &lt;STRONG&gt;Rev tag&lt;/STRONG&gt; is A then i want to change it to &lt;STRONG&gt;B&lt;/STRONG&gt; and also need to change the &lt;STRONG&gt;Date tag&lt;/STRONG&gt; to the &lt;STRONG&gt;new Date&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I think Norman code is what i was looking for.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 07:00:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650736#M18956</guid>
      <dc:creator>yoitsarun</dc:creator>
      <dc:date>2020-07-23T07:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Change Attribute Tags together</title>
      <link>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650807#M18957</link>
      <description>&lt;P&gt;Norman could hardly be wrong...&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 07:56:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/change-attribute-tags-together/m-p/9650807#M18957</guid>
      <dc:creator>micle.space</dc:creator>
      <dc:date>2020-07-23T07:56:31Z</dc:date>
    </item>
  </channel>
</rss>

