API help : Save as Jpeg

Discussion in 'SolidWorks' started by Jean Marc, Jan 11, 2008.

  1. Jean Marc

    Jean Marc Guest

    We need to write a macro that opens all parts in a dir one at a time,
    put it in "hidden lines", goes to the first config, zoom to isometric, save
    as jpeg name: "filename + configname" - Loop config - Loop next part.

    I plan to start with a macro of what I can do with SW, and give it to one of
    our IT guy to play with. But as there could be something close already done,
    I wonder if anyone knows of some code we could start with.

    TIA
    JM
     
    Jean Marc, Jan 11, 2008
    #1
  2. Here's the code from one that I use tosave out a jpg file.

    ' **************************************************************
    ' JPG Save Macro Created by Matthew Poster on 11/20/2000
    '
    ' This Macro does the following:
    ' 1) Attaches to current SW session
    ' 2) Checks to see if a SW file is open, if so
    ' 3) Attaches to active SW File I.E. part, assembly, drawing if not sends a
    message to the user
    ' 4) If a SW file is open saves JPG image to current directory and adds xxx
    number suffix to the end
    ' 5) If JPG exists in directory already it saves by incrementing the suffix
    ' **************************************************************

    ' Use Option Explicit to avoid mistakes and frustration. With it VB makes
    sure you declare
    ' all your variables kind of like eating all you vegetables.
    Option Explicit

    ' Object type variables
    Dim objSwApp As Object
    Dim objFile As Object

    ' Boolean type variables
    Dim boolstatus As Boolean

    ' Long type variables
    Dim longstatus As Long

    ' String type variables
    Dim ExistingFile As String

    ' Declaring file name variables
    Dim fnameLength
    Dim fName
    Dim x

    ' Beginning of macro
    Sub main()

    ' Attach to the current SW session
    Set objSwApp = CreateObject("SldWorks.Application")

    ' Attach to the current active file to be worked on
    Set objFile = objSwApp.ActiveDoc

    ' Error checker to see if a file is open
    If objFile Is Nothing Then

    ' If nothing is loaded then notify the user
    objSwApp.SendMsgToUser ("Please open a SolidWorks File!")

    ' ends macro
    End

    ' End the If then statement
    End If

    fnameLength = Len(objFile.GetPathName) - 6 'Strip the file extension but
    leave "." so if objFile number is a # it won't be affected
    fName = Left(objFile.GetPathName, fnameLength)

    ' check to see if directory has fName.x.jpg and increment x
    ' until there are no files of that extension
    x = 1

    While 1 = 1 'Repeat loop until kicked out
    ExistingFile = Dir(fName & x & ".JPG")
    If ExistingFile = "" Then GoTo GotExtensionName 'no file of that
    suffix exists
    x = x + 1
    Wend ' End of While Loop

    GotExtensionName: 'we know which value of x to use

    objFile.SaveAs2 fName & x & ".JPG", 0, True, False ' newName, saveAsVersion,
    saveAsCopy, silent

    End Sub
     
    Wayne Tiffany, Jan 11, 2008
    #2
  3. Jean Marc

    fcsuper Guest

    Wayne,

    Do you have a source for that code, like where I can contact Matthew
    Poster?

    Matt
     
    fcsuper, Jan 11, 2008
    #3
  4. No, sorry. It's just something I picked up somewhere, obviously it was
    created several years ago. Maybe he's lurking here??

    WT
     
    Wayne Tiffany, Jan 11, 2008
    #4
  5. Jean Marc

    Jean Marc Guest

    Thanks for the answers, we'll see what we can do. If anything usable i'll
    make it available here.
    JM
     
    Jean Marc, Jan 18, 2008
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.