<?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: Moving Annotative Object to Current Anno Scale in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12720924#M4421</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        public void AddCurrentAnnoScaleAndRemoveOthers()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            TypedValue[] types = new TypedValue[]
            {
                new TypedValue((int)DxfCode.Operator, "&amp;lt;or"),
                new TypedValue((int)DxfCode.Start, "INSERT"),
                new TypedValue((int)DxfCode.Start, "MTEXT"),
                new TypedValue((int)DxfCode.Start, "MULTILEADER"),
                new TypedValue((int)DxfCode.Start, "DIMENSION"),
                new TypedValue((int)DxfCode.Operator, "or&amp;gt;")
            };

            SelectionFilter sf = new SelectionFilter(types);
            PromptSelectionResult psr = ed.GetSelection(sf);

            if (psr.Status != PromptStatus.OK)
                return;

            ObjectId[] ids = psr.Value.GetObjectIds();

            ObjectContextManager ocm = db.ObjectContextManager;
            ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");

            if (ocm == null)
                return;          

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;

                    if (ent == null)
                        continue;

                    if (ent.Annotative == AnnotativeStates.True)
                    {
                        if (!ent.HasContext(db.Cannoscale))                        
                            ent.AddContext(db.Cannoscale);

                        foreach (ObjectContext oc in occ)
                           if (ent.HasContext(oc) &amp;amp;&amp;amp; oc.Name != db.Cannoscale.Name)
                                ent.RemoveContext(oc);                                       
                    }
                    else
                    {
                        ent.Annotative = AnnotativeStates.True;
                        ent.AddContext(db.Cannoscale);                       
                    }
                }
                trans.Commit();
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Apr 2024 18:24:07 GMT</pubDate>
    <dc:creator>Gepaha</dc:creator>
    <dc:date>2024-04-19T18:24:07Z</dc:date>
    <item>
      <title>Moving Annotative Object to Current Anno Scale</title>
      <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12713783#M4418</link>
      <description>&lt;P&gt;I am trying to make a command that the user selects items in the drawing and the goal is to remove the current annotative scales for that item and&amp;nbsp; move it to the current set annotative scale. i dont just want to add the current it needs to remove the old ones first.&lt;BR /&gt;&lt;BR /&gt;the reason why i split the different objects is because i assume that they all have different ways to set the annotative scales. the alert dialog box was to check if i selects a correct object. This Is what i have so far but i am stuck&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;  public void AttachToCurrentAnnoScale()
  {
      Document doc = Application.DocumentManager.MdiActiveDocument;
      Database db = doc.Database;
      Editor edt = doc.Editor;

      ObjectContextManager ocm = db.ObjectContextManager;
      ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");
      AnnotationScale currentAnnoScale = db.Cannoscale;

      Application.MainWindow.Focus();

      using (DocumentLock docLock = doc.LockDocument())
      {
          using (Transaction trans = db.TransactionManager.StartTransaction())
          {
              //Create TypedValue
              TypedValue[] types = new TypedValue[]
                  {
          new TypedValue((int)DxfCode.Operator, "&amp;lt;or"),
          new TypedValue((int)DxfCode.Start, "INSERT"),
          new TypedValue((int)DxfCode.Start, "MTEXT"),
          new TypedValue((int)DxfCode.Start, "MULTILEADER"),
          new TypedValue((int)DxfCode.Start, "DIMENSION"),
          new TypedValue((int)DxfCode.Operator, "or&amp;gt;")
                  };

              //Create SelectionFilter
              SelectionFilter filter = new SelectionFilter(types);

              //Create PromptStringResult

              PromptSelectionResult selResult = edt.GetSelection(filter);

              //Selection Verification
              if (selResult.Status == PromptStatus.OK)
              {
                  //Create Selection Set
                  SelectionSet ss = selResult.Value;
                  //Loop Thru Selection Set
                  foreach (SelectedObject selObj in ss)
                  {
                      DBObject dbobj = trans.GetObject(selObj.ObjectId, OpenMode.ForWrite);
                      if (dbobj != null)
                      {
                          //Check For Block
                          if (dbobj is BlockReference blockref)
                          {
                              Application.ShowAlertDialog("You Selected a Block");

                          }

                          //Check For Mtext
                          if (dbobj is MText mtext)
                          {
                              mtext.Annotative = AnnotativeStates.True;
                              Application.ShowAlertDialog("You Selected a MTEXT");
                              
                          }

                          //Check for MLeader
                          if (dbobj is MLeader mleader)
                          {
                              mleader.Annotative = AnnotativeStates.True;
                              Application.ShowAlertDialog("You Selected a MLeader");
                          }

                          //Check for Dimension
                          if (dbobj is Dimension dim)
                          {
                              dim.Annotative = AnnotativeStates.True;
                              Application.ShowAlertDialog("You Selected a Dimension");
                          }


                      }
                  }
                  trans.Commit();
                  edt.WriteMessage("\nObject Moved to Current Annotation Scale.");
              }
              else
              {
                  edt.WriteMessage("\nNo valid entities selected. Ensure the correct types are being selected.");
              }
          }
      }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;THis&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 06:39:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12713783#M4418</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-04-17T06:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Annotative Object to Current Anno Scale</title>
      <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12713883#M4419</link>
      <description>&lt;P&gt;You can use dbobj.RemoveContext() in a loop for all Annotation Scales, then dbobj.AddContext() to add the current one. Here you find some examples btw:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.keanw.com/2011/10/delete-all-but-current-annotation-scales-on-autocad-objects-using-net.html" target="_blank"&gt;https://www.keanw.com/2011/10/delete-all-but-current-annotation-scales-on-autocad-objects-using-net.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a side note: you don't move objects to a scale, you apply a scale to an object &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 07:45:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12713883#M4419</guid>
      <dc:creator>Anton_Huizinga</dc:creator>
      <dc:date>2024-04-17T07:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Annotative Object to Current Anno Scale</title>
      <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12719126#M4420</link>
      <description>&lt;P&gt;this works but there is an issue when it comes to mleaders. it applies the scales but it doesnt change. i have a lisp file i have used for a long time and when using the lisp it works fine but this doesnt seem to work correctly with mleaders even though they are set annotative and changes when changing manually&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 05:10:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12719126#M4420</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-04-19T05:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Annotative Object to Current Anno Scale</title>
      <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12720924#M4421</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        public void AddCurrentAnnoScaleAndRemoveOthers()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            TypedValue[] types = new TypedValue[]
            {
                new TypedValue((int)DxfCode.Operator, "&amp;lt;or"),
                new TypedValue((int)DxfCode.Start, "INSERT"),
                new TypedValue((int)DxfCode.Start, "MTEXT"),
                new TypedValue((int)DxfCode.Start, "MULTILEADER"),
                new TypedValue((int)DxfCode.Start, "DIMENSION"),
                new TypedValue((int)DxfCode.Operator, "or&amp;gt;")
            };

            SelectionFilter sf = new SelectionFilter(types);
            PromptSelectionResult psr = ed.GetSelection(sf);

            if (psr.Status != PromptStatus.OK)
                return;

            ObjectId[] ids = psr.Value.GetObjectIds();

            ObjectContextManager ocm = db.ObjectContextManager;
            ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES");

            if (ocm == null)
                return;          

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    Entity ent = trans.GetObject(id, OpenMode.ForWrite) as Entity;

                    if (ent == null)
                        continue;

                    if (ent.Annotative == AnnotativeStates.True)
                    {
                        if (!ent.HasContext(db.Cannoscale))                        
                            ent.AddContext(db.Cannoscale);

                        foreach (ObjectContext oc in occ)
                           if (ent.HasContext(oc) &amp;amp;&amp;amp; oc.Name != db.Cannoscale.Name)
                                ent.RemoveContext(oc);                                       
                    }
                    else
                    {
                        ent.Annotative = AnnotativeStates.True;
                        ent.AddContext(db.Cannoscale);                       
                    }
                }
                trans.Commit();
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 18:24:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12720924#M4421</guid>
      <dc:creator>Gepaha</dc:creator>
      <dc:date>2024-04-19T18:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Moving Annotative Object to Current Anno Scale</title>
      <link>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12721671#M4422</link>
      <description>&lt;P&gt;Very interesting. Thank you i am trying to learn as much as possible as i go along i have done some online course but it seems the mountain&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2024 05:18:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/moving-annotative-object-to-current-anno-scale/m-p/12721671#M4422</guid>
      <dc:creator>My_Civil_3D</dc:creator>
      <dc:date>2024-04-20T05:18:47Z</dc:date>
    </item>
  </channel>
</rss>

