Python API update create statement with assembly

I am using a PythonProcessHandler to update a create statement in the process.
It needs to create different products depending on some input parameter.
I do not want to use long if statements in the UI, as I have many products and new ones are added regularly.

I got to here:

  createStatement = routine.getStatement(4)
  createStatement.ProductType = newType

For assemblies, this creates “full” assembles.
But I need to have a partial assembly, as in the next step, a robot is placing the parts using a GetAssembly-> TransportIn sequence.

I can get the AssemblySteps

  steps = createStatement.AssemblySteps

But this attribute is read-only.
How to set the assembly steps programatically?

You can alternatively set the DefaultProductType of certain slots to none:


That way they will not be there when the assembly is created. Use the filter function to make sure they only take the correct product. Hope this helps.

1 Like

Thanks for the input @cassian35 , but this just creates another problem, that I had send to the VC support.
If I assemble an assembly, it does not get disabled anymore.
So, if I proceed as you propose, I create an assembly with no DefaultProductType at the upper level.
I fill it up with a GetAssembly->TransportIn sequence but then I do not get it disassemblied anymore…

So no, not a working workaround.

Hey @gg-sps!

Disassembly should not be a problem either way.:thinking: But if you contacted VC Support, it’s better to let them figure this out.

My issue with the disassembly of previously assembled units is still not resolved, VC support could at least replicate it - but I finally got the missing code snippet. Hopefully this will be helpful for someone else in the future.
So, to define the included assembly steps in a createStatement:
First, get assembly information:

  productTypeManager = sim.ProcessController.ProductTypeManager 
  newAssemblyType = productTypeManager.findProductType("assembly_name")
  assemblySteps = newAssemblyType.AssemblySteps 

Then apply to the create Statement:

  createStatement = routine.getStatement(4)
  createStatement.ProductType = newType
  createStatement.AssemblySteps = [assemblySteps[0]] #Only first step

1 Like