This program is not written in pure VBA, rather it is a simplified version called iLogic. VBA was used to figure
out the object models within Inventor.
The purpose for the program is to add the Assembly sheet Index and the Bill Of Materials (BOM) item number
to the view label of the part. This is controlled by a form form which the action to be performed is chosen.
The choices are to Add only the First BOM Index, Add All BOM Sheet Indeces,
Remove All Indexes from Labels.
From the Remove Index choice the part view label will be modified to have no index:
Or it will have the choice number of indeces:
The addition here is the (0-0) before everything in the label.
Another part of this program is to add the sheet index of where the part was found to the
BOM SHT# column:
These index values are gathered from the sheet names in the navigation panel.
When the function is called a couple things happen. First the type of documents that is active is checked, this program will only operate on drawing documents. Then the Form is brought into view.
CheckForDrawingDoc is a function that does what it says, it then returns either the document if it is a drawing doc else, an error is displayed and Nothing is returned.
Selecting the action
The first action on the form, Apply First Index utilizes Inventor's User Parameters. These are
basic central stored variables that can be utilized anywhere in the project to set a value.
The first operation is to check that the parameter exists, if it doesn't then it is created. The parameter is then
set to "First". This tells the Part_Index_Populate function what to add to
the label.
The second option in the form Apply All Indeces is very similar. The only difference is it sets the
Index_Action parameter to All.
Populating the index
Once all checks are passed the real action begins.
The setup is, the drawing doc is put into a variable and all existing index labels are removed with
Part_Index_Romove, this is the rule name that contains the function.
Following this is the main operation loop for the function. The first concern is to check each
Sheet for a BOM. If that sheet has a BOM then the index is gathered.
The sheet index is contained in the name of the sheet. So a simple find and grab operation is required to
retrieve it. If there is not an index an error is thrown and the sheet is skipped.
When a BOM and index are located each sheet is then passed into UpdatePartLabel
UpdatePartLabel
Each view on the sheet is then inspected for each PartName listed in BOM. On finding the matching
PartName a few string variables are gathered. The ViewLabelName is the current label that the view
has. All the other variables are used to create the new view label.
IndexType gets the Parameter value that was assigned earlier, this is either All or First.
IsLabelled get true or false from CheckForIndexLabel.
CheckForIndexLabel
In the case that the parameter Index_Action equals First then the view already having an index in the
label will skip the ModifyIndexLabelInView function call.
ModifyIndexLabelInView
Finally the PartSheetIndex is added to the BOM in the SHT# column
Here the Part is an item row in the BOM, so Item(1) is the first column of
the row.
That finishes the populating of the part label. The other option to Remove Index is taken care
of by the Part_Index_Remove Rule.
Part_Index_Remove
The remove function takes the drawing document and loops through all views in each sheet to remove the indeces.
RemoveIndexLabel()
These strings are the same as I added earlier. The Preffix location in the label is found and a label that does not contain the index is stored in IndexRemoved. CheckForIndexLabel is the same as in the populating portion of the program. If CheckForIndexLabel returns true the label is then replace with the IndexRemoved label by the ModifyIndexLabelInView function.
This program required some knowledge of the object model of the BOM and sheet views. There is not much to say about it
as is a simple object modification program.
I can see places it could be optimized, one idea I had tried previously
was to create an array of all the views as a class. These included the sheetName, SheetIndex, and ViewLabel. This idea
did not pan out as storing and passing the array was a problem. After completing it in this simple way and having more
knowledge of the iLogic capabilities I will revisit this method.