Message 1 of 7
Not applicable
11-26-2013
08:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all!
My code mirrors a selection by either the x-axis or the y-axis.
It is working fine.
Exept, the drawing shows the result, when I move my cursor to the active dwg.
How can I refresh my drawing, direct after modification of a block?
Any sugestions to a clean solution?
Thank you!
I use the code below to mirror a selected block by a button on a docking pallette:
private void btn_Vertical_Mirror_Click(object sender, EventArgs e)
{
(new Modifikation()).Mirror("v");
}
the code, which is called is:
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 < 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
Solved! Go to Solution.
|