Feeder reading external data files

Hi guys,

I was wondering if there is anyway that a feeder can read external files with variables for the dimensions of the components that is feeding ?
For example if I have 100 variables for Length, Width, Hight, in a external file is there a Python Script that I need to use for the feeder.
Thanks in advance

Hi ,
You can open file with standard python functions open() or csv to read a file if you have access to modelling tab.
Then you can manipulate your data according to your needs. Check the advanced feeder script which can create batch from a file .

If you wait long enough, we’ll get with the next update access to the new Process features, which handles Products.

But you can still do it with the old methods/functions.
Here an example I made today:

import io
import csv
import random
from vcScript import *

def get_root():
  Return the RootFeature of the current component.
  return getComponent().RootFeature

def get_random_material():
  Return a random material
  return random.choice(

def get_block(name):
  Get a feature block by name
  return getComponent().findFeature(name)
def create_block(name):
  Create a new block with the given name and return the block
  root = get_root()
  return root.createFeature(VC_BLOCK, name)
def edit_block(name, height, length, width, material=None):
  Edit the block. If the block does not exits, it will be
  created and then the properties are set.
  root = get_root()
  if material is None:
    material = get_random_material()
  block = get_block(name)
  if not block:
    block = create_block(name)
  block.Height = str(height)
  block.Length = str(length)
  block.Width = str(width)
  block.Material = material

def create_properties():
  Create the missing properties in the component.
  comp = getComponent()
  size_props = ("Height", "Length", "Width")
  for prop_name in size_props:
    prop = comp.getProperty(prop_name)
    if not prop:
      comp.createProperty(VC_REAL, prop_name)
  material_list = comp.getProperty("ProductMaterial")
  if not material_list:
    material_list = getApplication().Materials
    # Usually VC_ constants are used for the first argument
    # In this case it must be a str. "Ref<Material>"
    # is a List with all available Materials
    comp.createProperty("Ref<Material>", "ProductMaterial")
  csv_file_uri = comp.getProperty("CSV Data")
  if not csv_file_uri:
    comp.createProperty(VC_URI, "CSV Data")

def get_sizes():
  Returns Height, Length and Width
  from properties
  comp = getComponent()
  h = comp.getProperty("Height").Value
  l = comp.getProperty("Length").Value
  w = comp.getProperty("Width").Value
  return h, l, w
def get_selected_material():
  Return material from DropDownList of Materials
  material = getComponent().getProperty("ProductMaterial")
  if not material or not material.Value:
    return get_random_material()
    return material.Value

def from_csv():
  Read Data from a custom csv file
  A URI Property is used, to select the csv file to process
  Return a random row from the csv file
  where the fields are converted to floats
    height, length, width
  uri = getComponent().getProperty("CSV Data").Value
  path = uri.replace("file:///", "")
  with io.open(path, "rt", encoding="utf8") as fd:
    reader = csv.reader(fd)
    row = random.choice(list(reader))
  return tuple(map(float, row))
def OnSignal(signal):

def OnRun():
  # Create missing properties
  # Example to change the Feature Block during runtime
  while True:
      # reading from csv and converting can
      # throw an exception
      h, w, l = from_csv()
      mat = None
    except Exception as e:
      # got no data from csv
      # getting data from the properties
      h, l, w = get_sizes()
      mat = get_selected_material()
    # set the propierties
    edit_block("simple block", h, l, w, mat)

Example data of csv:


The code is in the component itself. It should be changed to fit to your requirements.
For example you may not need the attached properties to the Component.
Or you can extend the csv function to get a name, material or other settings.

1 Like

Thank you for the fast answer, I will try this as soon as possible.

I was able to read from the csv file and generate different kind of parts depending on the data I entered in the CSV. Thanks again for the fast answer! I’m wondering how I can make the parts origin from the feeder to be aligned or moved so that it continues moving through the conveyor, but on his upper side. I’m trying to figure out how .MovementOrigin works but for now with no success

Annotation 2020-04-08 091139|690x355

This is how it appears right now (in the middle)
Any suggestions ?

Thanks in advance.