• Blog posts


    by Luke Davenport

    Hi comrades,


    Virtual parts in Inventor – they're very useful in cases where you don't need the actual geometry of a part (for clearance, fits, etc.), but you need the correct quantity and properties of a part in the BOM or parts list. A common application would be adding consumables (Loctite, grease) to your parts list, or even fasteners, as bolts and nuts in large quantities can certainly weigh down your assembly.


    Getting the quantity of these bolts to update automatically if the size of the model changes is a perfect application for iLogic. I've produced a simple iLogic rule that does the following:


    Note: when copying and pasting this code into an iLogic rule, make sure you don't copy the explanation text!


    1)      Uses a single line of code at the top to calculate the number of virtual parts required. In this case I've got a parameter called 'Length' in my assembly file


        ' Calculate required number of virtual parts

        ' (In this case I want a screw placed every 100mm)

        QTY = Floor(CDbl(Length)/100)


    2)  Then makes a collection of the current virtual parts in the assembly file.


        Dim asmDoc As AssemblyDocument

        asmDoc = ThisDoc.ModelDocument


        Dim oOccs As ComponentOccurrences

        oOccs = asmDoc.ComponentDefinition.Occurrences


        ' Create collection to hold virtual parts

        Dim oVPs As ObjectCollection

        oVPs = ThisApplication.TransientObjects.CreateObjectCollection


        ' Add to collection of virtual parts

        For Each oOcc As ComponentOccurrence In oOccs

            If TypeOf oOcc.Definition Is VirtualComponentDefinition Then


            End If



    3)  Then adds or removes virtual parts as required. Note you will need to insert the properties you'd like your virtual part to have in the code below (unless you'd like it to be called 'Cadline Self Tapping Screw' J


        Dim identity As Matrix = ThisApplication.TransientGeometry.CreateMatrix


        Dim virtOcc As ComponentOccurrence

        If oVPs.Count > 0 Then

            virtocc = oVPs.Item(1)


            virtOcc = oOccs.AddVirtual("CADLINE SELF TAPPING SCREW - SIZE 1", identity)

            ' Set properties of virtual part

            iProperties.Value(virtOcc.Name, "Project", "Part Number") = "INSERT PART NUMBER HERE"

            iProperties.Value(virtOcc.Name, "Project", "Description") = "INSERT DESCRIPTION HERE"

            iProperties.Value(virtOcc.Name, "Project", "Stock Number") = "INSERT STOCK NUMBER HERE"


        End If


        ' Compare actual to required

        If QTY > oVPs.Count Then ' Add more virtual parts

            For aaa = 1 To QTY - oVPs.Count

                Call oOccs.AddByComponentDefinition(virtOcc.Definition, identity)


        Else If QTY < oVPs.Count ' Remove virtual parts

            RemoveQTY = oVPs.Count - QTY

            For bbb = oVPs.Count To QTY + 1 Step -1



        End If


    4)      And that's it. If you set this iLogic rule to run automatically whenever your controlling parameter changes (or upon a document save operation) you'll be all set up, and the virtual part quantity should always be correct.



    a)      Remember you can use ANY number in your model to control the number of virtual parts, as required. Think outside the box.

    b)      You may want to put a few lines at the top of the rule to check that the current document is an assembly document, as you can't add virtual parts to a part or drawing file! Something like this….


    'check this file is an assembly

    Checkdoc = ThisDoc.ModelDocument

    If Checkdoc.DocumentType = kPartDocumentObject Then

    MessageBox.Show("This rule can only be run in an assembly file!", "Cadline iLogic")


    End If