- 积分
- 132
- 明经币
- 个
- 注册时间
- 2016-4-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 马佳弘 于 2016-5-27 16:53 编辑
本人机械设计人员,想自己做点二次开发自己用,用的vs2012中的vb.net。
请问如何用过代码在工具栏中选择标注样式呢?
目前已用代码生成了1:1,和1:2两个标注样式,用类似选择图层和文字样式的语句会报错。eInvalidinput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Colors
Imports Autodesk.AutoCAD.EditorInput
Public Class Class1
<CommandMethod("mb")>
Public Sub SCMB()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acDimStyleTbl As DimStyleTable
acDimStyleTbl = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)
Dim acDimStyleTblRec As DimStyleTableRecord = Nothing
If acDimStyleTbl.Has("1:1") = False Then
acDimStyleTblRec = New DimStyleTableRecord()
acDimStyleTblRec.Name = "1:1"
acDimStyleTbl.UpgradeOpen()
acDimStyleTbl.Add(acDimStyleTblRec)
acTrans.AddNewlyCreatedDBObject(acDimStyleTblRec, True)
End If
acTrans.Commit()
End Using
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acDimStyleTbl As DimStyleTable
acDimStyleTbl = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)
Dim acDimStyleTblRec As DimStyleTableRecord = Nothing
If acDimStyleTbl.Has("1:2") = False Then
acDimStyleTblRec = New DimStyleTableRecord()
acDimStyleTblRec.Name = "1:2"
acDimStyleTbl.UpgradeOpen()
acDimStyleTbl.Add(acDimStyleTblRec)
acTrans.AddNewlyCreatedDBObject(acDimStyleTblRec, True)
End If
acTrans.Commit()
End Using
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acDimStyleTbl As DimStyleTable
acDimStyleTbl = acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForRead)
acCurDb.Clayer = acDimStyleTbl("1:1")
acTrans.Commit()
End Using
End Sub
End Class
|
|