<?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: Refresh drawing after block modivication in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653961#M46754</link>
    <description>Hallo and thank you for your fast and competent reply!&lt;BR /&gt;&lt;BR /&gt;Thank's, once more!</description>
    <pubDate>Tue, 26 Nov 2013 17:56:10 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-11-26T17:56:10Z</dc:date>
    <item>
      <title>Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653443#M46752</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dear all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code mirrors a selection by either the x-axis or the y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exept, the drawing shows the result, when I move my cursor to the active dwg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I refresh my drawing, direct after modification of a block?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any sugestions to a clean solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I use the code below to mirror a selected block by a button on a docking pallette:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;private void btn_Vertical_Mirror_Click(object sender, EventArgs e)
{
	(new Modifikation()).Mirror("v");
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the code, which is called is:&lt;/P&gt;&lt;PRE&gt;public void Mirror(String axis = "")
{
	//---------------------------------------------------------------------------------------------------------------------------------------
	Document dwg = Application.DocumentManager.MdiActiveDocument;
	Database db = dwg.Database;
	Editor edt = dwg.Editor;
	//---------------------------------------------------------------------------------------------------------------------------------------
	try
	{
		Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
		PromptSelectionResult sel = edt.SelectImplied();
		//-----------------------------------------------------------------------------------------------------------------------------------
		if (sel.Status == PromptStatus.Error)
		{
			//Selection filter
			TypedValue[] tv = new TypedValue[] { new TypedValue( (int)DxfCode.Start, "INSERT") };
			SelectionFilter sf = new SelectionFilter(tv);
			PromptSelectionOptions pso = new PromptSelectionOptions();

			pso.MessageForAdding = "\nSelect block";
			sel = edt.GetSelection(pso, sf);

			if (sel.Status != PromptStatus.OK)//
			{
				edt.WriteMessage("\n#ERROR! Selection failed\n");
				return;
			}//if
		}
		//-----------------------------------------------------------------------------------------------------------------------------------
		while (axis == "")
		{
			axis = edt.GetString("Axis ('H'orizontaly oder 'V'erticaly)").StringResult.ToUpper();
			if (axis.StartsWith("H")) { axis = "h"; }
			else if (axis.StartsWith("V")) { axis = "v"; }
			else { axis = ""; }
		}
		//-----------------------------------------------------------------------------------------------------------------------------------
		using (Transaction tr = db.TransactionManager.StartTransaction())
		{
			using (DocumentLock lk = dwg.LockDocument())
			{
				for (int i = 0; i &amp;lt; sel.Value.Count; i++)
				{
					if (sel.Value[i].ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(BlockReference))))// Blöcke werden der Auswahl entnommen
					{
						BlockReference blk_ref = (BlockReference)tr.GetObject(sel.Value[i].ObjectId, OpenMode.ForWrite);

						//-------------------------------------------------------------------------------------------------------------------
						if (axis == "h")
						{
							Matrix3d spgl = Matrix3d.Mirroring(
								new Line3d(
									blk_ref.Position,
									new Point3d(
										blk_ref.Position.X + 1,
										blk_ref.Position.Y, 0)));
							blk_ref.TransformBy(spgl);
						}
						//-------------------------------------------------------------------------------------------------------------------
						else if (axis == "v")
						{
							Matrix3d spgl = Matrix3d.Mirroring(
								new Line3d(
									blk_ref.Position,
									new Point3d(
										blk_ref.Position.X,
										blk_ref.Position.Y + 1, 0)));
							blk_ref.TransformBy(spgl);
						}
						//-------------------------------------------------------------------------------------------------------------------
					}//if
				}// for
			}// using DocumentLock
			tr.Commit();
		}// using Transaction
		edt.WriteMessage("\nOkay\n");
	}// try
	//---------------------------------------------------------------------------------------------------------------------------------------
	catch { edt.WriteMessage("\n#Error!\n"); }
	//---------------------------------------------------------------------------------------------------------------------------------------
	finally { edt.WriteMessage("\nDone\n"); }
}// public void&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2013 16:41:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653443#M46752</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-26T16:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653705#M46753</link>
      <description>&lt;P&gt;try by adding this line at the end of your code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'' Regenerate the drawing
