AnsweredAssumed Answered

Can't find the instance of a sketch block definition on a drawing sheet.

Question asked by Greg Ashmore on Nov 16, 2017
Latest reply on Nov 17, 2017 by Josh Brady

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?

 

Thanks.

 

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)

         oDrawingModel.ActivateSheet(sSheetName)

         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

               End If

            Next

         End If

         If Not nInstanceSeen Then

            Throw New Exception("Datamatrix sketch block not found on sheet " & (iSheetCur + 1).ToString)

         End If

 

         iSheetCur += 1

      End While

 

 

      oMathPoint = Nothing

      oSketch = Nothing

      oaSketchBlockInstances = Nothing

      oSketchBlockInstance = Nothing

      oView = Nothing

   End Sub

Outcomes