By Clint Brown
Those Inventor users familiar with virtual parts, will know that they are extremely useful for adding information to an assembly, that you may not otherwise model (for example grease or glue).
Virtual parts will appear in your model browser, and on your Bill of Materials. While these can be created manually, I thought that I would share a method of creating them on the fly, using iLogic.
I've adapted a bit of code from the Inventor API blog (link in the code below) to work in iLogic and to also run a couple of checks for us before creating the virtual part, the overall process is pretty simple.
The Code below starts by checking that you are in an assembly file. If the rule is run from a part file, you are given a warning, and the rule will exit.
If you are in an assembly, you are prompted for a name, this will be used for the virtual part.
If you specify a name that has already been used to create a virtual part, you are given an error message and the rule will exit.
If the name you specify has not been used before, the iLogic code will create you a new virtual part with that name.
The animated GIF above shows the code in action.
'iLogic code by Clint Brown @ClintCadline, adapted from Inventor API code found here:
'This iLogic code was originally posted on Cadline Community
On Error Goto ClintsErrorTrapper:
'Check that we are in an Assembly
oDoc = ThisDoc.ModelDocument
If oDoc.DocumentType = kPartDocumentObject Then
MessageBox.Show("You must be in an Assembly to run this rule!", "Cadline - Virtual Part creator")
Dim oAssDef As AssemblyComponentDefinition
oAssDef = ODoc.ComponentDefinition
Dim oMatrix As matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
NameOfVirtualPart = InputBox("What would you like to call the new Virtual Part?", "Cadline - Virtual Part creator", "Please specify")
' add one virtual occurrence
Dim oNewOcc As ComponentOccurrence
oNewOcc = oAssDef.Occurrences.AddVirtual(NameOfVirtualPart, oMatrix)
Dim oCVirtualCompDef As VirtualComponentDefinition
oCVirtualCompDef = oNewOcc.Definition
MessageBox.Show("You already have a Virtual part with that name!", "Cadline - Virtual Part creator",MessageBoxButtons.Ok,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1)