Archive

Posts Tagged ‘pdm’

Workgroup PDM Macro 4 – Export PDFs of Drawings in a Project

September 23rd, 2010

Again in this series of Workgroup PDM Macros, this one builds upon the previous. It’s actually nearly identical, but instead of going “doc.Save”, we go “doc.SaveAsPDF”.

The Macro

This macro saves/exports the PDF of all Drawings in a Project in the PDM Vault onto a local computer.

' Title of Macro: Save/Export PDFs from all Drawings in a Workgroup PDM Project
' Further info: http://solidworks.burkesys.com/category/macro/
' Author: Stephen Burke | www.sburke.eu
' Version: SolidWorks 2010
' Add in "SolidWorks Workgroup PDM 1.0 Type Library" under: Tools - References
' Date: 23/09/2010

Option Explicit
Dim swApp As Object
Sub main()
    Dim connection As PDMWConnection
    Set connection = CreateObject("PDMWorks.PDMWConnection")
    connection.Login "pdmwadmin", "pdmwadmin", "localhost"
    'Enter your PDM Login details above, "username", "password", "pdmserver"

    Dim alldocs As PDMWDocuments
    Dim doc As PDMWDocument
    Dim project
    Dim item
    Dim msg
    Dim filename
    Set alldocs = connection.Documents
 
    Dim options As PDMWorks.PDMWSearchOptions
    Dim criteria As PDMWorks.PDMWSearchCriteria
    Dim results As PDMWorks.PDMWSearchResults
    Dim result As PDMWorks.PDMWSearchResult
    Dim i
    Dim cnt
 
    Set options = connection.GetSearchOptionsObject
    options.SearchOnlyChildrenOf = "Project1"
    ' ^ Type in the name of the Project you wish to save the files out of.

    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "slddrw"
    ' ^ set the search query: look for "All" (everything/*) in slddrw.

    Set results = connection.Search(options)
    cnt = results.Count
 
    For i = 0 To cnt - 1
        Set result = results(i)
        'msg = MsgBox(result.Name, vbCritical)
        Set doc = alldocs(result.Name)
        doc.SaveAsPDF "C:\Temp\"
 
        'filename = "C:\Temp\" & Replace(result.Name, ".SLDDRW", " ") & result.Revision & ".pdf"
        'If Dir(filename) <> "" Then Kill filename
        'Name "C:\Temp\" & result.Name & ".pdf" As filename
        ''Uncomment the above 3 lines. This will output the file "drawing 01.pdf", where 01 is the current revision of the drawing.
    Next i
 
    connection.Logout
End Sub

Make sure to scroll to the right in the code area above ^. Link to Macro Download

Note: The default filename which will be created is “filename.SLDDRW.pdf”. I read on the SolidWorks Forums of a person requesting an output file name: “filename 01.pdf” where 01 is the current revision. This functionality is in the above code. Uncomment the 3 lines underneath “doc.SaveAsPDF” (do so by removing the single quotation mark ‘ ). This is quite nice, because if this macro was being run by the Task Scheduler every night, it would be evident from looking at C:\Temp (or outbox folder specified) that  a new revision is available.

Readme

New in SolidWorks 2008 was the option to automatically have PDM create a PDF for every drawing upon check-in. This macro saves/exports this PDF, and is much quicker than if we were to re-print a PDF. If however, the option to create PDFs on check-in is not set in the Vault Admin Tool, this Macro will not work. See image below for where this option is within the VaultAdmin Tool.

The setting to create PDFs must be set in the Vault Admin Tool.

If this setting was not turned on, and you just enabled it, this macro still won’t work. The PDF only gets created upon check-in of drawings after this above setting is enabled. To check to see if a PDF is available for drawings in the Vault, right-click on a Drawing and see if the option “View Document as PDF” is available (see image below). If this method works, then the macro should too. If a drawing does not have a PDF, you may get the error “An unknown filesystem error occurred. (50)”. In this case, set the above option, checkout and checkin the drawing to have the PDF created automatically.

Right-click on a drawing and go "View Document as PDF" to check if the PDF shows.

Cautionary Warning

While macros are very powerful and can perform a lot of tasks in a short space of time, you need to be very careful. Manually, the PDFs exported, need to be checked by hand, individually, to make sure the contents are correct and accurate. A disaster can occur if someone runs the above macro and sends them off to manufacture, but never checks to see if the exported PDFs are correct and accurate. Check and check again. Unfortunately issues for whatever reason can occur, and its not enough just to say “it should have worked, its not my fault, I just ran the macro and emailed the pdfs”. Manual checking of the actions carried out by the macro must be done.

Macro , , ,

Workgroup PDM Macro 3 – Save out all files & linked files in a Project

September 23rd, 2010

In the previous Workgroup PDM Macro, there was a limitation when saving files in a Project, in that linked files were not saved. That was because “PDMWConnection::DocumentList” listed document names for the specified project, and has no option to include referenced/linked files.

The Macro

This macro saves all files including linked files in a particular Project in the PDM Vault, to the local computer.

