Archive for the ‘API’ Category

There’s an object for that

Thursday, March 4th, 2010

When writing custom code for your SolidWorks Enterprise PDM system, have you been tempted to connect directly to the Enterprise database tables? You certainly could. The database isn’t encrypted and when you first start out it is easy to get the information you need with a simple SQL query.

Don’t. There’s an object for that. Everything you need from the database: BOMs, history, users, variables, searches,  … has an associated object in the API.

It may take a little while to learn these new objects, but your code will be more robust and since you never know when SolidWorks may change the database schema, your code will be much more “upward” comparable in the future.

Heart

Check out the EdmUtility constants list in the API help file to give you a taste of some of the objects available to satisfy your little SQL writin’ heart.

Jeff Sweeney

Jeff Sweeney

Engineering Data Specialist
3DVision Technologies

Get BOM Table in an Assembly

Friday, December 11th, 2009

In SolidWorks 2009 they introduced the idea of having a BOM in an assembly file. Cute and sweet, but no balloons? What good is a BOM table if you cannot connect the parts to their line items?

In SolidWorks 2010, they stopped the maddness and gave us the ability to balloon our assemblies. (Hey the best way to speed up creating drawings is not not have to create them!)

Is it just me or shouldn’t the assembly balloons be spheres?! Wouldn’t that look cool?!

Now that we have the BOM table in the assembly, you are asking how to connect to the table with the API. It is a good question, there are many examples to get the BOM object when working in a drawing, they are always connected to a view…but there are no drawing views in assemblies!

You could have the user select the table before your code begins, but this little sample macro file finds the BOM table for you then shows how to read the table by printing the BOM in the immediate window.

Pffft….Come on SolidWorks 2D balloons in a 3D model – hurts my eyes!

Jeff Sweeney

Jeff Sweeney

Engineering Data Specialist
3DVision Technologies

Working with file paths in .NET

Wednesday, October 28th, 2009

Since I do a lot of file manipulations in my custom routines, my programming snippets library is full of little string manipulator functions written for the use of manipulating strings containing file paths.

Today I ran across the “Path” class in the System.IO namespace. Where has this been all my life?! (Well since the 1.1 .Net framework.) Check out this class! GetFileNameWithoutExtension, GetExtension, GetPathRoot, GetDirectoryName, ChangeExtension, etc.

If I had all the time back that I have spent writing my own versions of these methods I’d be 12 years old.

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

Add Hyperlinks to parts in your ECNs

Thursday, August 13th, 2009

I received this rather interesting telegram today from Western Union:

Stardate: 44995.3

I on behalf of the entire Klingon empire wish to thank you for your blog post on Earth date August 13, 2009 where you first posted the idea of including hyperlinks in ECN documents to make it easier for users to quickly find documents without having to even open SolidWorks Enterprise PDM.

You don’t know it yet but the format you used:
conisio://[vault name]/open?projectid=[projectID]&documentid=[documentID]&objecttype=1
is still in use today. In fact, the actual API code you wrote to make it easier for the engineers to automatically create the hyperlinks was used when we designed the Negh’Var-class birds of prey to help crush the rebellion and restore the empire!

Kapla!
Emperor Gowron

Thanks Emperor, what an honor it is to know I will be honored. As I am sure you know, you actually can do a lot of fun things with hyperlinks in your office documents when using Enterprise PDM. Here is a list of all the things you can do with a hyperlink: (replace “open” in my historical-to-be hyperlink with the proper command)
open– Opens the file in associated application
view– Opens the configured “Viewer” application for the file
explore– Opens an explorer window in the folder the file resides and selects the file
get– Triggers a Get of the file to the local file vault view
lock– Checks out the file
properties– Brings up the file properties
history– Brings up the file history

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

More logic in control logic

Thursday, November 20th, 2008

The control logic in Enterprise’s datacards can only include logic based on file’s variables. Weak. Life is more than just variables isn’t it?

The admin training manual shows a nice little trick of how you can control what people see on a datacard using tabs. You can control which tab is visible depending on a few factors…but even that is limited and tragically you can only show one tab at a time.

So here was my recent real world problem. Imagine having a card containing several edit boxes. Each edit box can only be modified by a certain corresponding user group….if a user is a member of more than one group, he needs access to the proper set of controls -users could be members of any combination of groups.

!!!!

Here was my solution:

  1. On the card, I created a checkbox for each group
  2. I set the control logic on these checkboxes so they would always be invisible. [Something like if the description contains the letter "A" or does not contain the letter "A" turn off the visibility. Even though they are invisible, you do want these to look rather neat because they can still be seen if being used as a search card.]
  3. I set the control logic on the edit boxes I ultimately wanted to manage to look at the proper corresponding checkbox created in step 1.  i.e if the checkbox was checked, enable; else disable.
    Control Logic Example(Click on thumbnail to enlarge)
  4. I wrote an Enterprise add-in that fires anytime a file is checked out. This addin ensures only the proper checkboxes are checked. (i.e. if he is member of the group, check the checkbox, else clear it.)

Setting the proper checkboxes automatically enables the proper edit boxes. That’s it. Four easy steps. You owe me a turkey sandwich pizza.

(There is no reason to bother clearing the checkboxes at checkin, they are always correctly set when a user again checks out the file, and when the file is checked in all controls are disabled anyway.)

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

GetVar vs GetVarFromDB – the rematch

Wednesday, September 24th, 2008

In a previous post, I spent a lot of time bashing my new friend, the Enterprise PDM function “GetVar”. The help file skims over the differences between “GetVar” and “GetVarFromDB”. So I thought it may be helpful to the world if I list them here.

