Task Scheduler

First many thanks to Freddy, for the Catico link, it is now in English and works great so far!

Now I need some clever peeps!

Task scheduler has an option to update documents in a folder.

What I want is a macro that will do the same but with the added function of changing the part and assembly views to iso, then zoomed to fit and finally to save the part or assembly document. If this is a drawing document, I want to zoom to fit, and then save, only.

Why would I want this you may ask, well as I do a lot of prototyping work, I quite often need to zoom in a document, ( to get a dimension), for example.

When I have finished, I then "save all", so that all documents are saved, (so that I don't miss any changes made).

End result = messed up views that can not be seen clearly enough in explorer or Pdmworks!

Solidworks crashes mid-stream.....

End result 2 = messed up views, Grrrrr!

I can record a macro, to do the zoom to fit and the iso view, but only for that file, that is open.

What I want is the information on how to get each file in turn, decide if part assembly or drawing document and proceed accordingly.

Anyone have the answer?

Ps I have googled for the past two weeks and now I am stuck :-(

Many thanks if you want to help!!!! :-)

Reply to
pfarnham
Loading thread data ...

I'll have to look. It isn't hard to do, in fact if you just record a macro you might get there yourself. But I will look.

TOP

Reply to
TOP

Hi Top, After recording the macro, all I can do when running the macro, is open the document, that was opened, when the macro was recorded.

I want to open all of the documents in a folder, (one by one), decide if a drawing or part/assembly, do what is required and then close the document, the get the next one.

What i need is the fuction call to get each document in turn. This is where I am stuck.

Pete

Reply to
pfarnham

I have made a macro from various bits from this user group.

All it does is open all files in a folder 1by1 - rebuilding it - and saving them again.

I am sure you can gather the pieces to make a macro to suit your needs (just add the call for fit and zoom, also iso is a standard named view so that is easy also).

I would like to add that my macro in its current form is used on a speciel type of file (slddrw or sldasm or sldprt) but you can just make a loop to make it able to work on all.

In my expirience dont run it with more than 100-200 files a pop, since you will continue to fill the SW memory with this kind of macro that works from inside SW (and dosnt reboot it after each file).

Here it goes:

Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.DrawingDoc =B4this you would have to make a loop with to be used for the different file types .AssemblyDoc and .PartDoc Dim ReturnVal As Long Dim Response As String Dim DocName As String Dim Success As Boolean Dim DocType As String Dim swUpper As String Dim swDocTypeLong As Long

Const workDir =3D "C:\YourFolderWithFiles\" Const swDocType =3D ".SLDDRW" =B4here you set the type of files you want to open

Const readOnly =3D 0 ' 0-false 1-true Const viewOnly =3D 0 ' 0-false 1-true Const silent =3D 1 ' 0-false 1-true

' start of main program Set swApp =3D Application.SldWorks swApp.Visible =3D True ChDir (workDir) Response =3D Dir(workDir) Do Until Response =3D "" ' see if filename ends with .SLDDRW or which filetype you putted as swDocType swUpper =3D UCase$(Response) If Right(swUpper, 7) =3D swDocType Then

' open the SolidWorks file (this bit can handle all the 3 types of SW files, this is done so I can easily what between file types just by changing swDocType and swModel) If UCase$(swDocType) =3D ".SLDPRT" Then swDocTypeLong =3D swDocPART ElseIf UCase$(swDocType) =3D ".SLDASM" Then swDocTypeLong =3D swDocASSEMBLY ElseIf UCase$(swDocType) =3D ".SLDDRW" Then swDocTypeLong =3D swDocDRAWING Else Stop 'Error Occured End If

Dim swName As String swName =3D workDir & Response

Dim nErrors As Long Dim nWarnings As Long

Set swModel =3D swApp.OpenDoc6(swName, swDocDRAWING, swOpenDocOptions_e.swOpenDocOptions_Silent, "", nErrors, nWarnings)

=B4HERE you can add the call for fit and iso view (I dont recall it and dont have time to look it up)

DoEvents

swModel.ForceRebuild3 False

DocName =3D swModel.GetTitle ReturnVal =3D swModel.Save2(silent)

swApp.CloseDoc DocName Set swModel =3D Nothing

End If

' get the next filename

Response =3D Dir Loop

Set swApp =3D Nothing End Sub

I hope this will help you get there. Or I am sure many others can fill in the missing parts.

Reply to
Ronni

Hmm dont seem to be able to find an "edit" function.. just a small change

I see I overwrited the handling of all the 3 types of file by setting swDocDRAWING directly instead of using swDocTypeLong... So here is how it should have looked:

Reply to
Ronni

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.