PDM hyperlinks to your clipboard - in plain text!
We thought 2018 was going to be a good year because that was the year SOLIDWORKS gave us the ability to copy a PDM file’s hyperlink to the clipboard. The excitement must have worn off because, even though the “Copy Link” function is still available on a file’s context sensitive menu, no mention of it can be found in the 2020 help file.
The ability to create SOLIDWORKS PDM Pro hyperlinks to files and folders has been around for many years. Hyperlinks are a great tool for opening, finding, viewing, [etc.] documents from external sources. The problem has always been that they hyperlinks are not very easy to create. Before 2018, your only choices were to use the programming interface or build the link through SQL.
The idea with “Copy Link” is that you right-click on a file, click “Copy Link” and that adds the hyperlink to your clipboard. Later, when you paste the link into an HTML aware editor (e.g. MS Office) you’re pasting the name of the file into your document, with the hyperlink properly added. The problem is that you cannot paste the link into non-HTML aware locations. Notepad, your ERP system, database fields -practically everywhere else, the paste function doesn’t work.
I believe most of the time it would be better to have the hyperlink added to the clipboard as plain text. If it’s in plain text I can do anything I want with it. For a long time I was doing this with a PDM add-in. It worked great, but writing add-ins isn’t for everyone. So, this blog post shows how I finally figured out a way to make a PDM data card button copy my hyperlinks to my clipboard for me.
How it works – behind the scenes
[Warning: in this section I do get into some code writing. You don’t really need to know any of this to make it work in your data cards. If you just want to make it work, skip to the next section.]
The trick is to make the data card button run some PowerShell code to copy PDM hyperlinks to your clipboard.
(No I normally don’t use such terrible variable names. But card buttons will only accept 255 characters, so I purposefully made this code as tight as I could.)
- Line two connects the code to the vault. The %2 is the data card parameter for the vault name.
- I admit the third line is a hack, but it is the easiest way I have figured out how to define the folder object required in line four. If you know of a better way, please let me know!
- Notice the %1 in line four. It’s the parameter sent by the data card button for the file’s full path. By reference “GetFileFromPath” also returns the actual folder, overwriting my hack from line three.
- Lines five and six just makes getting the file and folder’s UID for ease in building the hyperlink
- Line seven is where the rubber hits the road, and it writes the string in text format to the clipboard. Depending on the goal of the hyperlink, substitute the word explore for ‘open’, ‘view’, ‘get’, ‘lock’, ‘properties’ or ‘history’.
To take this code and put it into a card button, combine all seven lines into one and separate with semicolons. Then, tell the command button you want to run the code with PowerShell by putting the word “PowerShell.exe” at the beginning of the line and put all of the code inside of double quotes.
Now, let’s put this into action. First, we’ll add a button to your PDM Pro data card. Give the button a clever caption, set the command type to “Command String”, and cut/past the code below into the data card’s “Command” property. Then, you can copy your PDM hyperlinks to your clipboard as often as your heart desires.
powershell.exe "$v=New-Object -COMObject ConisioLib.EdmVault;$v.LoginAuto('%2',0);$fo=$v.RootFolder;$f=$v.GetFileFromPath('%1',[ref]$fo);$fi=$f.id;$foi=$fo.id;Set-Clipboard -Value \"conisio://%2/explore?projectid=$foi&documentid=$fi&objecttype=1\""
The button properties should look like this:
One last point: You need to check-in the file at least once for the hyperlink to be built properly.
Sorry PDM Standard guys, this method uses API so it will not work for you.