Professional Documents
Culture Documents
AutoCAD
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Public Class Class1
<Autodesk.AutoCAD.Runtime.CommandMethod("RunMe")>
Public Sub RunMe()
MsgBox("I'm glad this works.")
End Sub
<Autodesk.AutoCAD.Runtime.CommandMethod("DrawLine")>
Public Sub DrawLine()
Dim myDoc As Document = DocumentManager.MdiActiveDocument
Dim myDB As Database = myDoc.Database
Dim myEditor As Editor = myDoc.Editor
Using myTrans As Transaction = myDoc.TransactionManager.StartTransaction
Dim myBTR As BlockTableRecord =
myDB.CurrentSpaceId.GetObject(OpenMode.ForWrite)
Dim startPoint As Point3d = myEditor.GetPoint("Select Start
Point:").Value
Dim myPPO As New PromptPointOptions("Select End Point:")
myPPO.BasePoint = startPoint
myPPO.UseBasePoint = True
Dim endPoint As Point3d = myEditor.GetPoint(myPPO).Value
Dim myLine As New Line(startPoint, endPoint)
myBTR.AppendEntity(myLine)
myTrans.AddNewlyCreatedDBObject(myLine, True)
myTrans.Commit()
End Using
End Sub
<Autodesk.AutoCAD.Runtime.CommandMethod("DrawGrid")>
Public Sub DrawGrid()
Dim myDoc As Document = DocumentManager.MdiActiveDocument
Dim myDB As Database = myDoc.Database
Dim myEditor As Editor = myDoc.Editor
Using myTrans As Transaction = myDoc.TransactionManager.StartTransaction
Dim myBTR As BlockTableRecord =
myDB.CurrentSpaceId.GetObject(OpenMode.ForWrite)
For X As Double = 0 To 10 Step 0.5
For Y As Double = 0 To 10 Step 0.5
Dim startPoint As New Point3d(X, 0, 0)
Dim endPoint As New Point3d(X, 10, 0)
Dim myLine As New Line(startPoint, endPoint)
myBTR.AppendEntity(myLine)
myTrans.AddNewlyCreatedDBObject(myLine, True)
startPoint = New Point3d(0, Y, 0)
endPoint = New Point3d(10, Y, 0)
myLine = New Line(startPoint, endPoint)
myBTR.AppendEntity(myLine)
myTrans.AddNewlyCreatedDBObject(myLine, True)
Next
Next
myTrans.Commit()
End Using
End Sub
<Autodesk.AutoCAD.Runtime.CommandMethod("DrawLineTest")>
Public Sub DrawLineTest()
'draw square first
DrawLineFunction(0, 0, 0, 4, 0, 0)
DrawLineFunction(4, 0, 0, 4, 4, 0)
DrawLineFunction(4, 4, 0, 0, 4, 0)
DrawLineFunction(0, 4, 0, 0, 0, 0)
'now draw corner to corner
DrawLineFunction(0, 0, 0, 4, 4, 0)
DrawLineFunction(0, 4, 0, 4, 0, 0)
End Sub
<Autodesk.AutoCAD.Runtime.CommandMethod("GetBTRNames")>
Public Sub GetBTRNames()
For Each myBName As String In GetAllBlockTableRecords()
MsgBox(myBName)
Next
End Sub
myBRef.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)
If retVal.ContainsKey(parentBTR.Name) = False Then
retVal.Add(parentBTR.Name, New List(Of ObjectId))
End If
retVal(parentBTR.Name).Add(myEntID)
Else
If retVal.ContainsKey(myBRef.Name) = False Then
retVal.Add(myBRef.Name, New List(Of ObjectId))
End If
retVal(myBRef.Name).Add(myEntID)
End If
End If
Next
myTrans.Commit()
End Using
Return retVal
End Function
<Autodesk.AutoCAD.Runtime.CommandMethod("WriteBlocksOut")>
Public Sub WriteBlocksOut()
Dim myDB As Database = HostApplicationServices.WorkingDatabase
Dim myBlocks As Dictionary(Of String, List(Of ObjectId)) =
GetBlockReferencesInModelSpace(myDB)
<Autodesk.AutoCAD.Runtime.CommandMethod("WriteBlocksAndAttributesOutToExcel")>
Public Sub WriteBlocksAndAttributesOutToExcel()
Dim myDB As Database = HostApplicationServices.WorkingDatabase
Dim myBlocks As Dictionary(Of String, List(Of ObjectId)) =
GetBlockReferencesInModelSpace(myDB)
End Class