Inventor 2017 - iLogic - Create Virtual Parts on the Fly

Zen Admin
Zen Admin

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.


Sub Main()
'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")
End If

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
Exit Sub

MessageBox.Show("You already have a Virtual part with that name!", "Cadline - Virtual Part creator",MessageBoxButtons.Ok,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1)
End Sub


Was this article helpful?

1 out of 1 found this helpful

Have more questions? Submit a request



  • Comment author
    Jared Judd

    Is it possible to also set iproperties of that virtual component within the same ilogic rule?

  • Comment author
    Zen Admin

    Hi Jared

    Great question. I'm working on a new blog post about this, but in while we wait for it to be finalised, I have created a video which you can watch here.

    The 3 iLogic rules in the video are available here: One, Two, Three.

    I'll delete this info and replace it with a link to my new blog once updated.

  • Comment author
    Jared Judd


    Thank you for the response. I am very inexperienced with iLogic rules but you've certainly helped. I will definitely be able to utilize this new info as well.


Please sign in to leave a comment.