API help : Save as Jpeg

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

Reply to
Jean Marc
Loading thread data ...

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

Reply to
Wayne Tiffany

hat opens all parts in a dir one at a time,

Wayne,

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

Matt

Reply to
fcsuper

No, sorry. It's just something I picked up somewhere, obviously it was created several years ago. Maybe he's lurking here??

WT

Reply to
Wayne Tiffany

Thanks for the answers, we'll see what we can do. If anything usable i'll make it available here. JM

"Wayne Tiffany" a écrit dans le message de news: 4787b21e$0$1348$ snipped-for-privacy@reader.greatnowhere.com...

Reply to
Jean Marc

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.