Script to automatically clone existing feeder but change X Y locations for each clone?

47 views
Skip to first unread message

Fern528

unread,
Dec 3, 2025, 8:33:41 PM (9 days ago) Dec 3
to OpenPnP
current manual workflow to setup a new part type:
1. add a AdvancedLoosePartFeeder 
2. jog to start desired XY position of the part supply tray
3. configure the AdvancedLoosePartFeeder locations and vision feed pipeline after training pipeline. 
4. go into the machine.xml and copy the feeder block of code for the AdvancedLoosePartFeeder I just made. 
5. on a separate file I paste the feeder code 192 times and change the XY values to cover the entire supply tray that's 120 x 320 mm. 

My field of view is only 20 mm x 10 mm, and I am picking tiny loose SMD components. Yes I know I can change my field of view by repositioning my camera but that's a lot of re-configuring of everything the camera position affects. 

Started reading into scripting then used chatgpt to help me try to automate this. Was able to add a new AdvancedLoosePartFeeder. Then error after error with code chatgpt tried making. poor chat good try. Conclusion was scripting can't set the feeder x y settings or the vision pipeline settings? Can it? if so how?!?!? 

I was able to make a script to enable all the 192 feeders to start a new board, that was a win!!! Scripting is great!

Any help is appreciated and suggestions are welcome. 

I attached the machine.xml for reference. 

script code chatgpt made:

var AdvancedLoosePartFeeder = Java.type("org.openpnp.machine.reference.feeder.AdvancedLoosePartFeeder");

// Step 1: create feeder
var f = new AdvancedLoosePartFeeder();

// Step 2: give it a name
f.setName("Feeder_Test");

// Step 3: add to machine
machine.addFeeder(f);



Thanks,
Fernando 

machine.xml

Fern528

unread,
Dec 5, 2025, 10:18:38 PM (7 days ago) Dec 5
to OpenPnP
Since no one responded here is the preliminary working code to automatically add a AdvancedLoosePartFeeder. Still needs to be made more robust going to add user input prompts for the part id drop down list, feeder name, how many feeders, locations etc.

Huge thanks to my coworker who is a coding whiz!

.js script code:

var AdvancedLoosePartFeeder = Java.type("org.openpnp.machine.reference.feeder.AdvancedLoosePartFeeder");
var Location = Java.type("org.openpnp.model.Location");
var LengthUnit = Java.type("org.openpnp.model.LengthUnit");
var Part = Java.type("org.openpnp.model.Part");

                               
var f = new AdvancedLoosePartFeeder();
var l = new Location(LengthUnit.Millimeters, 11.0, 22.0, 33.0, 44.0);
var p = new Part("R0805-1K")

f.name="setFeedRetryCount​(int feedRetryCount)";
f.setPart(p);
f.setEnabled(true);
f.setLocation(l);

machine.addFeeder(f); 

Reply all
Reply to author
Forward
0 new messages