[討論]叫 AUTOCAD 自動產生圖形的兩個方法
3 posters
AutoCAD顧問 :: 技術(發言等級:一般會員) :: :: 進階討論
第1頁(共1頁)
[討論]叫 AUTOCAD 自動產生圖形的兩個方法
應該是還有更多的方法,我稍微知道的是兩種:
一 在 AUTOCAD 裡面寫 AUTOLISP 程式,
利用 (COMMAND ) 叫 AUTOCAD 自動畫圖
二 在 AUTOCAD 外面,使用任何你所熟系的電腦語言,
產生 AUTOCAD SCRIPT FILE: XXX.SCR
檔案內容,類似如下:
-COLOR
2
POINT
0,0
LINE
0,1
2,3
0,5
CLOSE
CIRCLE
3,4
5
ARC
0,1
2,3
0,5
ZOOM
E
ZOOM
0.8X
如果大家有興趣的話,我再撥空寫作幾個實際的例子與大家分享。
一 在 AUTOCAD 裡面寫 AUTOLISP 程式,
利用 (COMMAND ) 叫 AUTOCAD 自動畫圖
二 在 AUTOCAD 外面,使用任何你所熟系的電腦語言,
產生 AUTOCAD SCRIPT FILE: XXX.SCR
檔案內容,類似如下:
-COLOR
2
POINT
0,0
LINE
0,1
2,3
0,5
CLOSE
CIRCLE
3,4
5
ARC
0,1
2,3
0,5
ZOOM
E
ZOOM
0.8X
如果大家有興趣的話,我再撥空寫作幾個實際的例子與大家分享。
Tiger&蘋果爸 在 周一 31 五月 2010 - 14:37 作了第 1 次修改 (原因 : 此主題為[討論]類型)
andychen- 該用戶停權中
- 文章總數 : 186
年齡 : 40
經驗值 : 6032
威望值 : 71
注冊日期 : 2010-04-09
回復: [討論]叫 AUTOCAD 自動產生圖形的兩個方法
C#.NET也不錯
[CommandMethod("netLine")]
public void testLine()
{
Line ent = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0));
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction ta = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)ta.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)ta.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(ent);
ta.AddNewlyCreatedDBObject(ent, true);
ta.Commit();
}
}
[CommandMethod("netLine")]
public void testLine()
{
Line ent = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0));
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction ta = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)ta.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)ta.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(ent);
ta.AddNewlyCreatedDBObject(ent, true);
ta.Commit();
}
}
回復: [討論]叫 AUTOCAD 自動產生圖形的兩個方法
樓上所說的c#完整程式碼如下:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace AcadNetSamples
{
public class Commands
{
[CommandMethod("DrawLine")]
public static void DrawLine()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions prPO = new PromptPointOptions("\nPick start point of line: ");
prPO.AllowNone = false;
prPO.UseBasePoint = false;
PromptPointResult ppr1 = ed.GetPoint(prPO);
if (ppr1.Status == PromptStatus.OK)
{
prPO.UseBasePoint = true;
prPO.BasePoint = ppr1.Value;
prPO.Message = "\nPick end point: ";
PromptPointResult ppr2 = ed.GetPoint(prPO);
if (ppr2.Status == PromptStatus.OK)
{
Point3d SPoint = ppr1.Value;
Point3d EPoint = ppr2.Value;
Line oLine = new Line(SPoint, EPoint);
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction();
using
(tr)
{
BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
using
(oLine)
{
btr.AppendEntity(oLine);
tm.AddNewlyCreatedDBObject(oLine, true);
}
tr.Commit();
}
}
}
}
}
}
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace AcadNetSamples
{
public class Commands
{
[CommandMethod("DrawLine")]
public static void DrawLine()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointOptions prPO = new PromptPointOptions("\nPick start point of line: ");
prPO.AllowNone = false;
prPO.UseBasePoint = false;
PromptPointResult ppr1 = ed.GetPoint(prPO);
if (ppr1.Status == PromptStatus.OK)
{
prPO.UseBasePoint = true;
prPO.BasePoint = ppr1.Value;
prPO.Message = "\nPick end point: ";
PromptPointResult ppr2 = ed.GetPoint(prPO);
if (ppr2.Status == PromptStatus.OK)
{
Point3d SPoint = ppr1.Value;
Point3d EPoint = ppr2.Value;
Line oLine = new Line(SPoint, EPoint);
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.DatabaseServices.Transaction tr = tm.StartTransaction();
using
(tr)
{
BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
using
(oLine)
{
btr.AppendEntity(oLine);
tm.AddNewlyCreatedDBObject(oLine, true);
}
tr.Commit();
}
}
}
}
}
}
AutoCAD顧問 :: 技術(發言等級:一般會員) :: :: 進階討論
第1頁(共1頁)
這個論壇的權限:
您 無法 在這個版面回復文章