如何插入一个形?
Public Function AddShape(ByVal ShapeName As String, ByVal Position As Point3d, ByVal Size As Double, ByVal Rotation As Double, ByVal WidthFactor As Double) As ObjectIdDim Sh As New Shape(Position, Size, Rotation, WidthFactor)
Sh.Name = ShapeName
Return AddEntity(Sh, "添加形")
End Function
Public Function AddEntity(ByVal Ent As Entity, ByVal WriteMis As String) As ObjectId
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim btr As BlockTableRecord
Dim bt As BlockTable
Dim ObjId As ObjectId
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Dim ED As Editor
ED = Application.DocumentManager.MdiActiveDocument.Editor
Try
Using trans
bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite, False)
btr = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False)
ObjId = btr.AppendEntity(Ent)
trans.AddNewlyCreatedDBObject(Ent, True)
trans.Commit()
Return ObjId
End Using
trans.Dispose()
Catch EX As Exception
trans.Dispose()
ED.WriteMessage(WriteMis + EX.Message)
End Try
End Function
我采用了以上方法,就是不行,提示出错,无法找到形文件 形文件在搜索目录中么 在的,我先用CAD中的命令LOAD加载了SHP文件,就可以了,但在软件中用什么方法加载SHP文件呢,请大师指点下,
public void LoadLineTypeFile(string lineTypeName, string filename)
Autodesk.AutoCAD.DatabaseServices.Database 的成员
好像不对吧,我要加载的是*.SHX形文件库,然
public void LoadLineTypeFile(string lineTypeName, string filename)
Autodesk.AutoCAD.DatabaseServices.Database 的成员是加载的字库
还请高手指点下
Using Trans As Transaction = Doc.TransactionManager.StartTransaction
Dim StyTab As TextStyleTable = Trans.GetObject(Doc.Database.TextStyleTableId, OpenMode.ForWrite)
Dim StyRec As New TextStyleTableRecord
StyRec.IsShapeFile = True
StyRec.FileName = "形文件的完整路径"
StyTab.Add(StyRec)
Trans.AddNewlyCreatedDBObject(StyRec, True)
Trans.Commit()
End Using 上面是加载形文件的方式,加载前需要判断一下是否已经加载,此处略 我试下,非常感谢 形文件加载好了,行运下面的代码
Public Function AddShape(ByVal ShapeName As String, ByVal Position As Point3d, ByVal Size As Double, ByVal Rotation As Double, ByVal WidthFactor As Double) As ObjectId
Dim Sh As New Shape(Position, Size, Rotation, WidthFactor)
Sh.Name = ShapeName
Return AddEntity(Sh, "添加形")
End Function
Sh.Name = ShapeName处出错Autodesk.AutoCAD.Runtime.Exception: eNotInDatabase 说是形不在数据库中,可有用SHAPE命令可以插入形的啊
有点晕
页:
[1]