Message 1 of 3
create block and insert it

Not applicable
11-30-2006
05:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to simplify my dvbs with functions and below I'm trying to create a block then insert the block. Below puts a block in the blocks collection but does not let me insert the block. I don't think that I am calling the block reference out correctly. Is my function set up correctly?
Sub BlockTEST()
Dim LayerName As String
Dim strRandomBlkName As String
LayerName = "Geometry"
' 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 blockObj As AcadBlock
strRandomBlkName = randomblkName
Set Block = ThisDrawing.Blocks.Add(ptOrigin, strRandomBlkName)
' Make point arrays for lines
Dim pt1(2) As Double
pt1(0) = -1#: pt1(1) = 6#: pt1(2) = 0#
Dim pt2(2) As Double
pt2(0) = 1#: pt2(1) = 0#: pt2(2) = 0#
Dim pt3(2) As Double
pt3(0) = 0#: pt3(1) = -1#: pt3(2) = 0#
Dim pt4(2) As Double
pt4(0) = 0#: pt4(1) = 6#: pt4(2) = 0#
Block.AddLine pt1, pt2
Block.AddLine pt3, pt4
' Make sure layer exists
'ThisDrawing.Layers.Add (LayerName)
End Sub
Public Function insertBlock(blkRef As AcadBlockReference) As AcadBlock
'Insert the block, creating a block reference
'Dim blockObj As AcadBlock
'Dim blkRef As AcadBlockReference
Dim pt As Variant
blockObj = ThisDrawing.Blocks.Add(pt, strRandomBlkName)
pt = ThisDrawing.Utility.GetPoint(, "Insert block: ")
Set blockObj = ThisDrawing.ModelSpace.insertBlock(pt, strRandomBlkName, 1#, 1#, 1#, 0)
'Set blkRef = insertBlock
End Function
Public Function randomblkName() As String
Dim iRandom As Integer
iRandom = Int((1000 * Rnd) + 1)
randomblkName = "TEST" & "-" & CStr(iRandom) & "-" & Format(Now, "yymmss")
End Function
Sub BlockTEST()
Dim LayerName As String
Dim strRandomBlkName As String
LayerName = "Geometry"
' 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 blockObj As AcadBlock
strRandomBlkName = randomblkName
Set Block = ThisDrawing.Blocks.Add(ptOrigin, strRandomBlkName)
' Make point arrays for lines
Dim pt1(2) As Double
pt1(0) = -1#: pt1(1) = 6#: pt1(2) = 0#
Dim pt2(2) As Double
pt2(0) = 1#: pt2(1) = 0#: pt2(2) = 0#
Dim pt3(2) As Double
pt3(0) = 0#: pt3(1) = -1#: pt3(2) = 0#
Dim pt4(2) As Double
pt4(0) = 0#: pt4(1) = 6#: pt4(2) = 0#
Block.AddLine pt1, pt2
Block.AddLine pt3, pt4
' Make sure layer exists
'ThisDrawing.Layers.Add (LayerName)
End Sub
Public Function insertBlock(blkRef As AcadBlockReference) As AcadBlock
'Insert the block, creating a block reference
'Dim blockObj As AcadBlock
'Dim blkRef As AcadBlockReference
Dim pt As Variant
blockObj = ThisDrawing.Blocks.Add(pt, strRandomBlkName)
pt = ThisDrawing.Utility.GetPoint(, "Insert block: ")
Set blockObj = ThisDrawing.ModelSpace.insertBlock(pt, strRandomBlkName, 1#, 1#, 1#, 0)
'Set blkRef = insertBlock
End Function
Public Function randomblkName() As String
Dim iRandom As Integer
iRandom = Int((1000 * Rnd) + 1)
randomblkName = "TEST" & "-" & CStr(iRandom) & "-" & Format(Now, "yymmss")
End Function