// get the component to replace
var componentToReplace = "R1";
// get the new component from a different library
var newComponentPath = "MyLibrary\\NewComponents.LibPkg"; // the path to the new library package
var newComponentName = "R3"; // the name of the new component in the library
// loop through all components in the schematic
for (var i = 0; i < currentSheet.GetSchObjectCount(); i++) {
var obj = currentSheet.GetSchObject(i);
if (obj.GetSelectStatus() == eSelected) {
if (obj.GetState() == SCH_COMP) {
var component = obj;
if (component.GetLibReference().GetLibItemName() == componentToReplace) {
// get the current location of the component
var x = component.GetState_X();
var y = component.GetState_Y();
// get the current rotation of the component
var rotation = component.GetState_Rotation();
// remove the current component
currentSheet.RemoveSchObject(component);
// add the new component from the new library at the same location and rotation
var newLib = currentDoc.FindLibrary(newComponentPath);
var newComponentTemplate = newLib.FindSchComponentTemplate(newComponentName);
var newComponent = currentSheet.CreateSchComponent(x, y, rotation, newComponentTemplate);
currentSheet.AddSchObject(newComponent);
}
}
}
}
Replace components in schematic JavaScript
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Электроника / cхемотехника
- Просмотров: 952
If you want to replace components in your schematic with components from another library, you will need to add that library to your Altium Designer project first. Once the library is added, you can modify the script to use components from the new library by specifying the full path and name of the new component.
Here's an example of how to modify the script to replace components with components from a different library:
javascript
