- 积分
- 3099
- 明经币
- 个
- 注册时间
- 2005-8-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2012-9-9 11:46:58
|
显示全部楼层
本帖最后由 single-yu 于 2012-9-9 11:47 编辑
我用的就是CAD2006+VS2005,一直都用的很正常,你试试我的这个代码:
我的程序是这样的,在外部建个DWG文件作为模板,每次调用它插入到图形中,并作修改!
- '开始当前文档的事务处理
- Using trans As Transaction = curDb.TransactionManager.StartTransaction
- '新建临时数据库来读取点之记模板
- Dim tempDb As New Database(False, True)
- '新建数据库来生成点之记
- Dim db As New Database(False, True)
- '使用多边形框来选择范围内的实体
- Dim resSel As PromptSelectionResult = ed.SelectCrossingPolygon(ptColl)
- Dim sSet As SelectionSet = resSel.Value
- Dim Ids As ObjectIdCollection = New ObjectIdCollection(sSet.GetObjectIds)
- Ids.Add(pLine.ObjectId)
- db = curDb.Wblock(Ids, curDb.Ucsorg)
- '读取点之记模板
- Dim fileName As String = "C:\Program Files\AcadTool\测量工具箱\TP.dwg" '模板文件的位置
- If System.IO.File.Exists(fileName) Then
- tempDb.ReadDwgFile(fileName, System.IO.FileShare.Read, True, Nothing)
- tempDb.CloseInput(True)
- '插入点之记模板文件到数据库
- db.Insert(System.IO.Path.GetFileNameWithoutExtension(fileName), tempDb, True)
- '开始点之记数据库的事务处理
- Using atrans As Transaction = db.TransactionManager.StartTransaction
- Dim bt As BlockTable = atrans.GetObject(db.BlockTableId, OpenMode.ForWrite)
- If bt.Has("TP") = False Then
- Return
- End If
- Dim block As BlockTableRecord = atrans.GetObject(bt.Item("TP"), OpenMode.ForWrite)
- '字体样式
- Dim tst As TextStyleTable = TryCast(atrans.GetObject(db.TextStyleTableId, OpenMode.ForWrite), TextStyleTable)
- '添加TP点点名
- Dim tpName As New DBText
- '在点之记中加入作业员
- Dim workmanText As New DBText
- '在点之记中加入检查员
- Dim checkmanText As New DBText
- '在点之记中加入说明
- Dim typeText As New MText
- tpName.TextString = "TP" & num.ToString
- tpName.Position = New Point3d(-30, -69, 0)
- tpName.Height = 4
- tpName.TextStyle = atrans.GetObject(tst.Item("宋体"), OpenMode.ForWrite).ObjectId
- workmanText.TextString = pointMarkPalette.textboxWorkMan.Text
- workmanText.Position = New Point3d(-55.65, -100.32, 0)
- workmanText.Height = 4
- workmanText.TextStyle = atrans.GetObject(tst.Item("宋体"), OpenMode.ForWrite).ObjectId
- checkmanText.TextString = pointMarkPalette.textboxCheckMan.Text
- checkmanText.Position = New Point3d(-2.86, -100.32, 0)
- checkmanText.Height = 4
- checkmanText.TextStyle = atrans.GetObject(tst.Item("宋体"), OpenMode.ForWrite).ObjectId
- typeText.Contents = "1、实地砸有" & pointMarkPalette.typeCbo.Text & ",并涂有红油漆。"
- typeText.Location = New Point3d(-49.235, -137.553, 0)
- typeText.TextHeight = 4
- typeText.TextStyle = atrans.GetObject(tst.Item("宋体"), OpenMode.ForWrite).ObjectId
- block.AppendEntity(tpName)
- block.AppendEntity(workmanText)
- block.AppendEntity(checkmanText)
- block.AppendEntity(typeText)
- atrans.AddNewlyCreatedDBObject(tpName, True)
- atrans.AddNewlyCreatedDBObject(workmanText, True)
- atrans.AddNewlyCreatedDBObject(checkmanText, True)
- atrans.AddNewlyCreatedDBObject(typeText, True)
- Dim blockref As BlockReference = New BlockReference(pt, bt.Item("TP"))
- '点之记根据比例尺缩小或者放大
- blockref.ScaleFactors = New Scale3d(ScaleFlector)
- blockref.Rotation = 0
- Dim btr As BlockTableRecord = atrans.GetObject(bt.Item(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
- btr.AppendEntity(blockref)
- atrans.AddNewlyCreatedDBObject(blockref, True)
- atrans.Commit()
- End Using
- End If
- '把临时存取模板的数据库销毁
- tempDb.Dispose()
- '保存各个点之记
- db.SaveAs(pointMarkPalette.saveFileName & "TP" & num.ToString & ".dwg", DwgVersion.Current)
- '提交事务处理
- trans.Commit()
- End Using
虽然你用的是C#,主要体会里面的方法就行了,我一直都用这个方法!
|
评分
-
查看全部评分
|