Beginner PDM API Direction?

Hi all,

I want to use the PDM API to populate job folders with the latest revisions of drawings. I have learned some programming in the past, but I’m kind of blank on how to get going here…
Let me explain where I am and where I am trying to get, and then I’ll ask if this is the right tool to get there and, if so, what language I should pick up to do it.

  • I have never used an API before, but I understand what it does.
  • I learned BASIC on a Tandy HD1000 about 25 years ago and I studied MATLAB in engineering school (and I did quite well at it).

When we get a job, a folder will be created for it on our project files network drive. This is where we will put the sales order, purchasing records, CMTRs, etc, as well as all the manufacturing documents to get material and build the machine. Part of my department’s job is to add all the drawings to that directory. Our current method is to print a BOM from our ERP system and go down the list marking off each drawing as we grab it and drag it over to the folder. This can be more than 400 drawings. Of course, there is not a handy search that will bring up most of the drawings, and some parts are used more than one place, so they’re not all in the same folder.

I used Microsoft Power Automate to put together a script that would accept a list of part numbers, get the most recently created PDF with that name, check to make sure it was released (by reading the watermark on the PDF), then add the drawing to an output folder or add the number to a list of missing drawings which we could then go through and revise or grab the previous rev, etc…
The issue I had with that is that I needed to get latest version on every PDF I wanted it to check, which meant ALL of our released drawings. Last I checked, that folder was somewhere around 17 kilofiles.

I used Octave (open-source MATLAB) to recreate the script, but I could never get it to read in the vault. I could copy a selection of PDFs to my local drive and it worked fine, but no joy in the vault.

It seems to me that with the API, I could get the BOM for a top level model, get the workflow state for each drawing, get the current revision, and grab the drawing or make a list of everything that needed to be revised, and it would be done in a few seconds rather than a few hours…
Since some of the drawings that need to be added are not captured in the model (schematics), maybe I could find a standardized way to export the BOM from ERP and feed that to the script instead.

Are you wanting to copy PDF files from inside the PDM vault to a location outside the vault? Yes, you can do this with the API. If you have a BOM exported from your ERP, you can certainly use that information to get the current revision of a PDF (or the same revision that the ERP BOM specifies) and copy it to a location outside the vault.

You can do this from a standalone application, a button on a data card, a custom SOLIDWORKS or File Explorer menu item, or do it automatically as the result of a state change.

You can use VB.NET, C# or C++/CLI. VBA is also an option, but technically it is not supported. My preference is C#, mainly because I have programmed in Java since 1996 and C# is very similar. I find VBA/VB.NET clunky and not intuitive.

Unless you decide to use VBA, you will need to have Visual Studio Professional installed at a minimum. If your company is large enough to have an ERP system, you most likely cannot use the free Visual Studio Code due to its licensing restrictions.

Ultimately, yes. But I would still consider it a win if I could assemble all the PDFs in one folder and copy that manually.

Does that mean that the zero cost option is _only_ VBA? Surely I can just write C# in notepad, right? … Unfortunately, my manager thinks the amount of time it takes us is just fine, so I’m not going to get very much company support on this one.

It’s probably possible to use MSBuild, which is free, but I’ve never done it and the universe of people who have (if they exist) is probably pretty small, so you would be a pioneer. I made a small error in my original reply. The ‘free’ IDE is Visual Studio Community, not VS Code. You can use community if you hve less than 5 developers and less than 1 million dollars in revenue, or if you want to roll the dice and hope Microsoft doesn’t notice. VS Code is a step below Community. It is mostly a code editor, but it can be connected to MSBuild and be used to develop COM aware stuff (which all of the SW/PDM API use). Again you would be pioneering.

If you’re stuck with free, VBA is probably your best option. It’s not a terrible option. You can look at VB.NET examples in the API help and the VBA will be very similar. I’ve certainly done quick tests with it. You will lose some flexibility because you will be stuck having to run it from a SOLIDWORKS (or MS Office) macro.

There are plenty of people here who can help if you get stuck.

1 Like

Thank you for mentioning GNU Octave. I will have to take it for a spin.

2 Likes

Yeah, it’s been pretty great for most things I do. They attempt to be compliant with MATLAB, but much like open office, it _is_ a different program. Some functions don’t exist or function a little differently. Certainly less polished than MATLAB is, but then again, I haven’t used MATLAB since maybe 2015

1 Like

Possible option:

robocopy can take a list of file names, search a directory, and then copy the found file to new location. An option to make a report afterwards to see results.

  1. Get an excel list of your file names from ERP system
  2. Send the file names to robocopy
  3. Check the report for any issues.

Possible macro start:

That’s a good thought, and thanks for thinking about it, but that’s where I started :confused:

The PDFs are named “123456_REV_A.pdf” where rev N-A comes immediately before A and 123456 could be MP052 or BPS05 or 128053 or one of the two random seven digit part numbers that are used in about half of our product line. All of the PDFs that have ever existed are stored in one folder.

That’s why I started with the most recently created PDF and checked for a watermark indicating it was not currently released. I am imagining with the API I can get the current workflow and revision of each file instead of faffing around with creation date and reading pdfs.

Like I say, this is a very slow start—It’s actually been about a year since I started working on this; just taking bits and pieces of time as I find them until I know what I’m doing and can find a good block to put everything together.

FYI: Once you get above 1000 files or so in a folder, Windows Explorer and therefore PDM browsing start to suffer. If you can carve that up into folders that make sense, it’s a good idea.

Luckily, here we use dumb 6 digit part numbers that always start with ‘4’, so I have organized everything in folders named ‘4[digit][digit]xxx’ (e.g. 401xxx) so that there can never be more than 2000 files in a folder (model + drawing) and in reality its always less than 2000 because out purchased parts don’t get drawings.

Yes. That is trivial stuff in the PDM API.

1 Like

@toomdog did you make anything for this yet?

Have some vba code that takes a list of file names and returns the drawing file revision via epdmfile.CurrentRevision

Example of output:

Num of Files to Find = 2

File to Find (0) = abcdef
File to Find (1) = ghijkl
Logged into Vault!

abcdef
REV =
B

ghijkl
REV =
C

I use VS community for my plugins (c#), however the new company I’m at has this Threat Locker stuff that makes compiling new projects a hassle. I’ve since switched to LinqPad. It is free, or there’s a premium version with intellisense which is not very expensive at all. If all you need is a console app you should check it out.

1 Like

No, unfortunately this is very back burner for the boss :person_shrugging:
I am confident this would be a very trivial thing to build but I just don’t have the knowledge for where to start.

Not 100% on how your system is setup. You can see if the attached helps. Enter the regular part # (123456) from the ERP system. It should output to the immediate window “123456_REV_A”.

I’m assuming the drawing is titled 123456.SLDDRW

Fill in your vault name too.

PDM DebugP Part Drw Revision V1.swp (102.5 KB)

Thank you! I’ll check this out when I get some time to poke around someday :slight_smile: