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 , , ,

Workgroup PDM Macro 1 – Save out a single file onto your computer

September 23rd, 2010

Skip straight to the Macro >

Introduction

Macros in SolidWorks are extremely powerful and useful. They can be however difficult to maintain, especially when upgrading to new versions of SW and requires a good knowledge of SW API and VB/C++. There are also many macros available for SolidWorks, (lenny’s SW Macros, 3D ContentCentral Macros, Loronos SW Macro Downloads, SolidWorks Forums – login required, and SolidWorks API Examples – broken, even when logged in) which are particularly helpful to study and use as a foundation to build your own macro. Unfortunately there are very few macros available for Workgroup PDM and some of which seem to get lost, especially links on the SolidWorks website (the sample pdm api project on the main solidworks help website is broken – FAIL). Also most of the active work regarding managing SW data is going towards SolidWorks Enterprise PDM which sits on a SQL server as opposed to a file based DB with Workgroup PDM.

SolidWorks Workgroup PDM is a product that comes with SolidWorks Professional and SolidWorks Premium. It allows for revision control of SolidWorks files, and allows multiple people to work on the same SolidWorks project. All SolidWorks files (and other files such as DWG, doc, jpg) gets stored in a main Vault on a central server. There is no direct access to files in the PDM Vault. Access must be through either SolidWorks or SolidWorks Explorer with a PDM Add-In. Files in the vault cannot be accessed directly via Windows Network Share/SMB. As a result interaction with data in Workgroup PDM must be done manually. However here is where SolidWorks Macros and the PDM API comes in.

This macro is the first of a few that I am going to write on Workgroup PDM. If your beginning to write macros, I’d recommend starting with this Macro which is a good foundation.

The Macro


This macro allows a user to copy/save a single specified file from the PDM Vault onto their computer.
While this is quite a small task, it is an excellent beginning to learn the SolidWorks PDM API.

Download Zip file of the Macro >

' Title of Macro: Save a single file out from the Workgroup PDM Vault
' Further info: http://solidworks.burkesys.com/category/macro/
' Author: Stephen Burke | www.sburke.eu
' Version: SolidWorks 2010
' Instructions: Replace "123456.SLDDRW", with the file required.
' 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
    Set alldocs = connection.Documents
 
    Set doc = alldocs("123456.SLDDRW")
    ' ^ Type in the name of the file you wish to save out.
    doc.Save "C:\Temp\"
    ' ^ Type in a folder on your computer to save into.

    connection.Logout
End Sub
Readme / Usage
  1. Open SolidWorks
  2. Tools -> Macro -> Edit (browse to the saved Zip file)
  3. (in Microsoft Visual basic) Tools -> References -> (add-in) “SolidWorks Workgroup PDM 1.0 Type Library”
  4. (in Microsoft Visual basic) Click the Save icon and close down the Visual Basic Editor
  5. (in SolidWorks) Tools -> Macro -> Run
  6. Check C:\Temp for the file

Troubleshooting & FAQ’s

Problem: You receive the following error: “Compile error: Can’t find project or library”
Solution: Go to Tools -> References and add in “SolidWorks Workgroup PDM 1.0 Type Library”. If that does not work, then go to SolidWorks, Tools -> Macro -> New. Choose a new name for the macro and where to save it. This will open up a new Macro. Go to Tools -> References and add in “SolidWorks Workgroup PDM 1.0 Type Library”. Then copy and paste the code from above.

Problem: You receive the following error: “Method ‘Item’ of object ‘IPDMWDocuments’ failed”.
Solution: The file you require was misspelt in the macro, or doesn’t exist in the Vault. Check the line ‘Set doc = alldocs(“123456.SLDDRW”)’

Note: It is not required to be logged into Workgroup PDM within SolidWorks, nor is it required to have “Workgroup PDM” turned on in Tools -> Add-Ins. It is required to have “Workgroup PDM” visible in Tools -> Add-Ins as this indicates that the PDM libraries are installed on your computer.

Note: It is possible to run this Macro from within SolidWorks (Tools -> Macro -> Run) and also from the SolidWorks Task Scheduler with a custom task.

Note: This is the macro in its simplest form. It would be possible to show an input dialog to allow a user select and choose which file to save out.

