wz0406 发表于 2015-7-1 14:46:18

如何插入一个形?

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
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
我采用了以上方法,就是不行,提示出错,无法找到形文件

雪山飞狐_lzh 发表于 2015-7-2 19:42:49

形文件在搜索目录中么

wz0406 发表于 2017-8-12 08:57:50

在的,我先用CAD中的命令LOAD加载了SHP文件,就可以了,但在软件中用什么方法加载SHP文件呢,请大师指点下,

sxpd 发表于 2017-8-13 09:56:53

public void LoadLineTypeFile(string lineTypeName, string filename)
    Autodesk.AutoCAD.DatabaseServices.Database 的成员

wz0406 发表于 2017-8-13 13:28:38

好像不对吧,我要加载的是*.SHX形文件库,然
public void LoadLineTypeFile(string lineTypeName, string filename)
    Autodesk.AutoCAD.DatabaseServices.Database 的成员是加载的字库

还请高手指点下

guohq 发表于 2017-8-24 23:46:36

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

guohq 发表于 2017-8-24 23:47:42

上面是加载形文件的方式,加载前需要判断一下是否已经加载,此处略

wz0406 发表于 2017-9-3 17:32:32

我试下,非常感谢

wz0406 发表于 2018-6-10 15:51:04

形文件加载好了,行运下面的代码
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

wz0406 发表于 2018-6-10 15:52:21

说是形不在数据库中,可有用SHAPE命令可以插入形的啊
有点晕
页: [1]
查看完整版本: 如何插入一个形?