Task Scheduler

Discussion in 'SolidWorks' started by pfarnham, Mar 28, 2008.

  1. pfarnham

    pfarnham Guest

    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!!!! :)
     
    pfarnham, Mar 28, 2008
    #1
  2. pfarnham

    TOP Guest

    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
     
    TOP, Mar 29, 2008
    #2
  3. pfarnham

    pfarnham Guest

    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
     
    pfarnham, Mar 31, 2008
    #3
  4. pfarnham

    Ronni Guest

    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 ´this 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 = "C:\YourFolderWithFiles\"
    Const swDocType = ".SLDDRW" ´here you set the type of files you want
    to open

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

    ' start of main program
    Set swApp = Application.SldWorks
    swApp.Visible = True
    ChDir (workDir)
    Response = Dir(workDir)
    Do Until Response = ""
    ' see if filename ends with .SLDDRW or which filetype you
    putted as swDocType
    swUpper = UCase$(Response)
    If Right(swUpper, 7) = 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) = ".SLDPRT" Then
    swDocTypeLong = swDocPART
    ElseIf UCase$(swDocType) = ".SLDASM" Then
    swDocTypeLong = swDocASSEMBLY
    ElseIf UCase$(swDocType) = ".SLDDRW" Then
    swDocTypeLong = swDocDRAWING
    Else
    Stop 'Error Occured
    End If

    Dim swName As String
    swName = workDir & Response

    Dim nErrors As Long
    Dim nWarnings As Long

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

    ´HERE 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 = swModel.GetTitle
    ReturnVal = swModel.Save2(silent)

    swApp.CloseDoc DocName
    Set swModel = Nothing


    End If

    ' get the next filename


    Response = Dir
    Loop


    Set swApp = Nothing
    End Sub


    I hope this will help you get there. Or I am sure many others can fill
    in the missing parts.
     
    Ronni, Apr 1, 2008
    #4
  5. pfarnham

    Ronni Guest

    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:
     
    Ronni, Apr 1, 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.