Is It Possible To Batch Run A Single Add-In On Multiple Assembly Models?

Is It Possible To Batch Run A Single Add-In On Multiple Assembly Models?

vfantiniSE63W
Contributor Contributor
960 Views
3 Replies
Message 1 of 4

Is It Possible To Batch Run A Single Add-In On Multiple Assembly Models?

vfantiniSE63W
Contributor
Contributor

Greetings everyone,

 

I've got an interesting problem that I couldn't find any useful information on via Google searches, so I figured I'd pose it to you guys.  Is it possible to run an Inventor Add-In and have it execute on multiple .IAM files at once?

 

Here's some more details - I've got a large library of wooden crate assembly models that my company uses for shipping our products to their job sites.  I've recently developed an Add-In that, when executed on a single crate assembly model (that's actively open in Inventor, of course), will scan the assembly model for any components that have a custom user parameter named "lumber_cost".  It then tallies up all of the lumber_cost values of every lumber component and stores the total in an auto-generated user parameter named "total_lumber_cost".  It then takes the value of total_lumber_cost and stores it in the crate assembly model's Estimated Cost iProperty so that it can be referenced from Windows Explorer.

 

This Add-In works like a charm, but again I've got a large library of these crate assembly models to go through if I want every crate model to have its lumber cost stored in its Estimated Cost iProperty.  Opening each crate model and running this Add-In would take quite a long time to do.

 

Is it possible to perhaps develop a variant of this single crate lumber cost calculator Add-In so that it can be directed to a directory of crate assembly models and go through the following steps:

  1. Open the first crate model in the directory.
  2. Scan & tally up its total_lumber_cost value.
  3. Assign the total_lumber_cost value to its Estimated Cost iProperty.
  4. Save & close the currently opened crate model.
  5. Open up the next crate model in the directory and repeat this process from Step 1, etc.

Any pointers on whether or not this kind of automation is even possible would be greatly appreciated!  Thanks in advance for your help!

 

- Sincerely,

Vince

0 Likes
Accepted solutions (1)
961 Views
3 Replies
Replies (3)
Message 2 of 4

matt_jlt
Collaborator
Collaborator
Accepted solution

Hi Vince, it is possible. You have pretty much outlined the steps required. As long as there is some way of identifying the top level assemblies from the rest then it shouldn't be a problem.

 

* Provide the directory, you can use the built FolderBrowserDialog for selection.

* Get a list of all the assembly files, and add extra filtering if required (excerpt below from ms online), there's a bunch of different methods you can do this. Google can help you here.

 

Dim fi As List(Of FileInfo) = New List(Of FileInfo)
For Each File In FileLocation.GetFiles()
    If (File IsNot Nothing) Then
        If (Path.GetExtension(File.ToString.ToLower) = ".iam") Then
            If (File.ToString.ToLower.Contains("data")) Then fi.Add(File)
        End If
    End If
Next

 

* Once you have your list of files, you can then iterate through the list and open each one up and run your code

 

' You can switch the document visibility on / off by switching the False to True etc.
Dim oDoc As AssemblyDocument = ThisApplication.Documents.Open("Filename Here",False)

* Now you have the document open, you can run your existing code on it.

* Once it has finished just save all and close the currently open document and loop through to the next document.

 

As your running make sure you add some checks to make sure things are going as planned, check that all of the documents have closed correctly etc.

 

Regards, Matt.

 

Message 3 of 4

vfantiniSE63W
Contributor
Contributor

Thanks, Matt!  Unfortunately, I've had to switch off of this programming endeavor for now and take care of another project.  But once I finish I'll give your suggestion a whirl and will let you know how it goes.  🙂

 

- Vinny

0 Likes
Message 4 of 4

vfantiniSE63W
Contributor
Contributor

I've finally finished my add-in, and your suggestion helped me get to the solution that I needed!  Thanks so much, Matt!

0 Likes