' Title of Macro: Save all files & linked files from a Project in Workgroup PDM
' Further info: http://solidworks.burkesys.com/category/macro/
' Author: Stephen Burke | www.sburke.eu
' Version: SolidWorks 2010
' Add in "SolidWorks Workgroup PDM 1.0 Type Library" under: Tools - References
' Date: 23/09/2010

Option Explicit
Dim swApp As Object
Sub main()
    Dim connection As PDMWConnection
    Set connection = CreateObject("PDMWorks.PDMWConnection")
    connection.Login "pdmwadmin", "pdmwadmin", "localhost"
    'Enter your PDM Login details above, "username", "password", "pdmserver"

    Dim alldocs As PDMWDocuments
    Dim doc As PDMWDocument
    Dim project
    Dim item
    'Dim msg
    Set alldocs = connection.Documents
 
    Dim options As PDMWorks.PDMWSearchOptions
    Dim criteria As PDMWorks.PDMWSearchCriteria
    Dim results As PDMWorks.PDMWSearchResults
    Dim result As PDMWorks.PDMWSearchResult
    Dim i
    Dim cnt
 
    Set options = connection.GetSearchOptionsObject
    options.SearchOnlyChildrenOf = "Project2"
    ' ^ Type in the name of the Project you wish to save the files out of.

    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "sldprt"
    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "slddrw"
    options.SearchCriteria.AddCriteria pdmwOr, pdmwDocumentName, "All", pdmwContains, "sldasm"
    ' ^ set the search query: look for "All" (everything/*) in sldprt,sldasm,slddrw.

    Set results = connection.Search(options)
    cnt = results.Count
 
    For i = 0 To cnt - 1
        Set result = results(i)
        'msg = MsgBox(result.Name, vbCritical)
        Set doc = alldocs(result.Name)
        doc.Save "C:\Temp\"
    Next i
 
    connection.Logout
End Sub

Make sure to scroll to the right in the code area above ^.

If you are having issues or errors make sure you look at the previous two posts with details on using the PDM API #1, #2.

This macro searches for all files in a particular project. It may not be the most efficient macro, but it works, and provides an excellent building block from which to make more intelligent and useful macros. It opens a lot more possibilities of been able to search the Workgroup PDM Vault in a scripted manner and carry out various operations such as saving out files. Again, the SolidWorks Task Scheduler can be set to run this macro periodically. Comments are welcome.

Macro , , ,

Workgroup PDM Macro 2 – Save out all files in a Project

September 23rd, 2010

So the previous post showed how a single file can be saved from Workgroup PDM onto your local computer using a macro. This macro builds upon that. If you are starting out with macros, I suggest you go back and get that working first.

The Macro

' Title of Macro: Save all files out from a Project in Workgroup PDM
' Further info: http://solidworks.burkesys.com/category/macro/
' Author: Stephen Burke | www.sburke.eu
' Version: SolidWorks 2010
' Add in "SolidWorks Workgroup PDM 1.0 Type Library" under: Tools - References
' Date: 23/09/2010

Option Explicit
Dim swApp As Object
Sub main()
    Dim connection As PDMWConnection
    Set connection = CreateObject("PDMWorks.PDMWConnection")
    connection.Login "pdmwadmin", "pdmwadmin", "localhost"
    'Enter your PDM Login details above, "username", "password", "pdmserver"

    Dim alldocs As PDMWDocuments
    Dim doc As PDMWDocument
    Dim project
    Dim item
    'Dim msg
    ' ^ remove the single quote from above if you want to debug.

    Set alldocs = connection.Documents
    project = connection.DocumentList("Project1")
    ' ^ Type in the name of the Project you wish to save the files out of.

    For Each item In project
        'msg = MsgBox(item, vbCritical)
        ' ^ remove the single quote from above if you want to debug.
        Set doc = alldocs(item)
        doc.Save "C:\Temp\"
    Next item
 
    connection.Logout
End Sub

Readme

This macro uses connection.DocumentList(“Projectname”) to create an array of files contained in a particular project in the PDM Vault. To debug this macro further, uncomment the lines “Dim msg” and “msg = MsgBox(item, vbCritical)”, and when you run the macro you will get a pop-up dialog telling you the names of each of the files found in the PDM Project.

There is one cavet. If you have links / references in the Project you are saving, those linked files will not be saved. E.g. in the image below, the Car-and-Engine-Drawing and the Slide3 files will not be saved out. I will post a following macro which will be able to save linked files.

Linked files will not be saved.

I’m not going to provide a download of this Macro. I recommend that you create a new Macro in SolidWorks, and type (or copy and paste) the above code into the new empty macro. Also, in case you have not read the previous macro, make sure to add in “SolidWorks Workgroup PDM 1.0 Type Library” under Tools -> References in Microsoft Visual Basic. That way you can use “IntelliSense” (code prompt and completion) to make sure that the pdm parameters are referenced correctly. In the image below, after typing the . (period/full stop), a drop-down list of available parameters should show up. If the drop-down list doesn’t show up, something is wrong. Check Tools -> References and go from there.

IntelliSense Code completion helps make sure you are referencing the PDM API correctly

Macro , , ,