Another newbie question that my designers can't answer. Both are collections of entities (lines, polylines, circles, text etc), but I can find nothing online that explains the difference, why one would be chosen over the other and how they interrelate. The code I have inherited mixes them interchangeably.
By way of an example, I have some code that creates a BlockReference:
Public Sub Draw1Lifter(ByVal x As Double, ByVal y As Double, ByRef parent As AcadBlock, ByVal myDocuments As AcadDocumentManagerExample, ByVal strCoreNumber As String)
Dim insertionPt(2) As Double
insertionPt(0) = x
insertionPt(1) = y
insertionPt(2) = 0
importLifterTemplate(myDocuments)
Dim lifterblkref As AcadBlockReference = parent.InsertBlock(insertionPt, "EasiCADLifter", 1, 1, 1, 0.0)
lifterblkref.Layer = "SLABOUTLINE"
'Update core number
Dim props As Object
props = lifterblkref.GetAttributes
Dim attr As AcadAttributeReference
For Each attr In props
If attr.TagString = "LifterCoreNumber" Then
attr.TextString = strCoreNumber
Exit For
End If
Next
End Sub
But prior to that it calls a subroutine called importLifterTemplate which passes the AcadDocument variable 'myDocuments' by reference. This is picking up a Block called 'EasiCADLifter' and then manipulating it using an Blockreference 'EasiCADLifterTemp' :
Public Sub importLifterTemplate(ByRef myDocuments As AcadDocumentManagerExample)
Dim lifterBlock As AcadBlock = Nothing
Dim insertionPt(2) As Double
If lifterTemplateImported Then Exit Sub
Try
lifterBlock = myDocuments.ThisDrawing.Blocks.Item("EasiCADLifter")
lifterBlock.Name = "EasiCADLifterTemp"
Try
Dim filepath As String = System.IO.Path.GetDirectoryName(New System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath) + "\\EasiCADLifter.dwg"
Dim lifterBlockRef As AcadBlockReference = myDocuments.ThisDrawing.ModelSpace.InsertBlock(insertionPt, filepath, 1, 1, 1, 0.0)
lifterBlockRef.Delete()
' Delete existing entities from EasiCADLifterTemp block
For Each entity As AcadEntity In lifterBlock
entity.Delete()
Next
Dim newBlk As AcadBlock = myDocuments.ThisDrawing.Blocks.Item("EasiCADLifter")
Dim entities(newBlk.Count - 1) As AcadEntity
For index As Integer = 0 To newBlk.Count - 1
entities(index) = newBlk.Item(index)
Next
newBlk.Delete()
' Copy all the entities to the block
Dim copiedObj As Object = myDocuments.ThisDrawing.CopyObjects(entities, lifterBlock)
Catch ex1 As System.Exception
' ignored
End Try
lifterBlock.Name = "EasiCADLifter"
Dim attrCoreNumber As AcadAttribute
attrCoreNumber = lifterBlock.AddAttribute(75, AcAttributeMode.acAttributeModeNormal, "LifterCoreNumber", insertionPt, "LifterCoreNumber", "")
attrCoreNumber.Visible = False
' Refresh drawing
myDocuments.ThisDrawing.Regen(AcRegenType.acActiveViewport)
Catch ex As System.Exception
Dim filepath As String = System.IO.Path.GetDirectoryName(New System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath) + "\\EasiCADLifter.dwg"
Dim lifterBlockRef As AcadBlockReference = myDocuments.ThisDrawing.ModelSpace.InsertBlock(insertionPt, filepath, 1, 1, 1, 0.0)
lifterBlockRef.Delete()
Dim attrCoreNumber As AcadAttribute
lifterBlock = myDocuments.ThisDrawing.Blocks.Item("EasiCADLifter")
attrCoreNumber = lifterBlock.AddAttribute(75, AcAttributeMode.acAttributeModeNormal, "LifterCoreNumber", insertionPt, "LifterCoreNumber", "")
attrCoreNumber.Visible = False
End Try
lifterTemplateImported = True
End Sub
Now when I talk to my designers, they tell me that they use Layers to differentiate different parts of a drawing, not Blocks. There are a few of the older hands that have used Blocks for metadata...and none of them have heard of a BlockReference. I can see the blocks on the drawing and view their attributes using BATTMAN, so why is this code using a BlockReference?
I'm going to have to identify this product, just in case the people who wrote this and support it are reading this. It's called FloorCAD, whom we bought the code off a couple of years ago and is an automation tool that helps designers build precast concrete hollowcore flooring.
A secondary question I have is about the hierarchy in a document. I can't find anything that provides an overview of the hierarchy of the contents of a drawing on the web. Anyone got anything helpful?