Note: While this macro was developed with SolidWorks 2010, it is possible to use this macro with all versions of SolidWorks. It would be best to copy and paste the code into a new macro in this case.

Note: If you re-run the macro, it will overwrite and replace any existing file.

SolidWorks Workgroup PDM API Help (pdmworksapi.chm)

This help file contains all the api references which can be used in Macros. This file is essential if you want to make full use of the workgroup PDM in Macros. Getting this file was a little difficult. SolidWorks’s help brought me to here, which wasn’t fully correct, but led me to this. A google before this led me to a 2008 version of this chm file, which fortunately had much more information and examples than the 2010 version. I’m going to provide a mirror of the files here, due to the large amount of broken links that occurs. Local Mirror of pdmworksapi-sw2008.chm and pdmworksapi-sw2010.chm. (You might have to go properties of the chm files after downloading and go “unblock”.) In the pdmworksapi-sw2008.chm, fortunately the Example contained therein had most of the macro in this post.

Stay tuned for more macros based on this simple example.

Macro , , , ,

Restore .NET Framework back to its original state

July 25th, 2010

Background

If you have done a clean re-install of SolidWorks and are still getting strange errors (such as missing dlls, or “unknown file types”), it may well be Microsoft .NET Framework at fault. Most of the time, looking in the Windows Event Viewer will confirm this if there are .NET Framework errors showing up.

The first step is to do a repair of .NET Framework, by going to Add/Remove Programs, right-clicking on .NET Framework (choose 3.5 or 3.1 if present) and going Repair. This should work, however sometimes it doesn’t.

You can also try:
Exploring the SolidWorks DVD and in the prereqs folder run “dotnetfx3.exe” (or dotnetfx3_x64.exe). I tried this however I got strange errors about “mscoree.dll” etc.

Download and usage

If all else fails, you can use a “.NET Framework Cleanup Tool“. It works really well and has worked for me every time. You can download this Executable Tool (in a Zip file) from: http://blogs.msdn.com/b/astebner/archive/2008/08/28/8904493.aspx

  • Just run the exe file and go “Cleanup Now”.
  • It takes around 5 minutes to process and at the end you will be prompted to Restart the Computer. Restart the Computer/
  • After the reboot, look in Add/Remove Programs. If its Windows XP, you will see the original .NET Framework 1.1 listed. Thats perfect.
  • From the prereqs folder of the SolidWorks DVD run “dotnetfx3.exe” or “dotnetfx3_x64.exe”.
  • Once this is installed, you should be able to start SolidWorks. (No need to go reinstalling SolidWorks)
  • Fingers crossed the dll errors or strangeness in SolidWorks will have gone.

Notes:
This worked fine on SolidWorks 2009 and SolidWorks 2010
Search the SolidWorks Knowledge Base for the dll error messages or for errors regarding the feature you are having issues with (such as property tab builder etc.) It will typically tell you if its a .NET issue.
Link to dotnetfx3.exe and dotnetfx3_x64.exe
After running the cleanup tool, rebooting, installing dotnetfx3.exe SolidWorks will work fine.
Installing .NET Framework 3 (the dotnetfx3.exe linked above and on the SW prereqs folder), will install .NET Framework 2.0 and 3.0.
I suggest you run Windows Updates, several times. More than likely a .NET 3.5 will have to be installed. Note also, until you run Windows Updates and install all .NET Frameworks that were in place (in Add/Remove Programs in the very begining), some other installed programs on your computer may give out.
Lastly, use at your own risk!

How-To, Note to Remember , , , ,

Macro Tip – How to quickly stop a SolidWorks macro

July 3rd, 2010

CTRL + Pause/Break

Especially useful for macros which loop through lots of operations.

If you have a looping MsgBox() popup, the above CTRL+break doesn’t seem to work. In this case:

Task Manager -> Processes -> swvbaserver.exe (End Process)
Note: SW may have to be restarted to allow a macro to run afterwards.

Reference

How-To, Macro

Cosmetic Threads in Assembly Drawings

June 23rd, 2010

I did come across this before, but forgot about it. Putting it here will remind me not to forget it again.

