Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.EditorInput
'引用AutoCAD安装文件夹下的两个文件,“acdbmgd.dll”, 和 “acmgd.dll”。
'引用AutoCAD 2006 Type Library
'NetLoad 命令后自动执行的代码
Public Class Class0
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
CreateMenu()
'
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim WelcomeFrm As New Form1 '显示欢迎屏幕
WelcomeFrm.Show()
acDoc.Editor.WriteMessage("田草CAD工具箱.net版本加载成功。")
End Sub
Private Sub CreateMenu()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub
End Class
'统一文字样式
Public Class Class1
<CommandMethod("TongYiTxtStyle")> _
Public Sub TongYiTxtStyle()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim Path As String
Path = GetPath()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acTxtTbl As TextStyleTable
acTxtTbl = acTrans.GetObject(acCurDb.TextStyleTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acTxtTbl
Dim acTxtTblRec As TextStyleTableRecord
acTxtTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acTxtTblRec.FileName = Path & "font/txt.shx"
acTxtTblRec.BigFontFileName = Path & "font/hztxt.shx"
Next
'acDoc.Editor.ReGen()
acTrans.Commit()
End Using
acDoc.SendStringToExecute("._regen ", True, False, False) '命令后面有个空格
End Sub
Public Function GetPath() As String
Dim acadApp As AcadApplication = Application.AcadApplication
Dim I As Short
Dim Temp As String
Temp = acadApp.FullName
Temp = Replace(Temp, "\", "/")
I = InStrRev(Temp, "/")
GetPath = Left(Temp, I - 1)
End Function
End Class
'显示所选择的图层
Public Class Class2
<CommandMethod("ShowLayer")> _
Public Sub ShowLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
'显隐藏所有图层
Dim acLyrTbl As LayerTable
Dim acLyrTblRec As LayerTableRecord
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acLyrTbl
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acLyrTblRec.IsOff = True
Next
'将选择集中的对象所在图层打开
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _
OpenMode.ForRead)
'MsgBox(acEnt.Layer.ToString())'返回图层的名称
acLyrTblRec = acTrans.GetObject(acEnt.LayerId, OpenMode.ForWrite)
acLyrTblRec.IsOff = False
End If
Next
End If
acTrans.Commit()
End Using
End Sub
End Class
'显示所有图层
Public Class Class3
<CommandMethod("ShowAllLayer")> _
Public Sub ShowAllLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acLyrTbl As LayerTable
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acLyrTbl
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acLyrTblRec.IsOff = False
Next
acTrans.Commit()
End Using
End Sub
End Class
'隐藏所选择的图层
Public Class Class4
<CommandMethod("HideLayer")> _
Public Sub HideLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
'将选择集中的对象所在图层关闭
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _
OpenMode.ForRead)
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acEnt.LayerId, OpenMode.ForWrite)
acLyrTblRec.IsOff = True
End If
Next
End If
acTrans.Commit()
End Using
End Sub
End Class
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.EditorInput
'引用AutoCAD安装文件夹下的两个文件,“acdbmgd.dll”, 和 “acmgd.dll”。
'引用AutoCAD 2006 Type Library
'NetLoad 命令后自动执行的代码
Public Class Class0
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
CreateMenu()
'
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim WelcomeFrm As New Form1 '显示欢迎屏幕
WelcomeFrm.Show()
acDoc.Editor.WriteMessage("田草CAD工具箱.net版本加载成功。")
End Sub
Private Sub CreateMenu()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub
End Class
'统一文字样式
Public Class Class1
<CommandMethod("TongYiTxtStyle")> _
Public Sub TongYiTxtStyle()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Dim Path As String
Path = GetPath()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acTxtTbl As TextStyleTable
acTxtTbl = acTrans.GetObject(acCurDb.TextStyleTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acTxtTbl
Dim acTxtTblRec As TextStyleTableRecord
acTxtTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acTxtTblRec.FileName = Path & "font/txt.shx"
acTxtTblRec.BigFontFileName = Path & "font/hztxt.shx"
Next
'acDoc.Editor.ReGen()
acTrans.Commit()
End Using
acDoc.SendStringToExecute("._regen ", True, False, False) '命令后面有个空格
End Sub
Public Function GetPath() As String
Dim acadApp As AcadApplication = Application.AcadApplication
Dim I As Short
Dim Temp As String
Temp = acadApp.FullName
Temp = Replace(Temp, "\", "/")
I = InStrRev(Temp, "/")
GetPath = Left(Temp, I - 1)
End Function
End Class
'显示所选择的图层
Public Class Class2
<CommandMethod("ShowLayer")> _
Public Sub ShowLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
'显隐藏所有图层
Dim acLyrTbl As LayerTable
Dim acLyrTblRec As LayerTableRecord
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acLyrTbl
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acLyrTblRec.IsOff = True
Next
'将选择集中的对象所在图层打开
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _
OpenMode.ForRead)
'MsgBox(acEnt.Layer.ToString())'返回图层的名称
acLyrTblRec = acTrans.GetObject(acEnt.LayerId, OpenMode.ForWrite)
acLyrTblRec.IsOff = False
End If
Next
End If
acTrans.Commit()
End Using
End Sub
End Class
'显示所有图层
Public Class Class3
<CommandMethod("ShowAllLayer")> _
Public Sub ShowAllLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acLyrTbl As LayerTable
acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
OpenMode.ForRead)
For Each acObjId As ObjectId In acLyrTbl
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite)
acLyrTblRec.IsOff = False
Next
acTrans.Commit()
End Using
End Sub
End Class
'隐藏所选择的图层
Public Class Class4
<CommandMethod("HideLayer")> _
Public Sub HideLayer()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
If acSSPrompt.Status = PromptStatus.OK Then '选择成功
'将选择集中的对象所在图层关闭
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
If Not IsDBNull(acSSObj) Then
Dim acEnt As Entity = acTrans.GetObject(acSSObj.ObjectId, _
OpenMode.ForRead)
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acEnt.LayerId, OpenMode.ForWrite)
acLyrTblRec.IsOff = True
End If
Next
End If
acTrans.Commit()
End Using
End Sub
End Class
[本日志由 tiancao1001 于 2009-12-23 05:41 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |