TheSwamp
Code Red => .NET => Topic started by: pedroantonio on June 19, 2011, 06:20:00 AM
-
I need help on drawing temporary red circle (like the one in hatch command when no valid boundary is found).
Is that even doable from .net?
I know about Editor.DrawVector but that is only to draw straight lines and another problem, it gets removed on zoom :(
Functionality description from hatch: Errors are marked with red circles that stays on screen even after zoom in/out, it automatically scales, but it gets removed on Regen/Redraw...
Thanks in advance for any pointers :angel:
-
Hi,
Maybe implementing a class which inherits the abstract Autodesk.AutoCAD.GraphicsInterface.Glyph class.
-
What I would like to know is can I gain access to the same .net command/wrapper that autocad does when he tries to mark errors (like after a hatching entity with not connected boudary)
-
Yes. Here's a quick example. More would need to be done to autoscale the circle based on the screen size but this should get you started.
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using aGi = Autodesk.AutoCAD.GraphicsInterface;
namespace MyTest
{
public class testing
{
private DBObjectCollection m_mrkers = new DBObjectCollection();
private IntegerCollection intColl = new IntegerCollection();
[CommandMethod("TempCirc")]
public void tempcirc()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
Point3d ctrPt = new Point3d(100,100,0);
Circle circ = new Circle(ctrPt, Vector3d.ZAxis, 5);
circ.ColorIndex = 1;
aGi.TransientManager.CurrentTransientManager.AddTransient(circ, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
m_mrkers.Add(circ);
}
void doc_CommandWillStart(object sender, CommandEventArgs e)
{
if (e.GlobalCommandName.Contains("REGEN"))
{
ClearMarkers();
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
}
}
private void ClearMarkers()
{
aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers[0], intColl);
m_mrkers[0].Dispose();
m_mrkers.Clear();
}
}
}
-
I'm trying to do something similar with lines instead of circles but I'm using VB.NET. I've converted Jeff_M's code using a C# to VB converter, but I'm having trouble with two lines of his code.
C# Code
doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
... converts to VB Code
doc.CommandWillStart += New CommandEventHandler(AddressOf doc_CommandWillStart)
doc.CommandWillStart -= New CommandEventHandler(AddressOf doc_CommandWillStart)
It doesn't understand doc.CommandWillStart and gives me a message, "Public Event CommandWillStart(...) is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event" when I hover over its blue squiggly underline. The closest option intellisense gives me is doc.CommandInProgress. I don't understand what it means by 'raising an event'.
I am new to VB.NET and the AutoCAD API so I'm apologizing in advance for being dense.
George
-
instead of this line (as converted)
doc.CommandWillStart += New CommandEventHandler(AddressOf doc_CommandWillStart)
use this one
AddHandler doc.CommandWillStart, New CommandEventHandler(AddressOf doc_CommandWillStart)
instead of this line
'doc.CommandWillStart -= New CommandEventHandler(AddressOf doc_CommandWillStart)
use next one:
RemoveHandler doc.CommandWillStart, AddressOf doc_CommandWillStart
and also if you will be draw circles multiple
try something like this:
Private Sub ClearMarkers()
If (m_mrkers.Count) > 0 Then
For i As Integer = 0 To m_mrkers.Count - 1
aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers(i), intColl)
m_mrkers(i).Dispose()
Next
End If
End Sub
Jeff beat me to it :)
-
Wow, thanks fixo, that was quick and it works like a charm. I don't think I could have stumbled upon figuring that out for a long time.
-
i'm having simular problems like above.
i'm drawing transient graphics to indicate problems in the design.
(https://dl.dropboxusercontent.com/u/51371340/HDD%20Good.PNG)
When I zoom the circles stay in place, but when i regen my circles moves.
(https://dl.dropboxusercontent.com/u/51371340/HDD%20Bad.PNG)
I can't find an event that triggers after regen to update the graphics. Is there such an event?
Or is there something to do with the Transientmanager?
Or what happens in the regen to the transient Graphics?
-
Yes. Here's a quick example. More would need to be done to autoscale the circle based on the screen size but this should get you started.
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using aGi = Autodesk.AutoCAD.GraphicsInterface;
namespace MyTest
{
public class testing
{
private DBObjectCollection m_mrkers = new DBObjectCollection();
private IntegerCollection intColl = new IntegerCollection();
[CommandMethod("TempCirc")]
public void tempcirc()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
Point3d ctrPt = new Point3d(100,100,0);
Circle circ = new Circle(ctrPt, Vector3d.ZAxis, 5);
circ.ColorIndex = 1;
aGi.TransientManager.CurrentTransientManager.AddTransient(circ, aGi.TransientDrawingMode.DirectTopmost, 128, intColl);
m_mrkers.Add(circ);
}
void doc_CommandWillStart(object sender, CommandEventArgs e)
{
if (e.GlobalCommandName.Contains("REGEN"))
{
ClearMarkers();
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.CommandWillStart -= new CommandEventHandler(doc_CommandWillStart);
}
}
private void ClearMarkers()
{
aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers[0], intColl);
m_mrkers[0].Dispose();
m_mrkers.Clear();
}
}
}
how to use aGi.TransientManager.CurrentTransientManager.AddTransient in autocad 2008?