- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
public static void TestGraph()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
PromptPointOptions ppo = new PromptPointOptions("\nJust a Lower Left corner: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK)
{
return;
}
PromptCornerOptions pco = new PromptCornerOptions("\nUpper Right corner: ", ppr.Value);
PromptPointResult pcr = ed.GetCorner(pco);
if (pcr.Status != PromptStatus.OK)
{
return;
}
Point3d p1 = ppr.Value;
Point3d p2 = pcr.Value;
if (((p1.X == p2.X || p1.Y == p2.Y) & (p2.X > p1.X || p2.Y > p1.Y)))
{
ed.WriteMessage("\nWrong coordinate specification");
return;
}
// Calculate the four corner points of the box
// and add them to a Point3dCollection:
Point3dCollection points = new Point3dCollection();
points.Add(p1);
points.Add(new Point3d(p2.X, p1.Y, 0.0));
points.Add(p2);
points.Add(new Point3d(p1.X, p2.Y, 0.0));
double leng = 0;
leng = p2.X - p1.X;
double wid = 0;
wid = p2.Y - p1.Y;
//'-------------------------------------------------------''
PromptIntegerOptions pio = new PromptIntegerOptions("");
pio.Message = "\nEnter the number of rows: ";
// Restrict input to positive and non-negative values
pio.AllowZero = false;
pio.AllowNegative = false;
// Add default value
pio.DefaultValue = 4;
pio.AllowNone = true;
// Get the value entered by the user
PromptIntegerResult ires = ed.GetInteger(pio);
if (ires.Status != PromptStatus.OK)
{
return;
}
int rownum = ires.Value;
pio.Message = "\nnEnter the number of columns: ";
// Restrict input to positive and non-negative values
pio.AllowZero = false;
pio.AllowNegative = false;
// Add default value
pio.DefaultValue = 8;
pio.AllowNone = true;
// Get the value entered by the user
PromptIntegerResult ires2 = ed.GetInteger(pio);
if (ires2.Status != PromptStatus.OK)
{
return;
}
int colnum = ires2.Value;
double rowstep = 0;
rowstep = wid / rownum;
double colstep = 0;
colstep = leng / colnum;
Database db = ed.Document.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Plane plan = new Plane(Point3d.Origin, Vector3d.ZAxis);
Polyline poly = new Polyline(4);
int i = 0;
foreach (Point3d pt in points)
{
poly.AddVertexAt(i, pt.Convert2d(plan), 0, 0, 0);
i += 1;
}
poly.Closed = true;
btr.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
Point3dCollection vps = new Point3dCollection();
Point3dCollection hps = new Point3dCollection();
for (i = 1; i <= rownum - 1; i++)
{
vps.Add(new Point3d(p1.X, p1.Y + (i * rowstep), p1.Z));
}
for (i = 1; i <= colnum - 1; i++)
{
hps.Add(new Point3d(p1.X + (i * colstep), p1.Y, p1.Z));
}
Line ln = new Line();
foreach (Point3d pt in vps)
{
ln = new Line(pt, new Point3d(pt.X + leng, pt.Y, 0));
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
}
foreach (Point3d pt in hps)
{
ln = new Line(pt, new Point3d(pt.X, pt.Y + wid, 0));
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
}
tr.Commit();
}
} |
|