Building a Console Application in VB for the Alibre Design API - Looping Through Configurations E-mail
Article Index
Building a Console Application in VB for the Alibre Design API
Getting Started
Create a Visual Basic Project
Referencing the Alibre Design API
Importing Namespaces
Adding Comments
Setting Up Command Line Flags
Reading the Command Line Arguments
Redirecting the Standard Output
Hooking Alibre Design
Looping Through Sessions
Looping Through Configurations
Finishing Up
Resources
All Pages

Looping Through Configurations

Next, if we got the "-conf" flag on the command line (lines 12, 17, 25-27, 62), then we go ahead and loop through all of the configurations associated with the session. In order to do this, though, we need to treat the current session we're examining as an IADDesignSession (line 63). Whereas an IADSession contains all the functionality that are in common about an Alibre Design document, an IADDesignSession is all the things that are in common about a design workspace (part or assembly) -- things like planes, points, tolerances, etc. It's the IADDesignSession that has a set of configurations.

This would be another really good time to tell some friends or associates about this site. If you've gotten this far you're obviously interested, so why not help out a bit by browsing around and spreading the word? =)

Lines 64-68 loop through the configurations, output the configuration name and type, and increment the configuration counter. Then in lines 69-71 we output the count, but only if we had originally received the "-count" flag as a command line argument.

        ' Write out the configurations if required
        If includeConfigurations Then
          Dim ds As IADDesignSession = session
          For Each configuration As IADConfiguration _
              In ds.Configurations
            Call Console.WriteLine("  " & configuration.Name _
              & " (" & configuration.Type.ToString() & ")")
            configCount = configCount + 1
          Next
          If includeCount Then
            Call Console.WriteLine("  Count: " & configCount)
          End If
        End If

One thing I should point out before I get too many emails on this, is that there's more than one way to do almost everything. For example, I could have just as easily gotten the total number of configurations by using "ds.Configurations.Count". That shortcut wouldn't have worked for sessions, though, because in this case we're only counting those sessions that are in a visible GUI.

Next we need to "close" the "If" on line 54 and continue with the "For Each" on line 51.

      End If
    Next



Last Updated ( Monday, 28 January 2008 16:22 )