Accessing Sketch Hatches on the Sheet Format?

I’m working on some code that goes through all the different views on a drawing sheet (Sheet Format, Drawing Sheet, Drawing Views) and accesses any Sketch Hatches. I am able to access the Sketch Hatches in all the views with the exception of the Sheet Format (AKA Sheet Template).

Here’s a snip of code that deletes the hatches in most of the views successfully. I added the “swDraw.EditTemplate” statement to get it to work on the sheet format, but no luck. Any ideas?

Set swDraw = swModel
swDraw.EditTemplate	
Set swSketch = swView.GetSketch
vSketchHatch = swSketch.GetSketchHatches
If Not IsEmpty(vSketchHatch) Then
    For i = 0 To UBound(vSketchHatch)
        Set swSketchHatch = vSketchHatch(i)
        swSketchHatch.Select False
        swModel.Extension.DeleteSelection2 swDelete_Absorbed
    Next i
End If
swDraw.EditSheet

Hi Loeb,

I believe you would need to get the sketch from the sheet instead of the view, since the sheet format itself will have none. See following link. Hope it helps.

1 Like

Thank you. That gives me a path forward.

It funny, I am able to draw on the Sheet Format without getting the sketch at all with this code

swDraw.EditTemplate
Set swSketchMgr = swModel.SketchManager
swSketchMgr.CreateCircle 0#, 0#, 0#, 3 * 0.0254, 0#, 0#
DrawSketchEntity = True

I find the SW API to be not very intuitive. This forum is a life saver.

Thanks!

1 Like

I found a slightly different solution. Seems I should have been using

Set swSketch = swModel.GetActiveSketch

instead of

Set swSketch = swView.GetSketch

Side note: The API help says that GetActiveSketch2 is superceded by GetActiveSketch. Seems backwards. Both seem to work.

The API Helps says that IModelDoc2::GetActiveSketch2 was superseded by SketchManager:ActiveSketch

Nothing backwards about it. Two different classes.

When COM objects are updated by adding methods or properties the convention is to add a numeric increment to the class name. So ModelDoc becomes ModelDoc2. If a method is changed to add new parameters or change the return type, a numeric increment is applied to the method name. ModelDoc2::GetActiveSketch becomes ModelDoc2::GetActiveSketch2.

The incremented classes and methods aren’t revisions of the originals. They are brand new. The old classes and methods remain for backward compatibility. It’s usually good practice to use the latest versions, unless they have a bug.

2 Likes