通过鼠标在cad中框选范围,再框选范围矩形框中随机画颜色、半径不同的圆,效果如下:
代码如下:
cs
public static class Class1
{
// private static PaletteSet pset;
[CommandMethod("xx")]
public static async void XX()
{
List<Circle> circles = Z.Drawcira(6);
Z.Zooma();
PromptPointResult ppr = Z.ed.GetPoint("");
var pt = ppr.Value;
PromptPointResult ppr1 = Z.ed.GetPoint("");
var pt1 = ppr1.Value;
double minx = Math.Min(pt1.X, pt.X);
double miny = Math.Min(pt1.Y, pt.Y);
double maxx = Math.Max(pt1.X, pt.X);
double maxy = Math.Max(pt1.Y, pt.Y);
int.TryParse(Math.Round(minx,0).ToString(),out int a);
int.TryParse(Math.Round(maxx, 0).ToString(), out int b);
int.TryParse(Math.Round(miny, 0).ToString(), out int c);
int.TryParse(Math.Round(maxy, 0).ToString(), out int d);
;
Random random = new Random();
List<Circle> cs = new List<Circle>();
for (int i = 0; i < 5000; i++)
{
Circle circle = new Circle()
{ColorIndex = random.Next(0,15),Radius = random.Next(20,100),
Center = new Point3d(random.Next( a, b), random.Next(c, d),0) };
cs.Add(circle);
}
Z.db.AddEntityToModeSpace(cs.ToArray());
}
}