From: stevefye on
You have the API code for that?(the File-Open routine usually called by
the Common-Dialog Control)? That would be awesome.

For the original poster, yes, standard VB will do what you're wanting.
I've already written code that will parse a directory for a quick
batch-print. Let me know what you intend to do to the drawings once
you have opened them.

From: That70sTick on
<http://www.mentalis.org/index2.shtml>

API calls to get components not directly licensed.
Perfectly legit.

From: Tin Man on
There's a macro at http://www.nhcad.com/sw_macros/ called BATCH
OPEN.SWB that will open all the files in a specified directory (one at
a time), perform a function, then save and close. The code is setup to
open parts and change their density, but it can easily be modified to
open assemblies and drawings.

Ken

From: Ben Eadie on
Crossed fingers that I can get this to work... So far I had to remove
the "_" from the code in sections like this to get no syntax errors.

Set modelDoc = swApp.OpenDoc2 (Response, _

swDocPart, readOnly, viewOnly, _

silent, returnVal)
this becomes

" Set modelDoc = swApp.OpenDoc2 (Response, swDocPart, readOnly,
viewOnly, silent, returnVal) "

But nothing seems to be happening, no files open and close on the SW
screen. Here is what I have done so far with the code

1. Changed the working directory in this -Const workDir = "c:\jj\sldworks\"

2. Changed the file type to open in this - Const swDocType = ".SLDPRT"
to .SLDDRW

3. Added my code to the function section

Part.SetUserPreferenceIntegerValue swUnitsLinear, swINCHES
Part.SetUserPreferenceIntegerValue swUnitsLinearDecimalDisplay, swFRACTION
Part.SetUserPreferenceIntegerValue swUnitsLinearFractionDenominator, 16
Part.SetUserPreferenceToggle swUnitsLinearRoundToNearestFraction, True
Part.SetUserPreferenceIntegerValue swUnitsAngularDecimalPlaces, 0


But still nouthing????? What am I missing here? Unfortunately this will
even not run as the original code to change densities with the syntax
corrections as mentied above and set to a local directory> I wonder if
this is a machine setting I am missing in running macros?

Below my name is the entire code I have sorry such a long post but those
out there that like puzzles feel free to dissect this and let me know
what has been done wrong. Guess I could email the original coder "Joe
Jones" if he does not view this forum.


Ben

**********************************************************

'

' batch open.swb - macro recorded on 01/14/00 by

' Joe Jones joe(a)nhcad.com

' New Hampshire CAD www.nhcad.com

'

' This program will do a batch OPEN / CHANGE DENSITY / SAVE / CLOSE

' to all part files ".SLDPRT" found in the working directory.

' With some simple modifications it could be used to batch plot

' or set a host of other user defined values.

'

' to run this program

' 1) start solidworks - do not open any part files

' 2) edit this macro to use the correct working direcotry

' (see "workDir" below)

' 3) run the macro

' ***************************************************************

Dim swApp As Object

Dim ModelDoc As Object

Dim ReturnVal As Long

Dim Response As String

Dim DocName As String

Dim Success As Boolean

Dim DocType As String





' *********** YOU MAY HAVE TO CHANGE THIS ***********

' change the following constant to target a directory

Const workDir = "C:\New Folder"



' *********** YOU MAY HAVE TO CHANGE THIS ***********

' change the following constant to target a type of file

Const swDocType = ".SLDPRT" ' I am only want to open part files





' the following constants are used in the OpenDoc2() function

Const swDocNONE = 0

Const swDocPART = 1

Const swDocASSEMBLY = 2

Const swDocDRAWING = 3



Const readOnly = 0 ' 0-false 1-true

Const viewOnly = 0 ' 0-false 1-true

Const silent = 1 ' 0-false 1-true





' the following constants are used in the

' SetUserPreferenceDoubleValue() function

Const swDetailingNoteFontHeight = 0

Const swDetailingDimFontHeight = 1

Const swSTLDeviation = 2

Const swSTLAngleTolerance = 3

Const swSpinBoxMetricLengthIncrement = 4

Const swSpinBoxEnglishLengthIncrement = 5

Const swSpinBoxAngleIncrement = 6

Const swMaterialPropertyDensity = 7





' start of main program

Sub main()



Set swApp = CreateObject("SldWorks.Application")

ChDir (workDir)

Response = Dir(workDir)



Do Until Response = ""

' see if filename ends with .SLDPRT

If Right(Response, 7) = swDocType Then



' open the SolidWorks part file

Set ModelDoc = swApp.OpenDoc2(Response, swDocPART,
readOnly, viewOnly, silent, ReturnVal)



' add your own code here to do

' whatever you want to the part file

Success =
ModelDoc.SetUserPreferenceDoubleValue(swMaterialPropertyDensity, 2699)
' kg/(cu meter)



' close the part

DoEvents

DocName = ModelDoc.GetTitle

ReturnVal = ModelDoc.Save2(silent)

swApp.CloseDoc DocName

Set ModelDoc = Nothing

End If

' get the next filename

Response = Dir

Loop

Set swApp = Nothing



End Sub




Tin Man wrote:
> There's a macro at http://www.nhcad.com/sw_macros/ called BATCH
> OPEN.SWB that will open all the files in a specified directory (one at
> a time), perform a function, then save and close. The code is setup to
> open parts and change their density, but it can easily be modified to
> open assemblies and drawings.
>
> Ken
>
From: That70sTick on
I found an example in my own work of the open file Common Dialog via
Windows API. Since then I acquired full VB6 and stopped doing this,
but it's there for your hacking pleasure.

<http://www.esoxrepublic.com/freeware>, in the "Copy Custom Info" macro.