How to access vcProduct objects within a simulation

Hi guys, I am working on creating a Python script to track and print all the current products in the 3D world.

I have checked through the help file, and I have not been able to find a way to access the vcProduct objects that exist in a 3D world.

However, I was able to access the vcProductType objects through the ProductType manager, for example as shown below:

process_controller = getSimulation().ProcessController
product_type_manager = process_controller.ProductTypeManager

product_type = product_type_manager.findProductType(‘Product_Type_Name’)

can anybody explain how I can access the vcProduct objects that exist within the simulation at a particular instance of time?

If you want to get a list of ProductTypes:

product_type_list = product_type_manager.ProductTypes

and their names
for i in product_type_list:
print i.Name

1 Like

Hi, Thank you for your reply. I can already access the vcProductType objects. And i can already print the list of the product types in my simulation.

What i want to access is the vcProduct object it self, and with this i want to be able to print out all the Product instances that are present in the simulation 3D world at any instance of time.

But, uptill now, i did not find a way to access the vcProduct objects.

Something like this :thinking:

from vcScript import *

app = getApplication()

def on_render_event(sim):
  comps = app.Components
  for comp in comps:
    if comp.Product:
      prod = comp.Product
      print ("Product of type {} leaving from {}. Current SimTime -> {}".format(prod.ProductType.Name, prod.LastEnteredNode.Component.Name, sim.SimTime))

app.OnRender = on_render_event
2 Likes

Hi,

I was able to edit this code to fit my needs. It was really helpful.

Thanks and kind regards.