I'm looking at creatre a block reference to insert different block symbols based on civil 3d surface query. I'm able to create the block name which shows in the block
collection after I run this test. The issue I'm having seems simple but I have not been able to find a sample that shows how to define the block reference for that block name. I found plenty of samples on how to insert a block from outside the editor. Basically I need to convert my vba sample that checks for a block and if that block is not found in the block collection it creates the block reference.
Thanks for any links or data you can provide.
John
''''' my old vba sample
If BlockExists("BlockName") Then
Call insertblocks ' blocks exist. go to insert routine
End If
If BlockExists("BlockName") = False Then
Call makeblocks
End If
End Sub
Sub makeblocks()
Dim BlockName1 As String
BlockName1 = "SURFACECUT"
Dim LayerName As String
' Make point array for block's insertion point
Dim ptOrigin(2) As Double
ptOrigin(0) = 0#: ptOrigin(1) = 0#: ptOrigin(2) = 0#
' Create the block object
Dim Block As AcadBlock
Set Block = ThisDrawing.Blocks.Add(ptOrigin, BlockName1)
' Make points for lines
Dim pt1(2) As Double
pt1(0) = 0#: pt1(1) = -0.04: pt1(2) = 0#
Dim pt2(2) As Double
pt2(0) = -0.06: pt2(1) = -0.04: pt2(2) = 0#
Dim pt3(2) As Double
pt3(0) = 0.06: pt3(1) = -0.04: pt3(2) = 0#
Dim pt4(2) As Double
pt4(0) = -0#: pt4(1) = 0.08: pt4(2) = 0#
' Add the lines to the block's definition
Block.AddLine pt2, pt3
Block.AddLine pt3, pt4
Block.AddLine pt4, pt2
Call insertblocks
End Sub
'vb sample
<CommandMethod("addblock1")> _
Public Sub addblock1()
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument
Dim acaddoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim BlockTable As BlockTable
Dim BlockTableRecord As BlockTableRecord
Dim tr As Transaction = db.TransactionManager.StartTransaction
Try
BlockTable = acaddoc.Database.BlockTableId.GetObject(OpenMode.ForWrite)
BlockTableRecord = New BlockTableRecord
BlockTableRecord.Name = "CUT"
' Make point lines to create block
Dim pt5(2) As Double
pt5(0) = 0.0# : pt5(1) = -0.072 : pt5(2) = 0.0#
Dim pt6(2) As Double
pt6(0) = -0.083 : pt6(1) = -0.072 : pt6(2) = 0.0#
Dim pt7(2) As Double
pt7(0) = -0.083 : pt7(1) = 0.072 : pt7(2) = 0.0#
Dim pt8(2) As Double
pt8(0) = 0.083 : pt8(1) = 0.072 : pt8(2) = 0.0#
Dim pt9(2) As Double
pt9(0) = 0.083 : pt9(1) = -0.072 : pt9(2) = 0.0#
Dim acLine As Line
acLine = New Line(New Point3d(pt6), New Point3d(pt7))
acLine = New Line(New Point3d(pt7), New Point3d(pt8))
acLine = New Line(New Point3d(pt8), New Point3d(pt9))
acLine = New Line(New Point3d(pt9), New Point3d(pt6))
BlockTable.Add(BlockTableRecord)
tr.AddNewlyCreatedDBObject(BlockTableRecord, True)
tr.Commit()
Catch ex As System.Exception
ed.WriteMessage(ex.ToString)
End Try
End Sub