[This would be so much easier to read in a table; but using this WordPress is like writing a novel with a crayon -not the skinny ones, the big fat ones that come eight in a box.]

If the file is checked out:
GetVar – retrieves the value the checked out person sees in his datacard
GetVarFromDB – retrieves the value from the version back in the vault

If the file is checked in:
GetVar – whines and cries like a baby and won’t work
GetVarFromDB – retrieves the value from the latest version in the vault

***
One other problem I have found with the help file. . .

Several times you’ll see an example that looks like this:
varEnum.GetVar("comment", "", value)
I’ve been told by API support that passing an empty string for the configuration is not proper etiquette. While it is true that it still works, there is an SPR out that may soon prevent this from working. The code for getting the part level variable should look like this:
varEnum.GetVar("comment", "@", value)

Keep an eye on this one when upgrading.

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

SolidWorks Add-ins – ain’t no big thang

Monday, September 15th, 2008

Normally when you think of SolidWorks add-ins you think of COSMOS, DriveWorks, CAM programs, …big programs. Don’t be intimated by these traditional add-ins. You can write small, very handy add-ins yourself -they can have a very fast return on investment!

I am seeing more and more companies with their own little add-ins. Most commonly these add-ins are just small little routines that check company standards on files before they get saved. [FileSaveNotify] An add-in like this is a lot more useful than a macro because your users can’t “accidentally” forget to run them -it will be run every time the file is saved!

  • Check to ensure all parts have the proper file properties defined
  • Check all purchased parts to ensure they have valid part numbers (via connecting to their ERP)
  • Check all drawing entities to ensure they are on the proper layer
  • Check to ensure the BOM is present and in the proper format

What little things do you find yourself having to go back fix after you’ve release your assemblies for production? Perhaps an add-in is the answer?

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

I like to keep hitting my head against the wall

Tuesday, September 2nd, 2008

You know the old joke: “I like to keep hitting my head against the wall because it feels so good when I stop.”?

I think I figured out why I like programming.

First, will all of you SolidWorks Enterprise PDM admins join me in protest of the function “IEdmEnumeratorVariable8:GetVar”? Why do I have to have write permissions of the file just to read the variable?! …but more on that later.

I just wrote a cute little routine that checks out a file, does some file manipulation, then checks the file back in. Easy and sweet. Worked great when I tested it on its own but I was getting many problems when I included it into my add-in.

Hours go by. Testing it outside works, testing it in the intended environment [within an add-in] no work-ie.

Any guesses? It is an obvious answer once you hear it.

Yeah, My add-in also did some small variable checks when the file got checked out [EdmCmd_PostLock] -these checks used the soon to be boycotted “GetVar” function. Thus my original routine was checking out the file, which was then calling the checkout hooks which were trying to checkout the file. Two separate routines trying to get write access to the same file. You don’t need to be an Engineering Data Specialist to know that is a bad thing.

Chant with me: “No more GetVar! With GetVar you won’t go far! No more GetVar”!

Please excuse me while I leave to get some ice for the bump on my head.

(Once I found the problem, the fix was easy. I had several options. I chose to change GetVar to GetVarFromDb.)

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

SolidWorks Enterprise PDM number assigner

Thursday, August 7th, 2008

It appears the folks at SolidWorks heard my gripe about their naming convention. Though the name couldn’t be much longer.

SolidWorks’ virtual components are so, so sweet. The fact that SolidWorks Enterprise PDM supports them adds just a bit more butter on top of the piece of toast. …but…what if you need to assign a virtual component a part number before you save it out as its own file? You cannot use SolidWorks Enterprise PDM’s serial number generator because you have no way to get the number nor tell the generator you manually assigned a number.

Here is a nice little SolidWorks macro to get you started. It simply finds the next available serial number and returns it to the user in a message box. The user can use this assigned number in anyway he chooses.

[You'll need to replace "Trains" with your vault name and "PartNumber" with the name of your serial number.]

'remember to add PDMWE Type Lib as a reference!
Sub main()
Dim objVault As IEdmVault8
Dim objSerNoGenerator As IEdmSerNoGen6
Set objVault = New EdmVault5
objVault.LoginAuto "Trains", 0 'use name of your vault
Set objSerNoGenerator = objVault
strNewNumber = objSerNoGenerator.GenerateSerNo(_
"PartNumber", 0, "", 0, 0, 0, 0)
MsgBox "The next avaliable part number is: " _
& strNewNumber
Set objSerNoGenerator = Nothing
Set objVault = Nothing
End Sub

Anytime you need the next avaliable serial number this could be used. i.e. files added via Pack and Go, drag and drop…

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

Extracting PDMWorks Enterprise BOM

Friday, August 1st, 2008

PDMWorks Enterprise 2008 introduced a new ability to automatically export your BOMs during transitions in your work flow. To date though I had not found any example code of how to extract the information from the XML file once it was created.

Luckily, I caught my buddy Philip Stears deep down in his dark lab writing this little diddy.

'Create the document object ready

Dim document As New XmlDocument()
Try
'Load the document from disk
document.Load("WorldDominationPlan.xml")
' Get hold of the root element in the XML file
Dim rootElement As XmlElement = document.DocumentElement
' Go through each element in it called "Property"
For Each childElement As XmlElement In _
rootElement.GetElementsByTagName("Property")
' Get the name and value attributes
Dim name As String = childElement.GetAttribute("Name")
Dim value As String = childElement.GetAttribute("Value")
'Do something clever with them
TakeOverTheWorld(name, value)
Next
Catch ex As Exception
' Foiled again, try again tomorrow
Foiled(ex)
End Try

He was in process of writing the “TakeOverTheWorld” subroutine, luckily I caught Philip just in time. Engineering Data Specialist Man saves the day again!

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies