I'm trying to automate the placement of certain components' positions in the PCB Design editor via javascript. I've tried assigning the Position.X and Position.Y attributes of the component directly with a float as well as trying to set them with the Design.toDSU() function, but neither seem to have any effect. Has anyone been able to assign positions to pcb components? Below is the full code. Also, is there a log or console anywhere that shows any output from the running of the script?
var Design = ActiveDocument();
var DesignComps = Design.Components();
var Comps = new Enumerator(DesignComps);
// Spin through the list of components.
for (; !Comps.atEnd(); Comps.moveNext()) {
// Retrieve the current component.
var Comp = Comps.item();
Comp.Position.X = Design.ToDsuX(0.0);
Comp.Position.Y = Design.ToDsuY(0.0);
// Have also tried this
//Comp.Position.X = 0;
//Comp.Position.Y = 0;
}
Sadly, what you are trying to do is not currently possible. Contrary to what it says for data type 'Point' (that X and Y have both Get and Set functions), you will find on the page for DesignItem (the base class of most design objects) that the Position property has a 'Get' but no 'Set' function. This means that for items like components you can get the current position but you cannot change it.
Hi David. Thanks for the quick reply. Is there any other way to set position data for a large number of components outside of scripting? We have 60 led and resistors we're placing in a circular pattern. Just to change the radius of the circle, we have to: computer x,y coordinates from radius,angle in excel; click through each led/resistor pair and set the coordinates through the dialog. Perhaps there a text format such that we could copy it to the clipboard and then do an "apply layout to selected" operation?
If you are placing items in a circular pattern, I would suggest you investigate Polar grids if you haven't already done so. A grid (for snapping items onto) usually gives you straightforward X Y steps, but by setting a grid as Polar you can tell it to start from a given location and subdivide the circle around that point by the required angular step, and also apply a number of concentric rings. It will also auto-rotate components as you place them at intersection points on the grid.
As things stand in the current software, there isn't really any way to feed the application with a list of component positions and angles