Archive for the ‘API’ Category

|||| || ||| |||||

Thursday, July 8th, 2010

What do you think of our “paperless” society so far? Way to go prognosticators, got your jet packs all tangled up on that one.

Though SolidWorks’ DimXpert is really cool and I know some companies are adopting it, most companies are still creating and printing drawings.

If you can’t talk management into adopting the new, cool technologies, think you could talk them into using 1949 technology – the barcode?

They are actually very easy to use – they can be added by using nothing more than a special TrueType font on your drawing -many can be downloaded for free.

Add your note to your drawing, change the font to barcode and….

BarCode….now a barcode reader can read your note! (As long as you don’t use the new “Fit Text” property. Character spacing is important.)

What can you do with it you ask? Add this barcode to your drawing sheet format, link it to a custom file property – perhaps file name, PDM unique id, part number, etc. and your barcode will update as the properties update.

Now everyone down stream can quickly access information about your drawings.

There are a lot of inexpensive bar USB code readers that behave just like a computer keyboard. (They even use keyboard drivers.) When the reader sees the barcode, it simply inputs the value into your computer as if it came from your keyboard.

Simplest example, imagine the barcode is the file name, the user opens up a search window puts the cursor in the file name field, scans the barcode and the search starts…no typing!

I’ve written simple applications that simply watched for keyboard input, when it saw the barcode the routine searched for the file in the database and marked that file as arrived at that work station.

Think of all the locations barcodes could be used. Stockrooms, purchasing, manufacturing, shipping…just a very quick way for your users to input data into your system.

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

Enumerations to save the world!

Tuesday, May 18th, 2010

Enumerations are great little tools designed to make working with your API code easier. In SolidWorks API, enumerations are often used to collect constants together in groups.

As an example, this line of code is perfectly acceptable:

swFeature.GetType = swSelBODYFEATURES

However if later you want to change the type of feature you are looking for you have to look up all of the constants “GetType” returns. This can take some time.

If you use enumerations, VBA’s IntelliSense provides you with a droplist to make selecting the proper constant name easier. Type the enumeration name, the period then…

droplist

Thus I am recommending the above code should have been written like this:

swFeature.GetType = swSelectType_e.swSelBODYFEATURES

It’s the same thing, just easier to work with. (Enumeration names can be found in the help file.)

ReturnValue

Once last super cool enumeration tip. Declare your variables using enumerations.

Continuing the above example, say you want to store the type of feature you found in a variable. If an enumeration is available, don’t simply declare the variable as a generic type, use the enumeration instead.

Dim intFeatureType As swSelectType_e

Now whenever you work with this variable, IntelliSense is there to help you along the way. Hit the equal sign and…

if
Better, faster, easier to read, more accurate code.

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

EZ Enterprise Dashboard Graphs

Friday, April 23rd, 2010

Everyone loves dashboard graphs – especially managers. Imagine going to management Monday telling them you can provide them real time graphs -showing them the status of anything you are storing in SolidWorks Enterprise PDM…all for free.

Yeah, I see a big raise in your future…maybe even a trip to the tropics as a bonus. Don’t forget the Engineering Data Specialist Man helped get you there!

/* WARNING: This blog contains SQL & VBA programming. Readership discretion is advised.  However, I promise there is not a lot…I’ll step you through. Once you see how easy and powerful these are you’ll know they are worth it. /*

In this example, let’s imagine you would like to be able to have your manager double click on a desktop icon and have a graph display showing all of the engineering change notices that have been created on a month by month basis.

First thing (and perhaps the most challenging) you’ll need to do is come up with a SQL statement to retrieve the information you’ll need:

SELECT COUNT(Documents.Filename) AS NumberofECNs,cast(month(VariableValue.ValueDate) as varchar(2)) + ‘/’ + cast(year(VariableValue.ValueDate) as varchar(4)) as ‘Month’
FROM Projects INNER JOIN
DocumentsInProjects ON Projects.ProjectID = DocumentsInProjects.ProjectID INNER JOIN
Documents ON DocumentsInProjects.DocumentID = Documents.DocumentID INNER JOIN
VariableValue ON Documents.DocumentID = VariableValue.DocumentID INNER JOIN
Variable ON VariableValue.VariableID = Variable.VariableID
WHERE     (Projects.Path = ‘\ECNs\’) AND (DocumentsInProjects.Deleted = 0) AND (Variable.VariableName = N’Date’)
GROUP BY month(VariableValue.ValueDate),year(VariableValue.ValueDate)

Teaching you SQL is quite a bit beyond the scope of this blog entry. If you have a SQL statement in mind that you need help with, there are tons of people who can help you in the SolidWorks forums or certainly your VAR can help. Besides this isn’t the cool part yet.

In short, the above SQL statement counts all files in the \ECNs\ directory and groups them by month as defined in the “Date” variable. Thus a typical output may look like this:

NumberofECNs Month
500 12/2009
250 1/2010
375 2/2010
507 3/2010
423 4/2010

Certainly we could take this output, paste it into an Excel sheet with a pre-made graph…but can you imagine someone in management being able to do all of these steps? Instead, make a spreadsheet that will automatically update itself every time it is opened. This way you can be assured you are looking at data as fresh as the moment the file was opened.

ECNs

This Excel file does exactly this. As soon as your user opens the file [via Sub Workbook_Open], it connects to your Enterprise database, counts all of the ECN files via a SQL query, and puts this information into the spreadsheet. The graph is set to automatically scale, so there is nothing left to do except sip on the margaritas.

I’ve added tons of comments in the Excel VBA code. Look in the “This Workbook” module to find it. [The first time you open the file, you will get a VBA crash message, because the routine is trying to connect to my vault, you'll need to modify the code's connection string to connect to your vault for it to work properly.]

This was an easy, free solution. Because all of your data is stored in SQL, the sky is the limit for the amount of reporting you can do. I’ve seen pie charts showing how many ECNs were created by each user, then if you pick on a pie piece all of the ECNs created by that user appears in a chart -with hyperlinks to the actual ECN – using Internet Explorer as the interface. Cool, cool, cool.

If you want to get into some of these fancy charts,  read up on “Business Intelligence” built into SQL Server….or stay tuned here, I’ll probably blog about it someday.

Jeff Sweeney

Jeff Sweeney
Engineering Data Specialist
3DVision Technologies

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” compatible 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