I am repetitively drawing sketches for a specific type of biological reactor, but the dimensions always change case by case, so my idea was to automatize this with a script.
Basically all i need is the outline the reactor and its main features from a top and a side view, I can define the coordinates to be step-by-step connected by straight lines (polylines) based on a set of input variables.
So as a first step i was trying to create a script which just draws a polyline based on some pre-defined points. Now it turns out I am a complete noob at this as I do not know Jscript and even long conversations with famous AI bots have not helped me produce working code. I am using EAction.handleUserMessage for debug messages as i am having issues displaying qDebug messages and i find this more convenient.
My last example is:
Code: Select all
include("scripts/EAction.js");
function AAAPolyline(guiAction) {
EAction.call(this, guiAction);
}
AAAPolyline.prototype = new EAction();
AAAPolyline.prototype.beginEvent = function() {
var doc = this.getDocument();
var di = this.getDocumentInterface();
if (!doc || !di) {
EAction.handleUserMessage("Error: Document or interface not found.");
return;
}
EAction.handleUserMessage("Creating a polyline.");
// Create a list of corner points for the polyline
var points = [
[0, 0], // First point
[100, 100], // Second point
[200, 0] // Third point
];
try {
// Add the polyline using addPolyline()
doc.addPolyline(points, false); // false indicates the polyline is not closed
EAction.handleUserMessage("Polyline added.");
} catch (error) {
EAction.handleUserMessage("Error adding polyline: " + error);
}
};
AAAPolyline.init = function(basePath) {
var action = new RGuiAction(qsTr("AAAPolyline"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/AAAPolyline.js");
action.setGroupSortOrder(11);
action.setSortOrder(101);
action.setWidgetNames(["DrawMenu", "DrawToolBar", "DrawToolsPanel"]);
}
Could somebody help point me in the right direction here?
I have done the mathematical part of the work to define all the coordinates of the cornerpoints of the polylines based on a set of input variables. So once this is working, the next step would be to prompt the user (me) for these variables (for example water depth, wall thickness, etc.) and then adjust the code so that the polylines are drawn according to these coordinates.
Thanks in advance for any tip!