Query: Cosmetic threads do not appear in Assembly Drawings.

  1. Create a Part with a Hole Wizard Hole with Cosmetic Thread.
  2. Create a Drawing of the Part, the Cosmetic Thread shows up in Plan, Elevation, Section etc.
  3. Create an Assembly with the above Part.
  4. Create a Drawing of the Assembly, Cosmetic Threads do not show by default.

The SolidWorks Knowledge Base provided a quick answer (S-03448). The above functionality is intended. If you want to see cosmetic threads in Assembly Drawings, you have to go Insert -> Model Items -> Cosmetic Thread

Note to Remember , ,

Problems inserting Routing Components from the Design Library?

April 9th, 2010

Working on a piping project recently, I done a pack-and-go to make sure the project would open correctly on another computer. Weeks later when I got back to the project, I worked on the extracted pack-and-go, and started creating a new route, I found I could not insert piping components (flanges, tees etc.) from the Design Library via drag-and-drop. I would see no preview of the part in order to smart mate it into place. When I tried to drag and drop, I got the error “Drag and Drop Failed” and also “This component is already open, would you like to show it..”.

I’ve had this problem before with one or two parts, and what I done was to rename the particular flange in the Design Library to weld neck flange2 and then it would drag and drop in correctly. This time however it was more widespread.

After searching the SolidWorks Knowledge Base on the Customer Portal, I found my problem. My problem was specifically due to the Pack and Go that I done. The pack-and-go copied all my Routing parts from the Design Library into a flat folder. Upon opening this, the routing parts (flanges, elbows etc.) were loaded up from the Project folder rather than the Deisgn Library.

Rule:
Keep all Routing Components (flanges, tees etc.) IN ONE PLACE, i.e. the Design Library
If you open an Assembly with routing components, and SW loads up a flange from Location X, you cannot drag and drop the same flange from Location Y. Use File -> Find References to check where SW loaded files up from.

Note to Remember ,

Xenocode – running applications (SolidWorks) in the “cloud”

September 5th, 2009

xenocode-solidworks Josh over at solidsmack and a few otherstalk a lot about running applications in the “cloud” and how SolidWorks 3D CAD will run on the Internet, and people use it as required. Its also referred to as SaaS (Software as a Service). Up until today, I didn’t realise how, apart from a citrix or remote desktop scenario which suffers from bandwidth issues. Matt over at dezignstuff has a good article about this, with comments regarding bandwidth issues.

Let me introduce xenocode. I originally came across it for a way to run IE6, IE7 etc for web development purposes.
After a little 2MB app is run, any application can be run within a minute or two. The xenocode website has some examples, from winamp to a DivX player, to Opera, Chrome etc. How about wanting to run Quicktime, without the hassle or large download?!

A few of the main points I found:

  • No installation of the program to run.
  • Full hardware support.
  • Network latency not an issue as application is not streamed when running.
  • Initial download of runtime environment does seem to be required.
  • Typically used for allowing demo use of software, i.e. IE8 etc.

Whether or not its a good idea, or whether it will take off is a different discussion altogether. It’s just with this, it seems a little more possible.

Misc.

SolidWorks 2010 Initial Review

August 24th, 2009

SW2010-Install-4Well after getting my hands on SW2010, I got straight into installing it and looking through the Whats New PDF. The install went fine, albeit I had to end Windows Explorer and WinSCP processes (hopefully this means that the install will be rock solid). For those people who may not be familar with the procedure, I put up some screenshots. In the case of the third image, you may need to go to the View -> Select Columns -> PID to see the appropriate column. Remember, this is only a beta release! I also did change the install directory to Program Files/SolidWorks Corp 2010/.

SW2010-Install-1SW2010-Install-2

The install finished fine. No need to restart the PC as I ended Windows Explorer (and left explorer.exe closed for the duration of the install). I started SW2010 up, activated it and that was it. Easy.
I won’t put the Whats New 2010 PDF here. Here are a few things I like:

PhotoView 360:

  • Choose a 2d Background Image
  • Choose a 3D HDRI Image
  • Save a Custom View!

SolidWorks 2010:

  • Multi-bodies in Sheet Metal
  • SolidWorks RX – Download Graphic Card Drivers automatically
  • Mouse Gesture Support
  • View Decals in eDrawings and SW w/out PhotoWorks enabled
  • SolidWorks Network Monitor (interesting)

That’s it for the moment. Lots and lots more to come.

How-To