double selTol = 1e-2; // Selection tolerance
double newR = 1.25; // New cylinder radius
double newH = 1; // New cylinder height
double plateThickness = 1; // Plate thickness
String plateAndCylinders = “arr1”;
// Update and split geometry
model.component(“comp1”).geom(“geom1”).run(“fin”);
GeomSequence geom = model.component(“comp1”).geom(“geom1”);
geom.run(plateAndCylinders);
geom.create(“spl1”, “Split”);
geom.feature(“spl1”).selection(“input”).set(plateAndCylinders);
// Find extents of geometry in x,y,z directions
double[] bBox = geom.getBoundingBox();
// Define scaled coordinate tolerance
double scale = Math.max(Math.max(MaxX-MinX, MaxY-MinY), MaxZ-MinZ);
double scaleSelTol = scale*selTol;
// Create box selection based on geometry extents
geom.create(“boxsel1”, “BoxSelection”);
with(geom.feature(“boxsel1”));
// Select boundaries inside box in X-Y direction using tolerance
set(“xmin”, MinX+scaleSelTol);
set(“xmax”, MaxX-scaleSelTol);
set(“ymin”, MinY+scaleSelTol);
set(“ymax”, MaxY-scaleSelTol);
set(“zmin”, MinZ-scaleSelTol);
set(“zmax”, MaxZ+scaleSelTol);
set(“condition”, “inside”);
set(“entitydim”, -1); // Select objects
String[] so = geom.selection(“boxsel1”).objects();
// Extract cylinder parameters
double[] MinXC = new double[nso];
double[] MaxXC = new double[nso];
double[] MinYC = new double[nso];
double[] MaxYC = new double[nso];
double[] MinZC = new double[nso];
double[] MaxZC = new double[nso];
double[] bBoxC = new double[6];
for (int i = 0; i < nso; i++) {
bBoxC = geom.obj(so[i]).getBoundingBox();
double[] radius = new double[nso];
double[] xc = new double[nso];
double[] yc = new double[nso];
double[] zc = new double[nso];
double[] hc = new double[nso];
double tol = scale*1e-6; // Tolerance check for skew cylinders, optional consistency check
for (int i = 0; i < nso; i++) {
xc[i] = (MaxXC[i]+MinXC[i])/2;
yc[i] = (MaxYC[i]+MinYC[i])/2;
zc[i] = (MaxZC[i]+MinZC[i])/2;
hc[i] = MaxZC[i]-MinZC[i];
radius[i] = (MaxXC[i]-MinXC[i])/2;
ry = (MaxYC[i]-MinYC[i])/2;
if (Math.abs(radius[i]-ry) > tol)
error(“Object is not a circular cylinder.”);
// Delete all cylinder objects
geom.create(“del1”, “Delete”);
geom.feature(“del1”).selection(“input”).init();
geom.feature(“del1”).selection(“input”).set(so);
String[] cylname = new String[nso];
for (int i = 0; i < nso; i++) {
cylname[i] = “cyl”+toString(i+1);
geom.create(cylname[i], “Cylinder”);
with(geom.feature(cylname[i]));
set(“h”, newH+2*scaleSelTol);
set(“pos”, new double[]{xc[i], yc[i], plateThickness-2*zc[i]-scaleSelTol});
// Combine all cylinders into one object
geom.create(“uni1”, “Union”);
geom.feature(“uni1”).selection(“input”).set(cylname);
// Difference between all objects and cylinders
geom.create(“dif1”, “Difference”);
String[] objs = geom.objectNames();
geom.feature(“dif1”).selection(“input”).set(objs);
geom.feature(“dif1”).selection(“input2”).set(“uni1”);
این روش فرض میکند که اجسام هندسه ورودی ساختاری مشابه با صفحه با استوانه مثال بالا دارند. توجه داشته باشید که برای پاک کردن دنباله هندسی می توانید یک متد با خط ایجاد کنید
model.component(“comp1”).geom(“geom1”).feature().clear();
اگر روش اصلی را به طور مکرر از بالا اجرا می کنید، می تواند مفید باشد، زیرا باید قبل از هر اجرا، دنباله هندسه را پاک کنید.
geom.feature(“del1”).selection(“input”).init();
geom.feature(“del1”).selection(“input”).set(so);
انتخاب را به صورت خالی از نوع شی مقداردهی اولیه می کند. سپس خط دوم تمام اشیاء با نام در آرایه را انتخاب می کند . به طور کلی، فراخوانی به init() بدون آرگومان ورودی به این معنی است که انتخاب برای اشیا و init(n) است که در آن n = 0 ، 1 ، 2 یا 3 به این معنی است که انتخاب برای نقاط، لبه ها، وجه ها و دامنه ها به ترتیب توجه داشته باشید که در برخی موارد n = -1 برای نشان دادن سطح شی (به جای آرگومان ورودی خالی) استفاده می شود. به کتابچه راهنمای مرجع برنامه نویسی مراجعه کنید.
شکل زیر نمونه ای را بر اساس آرایه بزرگتری از سیلندرها نشان می دهد.