One of the least explored areas in Inventor is the Custom Task in Inventor's Task Scheduler.
The help wiki is quite brief on the subject and it has always intrigued me because I think the custom task has potential.
A custom task is basically comprised of two elements: an executable program and one parameter.
A typical example would be: Notepad.exe "c:\test\MYTEXT.TXT"
This would automatically open a text file in Notepad via Task Scheduler.
Good for novelists or bookworms but not very useful for mechanical engineers using Inventor.
In the hope of giving you a more meaningful example while demystifying the area, I wanted to create a custom task that would interact on a series of part files (ipt), regardless where they are located on the disk drive.
I thought it would be a fun project to create mass, volume and area custom properties automatically in a series of ipt files. Here is the folder structure of the c:\test folder.
Here is the explanation what each of these files does in folder c:\test:
-
First there is an external iLogic file that creates the custom properties (I called the file Externalrule.txt). These 3 lines of code accomplish this.
iProperties.Value("Custom", "Mass") = iProperties.Mass
iProperties.Value("Custom", "Volume") = iProperties.Volume
iProperties.Value("Custom", "Area") = iProperties.Area
- "Myfiles.csv" is the list of ipt files. In my example I have two files in there but obviously you could put many more in the list.
How you create the list is up to you. You could use the DIR /S DOS command if you like but you need to provide the full filename so that the ipt can be located correctly on disk.
c:\test\part1.ipt
c:\test\part2.ipt
- Then fire up Task Scheduler and define a custom task. For some unknown reason to me the custom task only accepts one argument.
That means that if you want to use both the name of the external rule and the csv file as input , you need to do some special coding.
|
|
|
|
|
As custom task type name you can type anything, I used iLogicCsv.
Check the Application (EXE file) button and browse to the c:\test\Customtask.exe program.
This is a VB.Net exe that does all the work for us. The full source is included (see link at the end of the blog post).
Once you hit OK in above dialog, this brings you back to the initial Custom Task dialog.
Enter as parameters
"c:\test\myfiles.csv" "C:\test\Externalrule.txt"
The first string is the location of the csv list
The second string is the location of the external iLogic rule.
Make sure to put a space between the two strings.
Don't check the Immediately button for now
Enter your password as usual.
Before running the task, make sure that Inventor is up and running.
Voila, the only thing that is left to do is enable and run the task to create the custom properties.
The beauty of the technique is that both the list of ipt files and the content of the iLogic rule are flexible and can vary.
So you could very easily apply a different iLogic rule to a different set of files and schedule the task to run during the weekend or night.
The full set of files can be downloaded from here. I included two 2012 part sample files in the zip file.
I suggest you unzip the file to a c:\test folder so you can follow my instructions without any file path problems.
Have fun. Bob
|