AnsweredAssumed Answered

Is it possible save SketchPictures to file?

Question asked by roberto gennari on May 28, 2015
Latest reply on May 28, 2015 by roberto gennari


I have a question about SketchPicture:

Is it possible save to file (.png) a SketchPicture from a drawing view?


Option Explicit

Option Compare Text


Dim swApp As SldWorks.SldWorks

Dim Part As ModelDoc2


Sub main()

    Dim myDraw As DrawingDoc

    Dim mySheet As Sheet

    Dim mySketch As Sketch

    Dim sa As Variant

    Dim mySkPic As SldWorks.SketchPicture

    Dim w As Long, h As Long

    Dim wd As Double, hd As Double

    Dim n As Long

    Dim x As Double, y As Double

    Dim myFeat As Feature

    Dim boolstatus As Boolean

    Dim myMgr As SketchManager


    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc

    Set myDraw = Part

    If myDraw.GetEditSheet Then myDraw.EditTemplate


    Set mySheet = myDraw.GetCurrentSheet

    Set myMgr = Part.SketchManager


    Set mySketch = mySheet.GetTemplateSketch

    sa = mySketch.GetSketchPictures


    If IsEmpty(sa) Then Exit Sub

    Set mySkPic = sa(0)


    n = mySkPic.GetPixelmapSize(w, h)

    mySkPic.GetSize wd, hd

    mySkPic.GetOrigin x, y


    Debug.Print "Width=" & w & ", Height=" & h & ", x=" & Round(x * 1000, 1) & ", y=" & Round(y * 1000, 1)

'Actually, wd and hd are what we need, not w and h


    Set myFeat = mySkPic.GetFeature


    'Doesn't work:

    boolstatus = Part.Extension.SelectByID2(myFeat.Name, "SKETCHBITMAP", 0#, 0#, 0, False, 0, Nothing, 0)


'Here save the image to file



End Sub


Thanks to everybody