I have a SketchBlockDefinition in a drawing.
The drawing has just one sheet.
There is an instance of the sketch block definition in the sheet format.
I activated the sheet and retrieved the first view, which I believe is the sheet view.
I got the sketch for the view and called GetSketchBlockInstances.
The return was Nothing.
I expected to get a reference to the block instance that is in the sheet format.
In this drawing, which has only one instance of the sketch block definition, I could get the block definition from the document sketch manager, and retrieve the instance from the block definition.
But in the general case, there may be multiple sheets, each sheet having its own instance of the block definition in the sheet format.
I need to discover the location of each instance in its sheet so that I can insert an entity at an offset from that location.
I can get the sketch from the instance, but I don't see anyway of determining which sheet the sketch is associated with.
So I have no way of associating the instance with a sheet.
How can I get the instance of the sketch block definition in a sheet format?
Here is the code:
Private Shared Sub DatamatrixInstanceLocationsGet()
Dim nInstanceSeen As Boolean
Dim iSheetCur As Integer
Dim sSheetName As String
Dim oMathPoint As MathPoint
Dim oSketch As Sketch
Dim oaSketchBlockInstances() As Object
Dim oSketchBlockInstance As SketchBlockInstance
Dim oView As SolidWorks.Interop.sldworks.View
iSheetCur = 0
While iSheetCur < iSheetCount
sSheetName = oaSheetNames(iSheetCur)
oView = oDrawingModel.GetFirstView
oSketch = oView.GetSketch
nInstanceSeen = False
oaSketchBlockInstances = oSketch.GetSketchBlockInstances <<<<<<<<<<< returns Nothing
If oaSketchBlockInstances IsNot Nothing Then
For Each oSketchBlockInstance In oaSketchBlockInstances
If oSketchBlockInstance.Definition.FileName = sDatamatrixBlockDefinitionFileName Then
oMathPoint = oSketchBlockInstance.InstancePosition
faDatamatrixBlockOriginX(iSheetCur) = oMathPoint.ArrayData(0)
faDatamatrixBlockOriginY(iSheetCur) = oMathPoint.ArrayData(1)
nInstanceSeen = True
If Not nInstanceSeen Then
Throw New Exception("Datamatrix sketch block not found on sheet " & (iSheetCur + 1).ToString)
iSheetCur += 1
oMathPoint = Nothing
oSketch = Nothing
oaSketchBlockInstances = Nothing
oSketchBlockInstance = Nothing
oView = Nothing