edt.Regen()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;A target="_blank" href="http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/files/WS1a9193826455f5ff2566ffd511ff6f8c7ca-42db.htm"&gt;http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/files/WS1a9193826455f5ff2566ffd511ff6f8c7ca-42db.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2013 17:36:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653705#M46753</guid>
      <dc:creator>Ajilal.Vijayan</dc:creator>
      <dc:date>2013-11-26T17:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653961#M46754</link>
      <description>Hallo and thank you for your fast and competent reply!&lt;BR /&gt;&lt;BR /&gt;Thank's, once more!</description>
      <pubDate>Tue, 26 Nov 2013 17:56:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4653961#M46754</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-26T17:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4654421#M46755</link>
      <description>&lt;P&gt;Calling Regen can be a tad slow for a large drawing. When I've modified a BlockTableRecord, I prefer to iterate through all the BlockReferences for that BlockTableRecord and call RecordGraphicsModified(0 on each one. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;A href="http://adndevblog.typepad.com/autocad/2012/05/redefining-a-block.html" target="_blank"&gt;http://adndevblog.typepad.com/autocad/2012/05/redefining-a-block.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its personal choice really - just mentioning this for others who may find this post in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2013 22:02:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4654421#M46755</guid>
      <dc:creator>StephenPreston</dc:creator>
      <dc:date>2013-11-26T22:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4656711#M46756</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Stephen!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some kind of loop was also my first idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tryed to refresh my drawing by using the code below.&lt;/P&gt;&lt;P&gt;It's a function, which is called after closing the transaction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private void RefreshBlocks()
{
  //-------------------------
  Document dwg = Application.DocumentManager.MdiActiveDocument;
  Database db = dwg.Database;
  Editor edt = dwg.Editor;
  //-------------------------
  Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
  PromptSelectionResult sel = edt.SelectImplied();
  if (sel.Status == PromptStatus.Error) { sel = edt.SelectAll(); }
  //-------------------------
  try
  {
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
      using (DocumentLock lk = dwg.LockDocument())
      {
        for (int i = 0; i &amp;lt; sel.Value.Count; i++)// Loop objects
        {
          if (sel.Value[i].ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(BlockReference))))// proceed only blocks
          {
            BlockReference blk_ref = (BlockReference)tr.GetObject(sel.Value[i].ObjectId, OpenMode.ForWrite);
            blk_ref.RecordGraphicsModified(true);
          }// if
        }// for
      }// using DocumentLock 
      tr.Commit();
    }// using Transaction 
  }// try
  //-------------------------
  catch { }
  //-------------------------
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But something is wrong. The changes on the block are not shown, until i set the focus to the drawing.&lt;/P&gt;&lt;P&gt;By calling &amp;lt; regen &amp;gt; everything goes well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you point your finger to the mistake or error of the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2013 18:49:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4656711#M46756</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-27T18:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4656915#M46757</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try adding:&lt;/P&gt;
&lt;PRE&gt;db.TransactionManager.QueueForGraphicsFlush();&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;after each:&lt;/P&gt;
&lt;PRE&gt;blk_ref.TransformBy(spgl);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2013 20:26:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4656915#M46757</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-11-27T20:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Refresh drawing after block modivication</title>
      <link>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4658239#M46758</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After playing around I finaly have a (partial) solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I insered the following rows to my code:&lt;/P&gt;&lt;PRE&gt;using (Transaction tr = db.TransactionManager.StartTransaction())
{
  using (DocumentLock lk = dwg.LockDocument())
  {
    dwg.TransactionManager.EnableGraphicsFlush(true);// new
	
	// Code for modification of the block(s)
	
    db.TransactionManager.QueueForGraphicsFlush();// new&lt;BR /&gt;&lt;SPAN style="line-height: 15px;"&gt;    dwg.TransactionManager.FlushGraphics();// new&lt;BR /&gt;  }// using DocumentLock&lt;BR /&gt;  tr.Commit();&lt;BR /&gt;}// using Transaction&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT!! It showes some strainge behaviour:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Rotating of blocks is working fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 15px;"&gt;Mirroring of blocks is only working, by selecting the blocks by a&amp;nbsp;&lt;/SPAN&gt;&amp;lt;&amp;nbsp;edt.GetSelection(pso, sf)&amp;nbsp;&amp;gt; command.&lt;/P&gt;&lt;P&gt;Using &amp;nbsp;&amp;lt;&amp;nbsp;edt.SelectImplied(); &amp;gt;, the updating of the drawing fails (must be triggered by activating by the operator)&lt;/P&gt;&lt;P&gt;I can overcome this, by using the code below.&lt;/P&gt;&lt;P&gt;But it looks not nice to me.&lt;/P&gt;&lt;PRE&gt;PromptSelectionResult sel = edt.SelectImplied();
if (sel.Status == PromptStatus.OK)
{
  ObjectId[] sel_tmp = new ObjectId[sel.Value.Count];
  for (int i = 0; i &amp;lt; sel.Value.Count; i++) temp_sel[i] = sel.Value[i].ObjectId;
  edt.SetImpliedSelection(new ObjectId[0]);
  edt.SetImpliedSelection(sel_tmp);
}// if &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2013 09:11:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/refresh-drawing-after-block-modivication/m-p/4658239#M46758</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-28T09:11:08Z</dc:date>
    </item>
  </channel>
</rss>

