convert polyline to spline
Posted: Wed Apr 02, 2025 8:13 am
MACOS 14.7.3 Qcad 3.27
is there a way to convert a convert polyline to spline through GUI or a script AUTOMATICALLY ?
I remember a post from andrew :
Here's a way to do it without clicking each point. First, we have to set an undocumented preference in the QCAD3.ini file (we only have to do this once): 1. Misc > Development > Script Shell 2. In dialog click "Show ECMAScript Shell" 3. In the script shell, type: RSettings.setValue("InfoStorePositions/PolylineNodes", true); 4. Press Enter To draw a spline with fit points from polyline nodes: 1. Select the polyline 2. Misc > Information > Store Positions 3. Draw > Spline > Spline (Fit Points) 4. Misc > Information > Use Positions 5. Escape More information about reusing drawing positions: https://qcad.org/tutorial-reusing-drawing-positions.
Any attemps I try to write a script result in a error:
Following is my last attemps.
I would appreciate if someone did successfully the same task.
Daniele
/**
* QCAD Polyline to Spline Automation Script
* This script automates the process of converting polylines to splines
* using fit points in QCAD on macOS.
*/
function init(basePath) {
// Nothing to do here
print("DEBUG: Script initialization started");
}
function run() {
print("DEBUG: Script execution started");
// First, make sure the preference is set
print("DEBUG: Checking preference setting...");
var currentValue = RSettings.getValue("InfoStorePositions/PolylineNodes", false);
if (!currentValue) {
print("DEBUG: Setting preference 'InfoStorePositions/PolylineNodes' to true");
RSettings.setValue("InfoStorePositions/PolylineNodes", true);
print("Preference 'InfoStorePositions/PolylineNodes' set to true");
} else {
print("DEBUG: Preference is already set correctly");
}
// Get the document and document interface
print("DEBUG: Getting document interface and document");
var di = EAction.getDocumentInterface();
if (!di) {
print("ERROR: Document interface not available");
return;
}
print("DEBUG: Document interface obtained successfully");
var doc = di.getDocument();
if (!doc) {
print("ERROR: No document available");
return;
}
print("DEBUG: Document obtained successfully");
// Get the current selection
print("DEBUG: Getting current selection");
var selection = doc.getSelectionSet();
print("DEBUG: Selection size: " + selection.size());
if (selection.size() === 0) {
print("ERROR: Nothing selected. Please select a polyline first.");
return;
}
if (selection.size() > 1) {
print("ERROR: Please select only one polyline at a time.");
return;
}
// Get the ID of the selected entity
print("DEBUG: Getting selected entity");
var objectId = selection.at(0);
print("DEBUG: Selected object ID: " + objectId);
var object = doc.queryEntityDirect(objectId);
if (!object) {
print("ERROR: Could not query the selected object");
return;
}
print("DEBUG: Entity type: " + object.getType());
if (!isPolylineEntity(object)) {
print("ERROR: The selected object is not a polyline");
return;
}
print("DEBUG: Selected object is a polyline");
// Store positions of polyline nodes
print("DEBUG: Storing polyline node positions...");
var success = di.callCommand("InfoStorePositions", ["PolylineNodes"]);
if (!success) {
print("ERROR: Failed to store polyline positions");
return;
}
print("DEBUG: Polyline node positions stored successfully");
// Create spline from stored positions
print("DEBUG: Creating spline...");
success = di.callCommand("SplineFitPoints", []);
if (!success) {
print("ERROR: Failed to create spline");
return;
}
print("DEBUG: Spline created successfully");
// Use stored positions for the spline
print("DEBUG: Using stored positions for spline...");
success = di.callCommand("InfoUsePositions", []);
if (!success) {
print("ERROR: Failed to use stored positions");
return;
}
print("DEBUG: Process completed successfully - polyline converted to spline");
}
// Helper function to check if the entity is a polyline
function isPolylineEntity(entity) {
print("DEBUG: Checking if entity is a polyline");
if (!entity) {
print("DEBUG: Entity is null or undefined");
return false;
}
var type = entity.getType();
print("DEBUG: Entity type is: " + type + " (Polyline type would be: " + RS.EntityPolyline + ")");
return type === RS.EntityPolyline;
}
is there a way to convert a convert polyline to spline through GUI or a script AUTOMATICALLY ?
I remember a post from andrew :
Here's a way to do it without clicking each point. First, we have to set an undocumented preference in the QCAD3.ini file (we only have to do this once): 1. Misc > Development > Script Shell 2. In dialog click "Show ECMAScript Shell" 3. In the script shell, type: RSettings.setValue("InfoStorePositions/PolylineNodes", true); 4. Press Enter To draw a spline with fit points from polyline nodes: 1. Select the polyline 2. Misc > Information > Store Positions 3. Draw > Spline > Spline (Fit Points) 4. Misc > Information > Use Positions 5. Escape More information about reusing drawing positions: https://qcad.org/tutorial-reusing-drawing-positions.
Any attemps I try to write a script result in a error:
Following is my last attemps.
I would appreciate if someone did successfully the same task.
Daniele
/**
* QCAD Polyline to Spline Automation Script
* This script automates the process of converting polylines to splines
* using fit points in QCAD on macOS.
*/
function init(basePath) {
// Nothing to do here
print("DEBUG: Script initialization started");
}
function run() {
print("DEBUG: Script execution started");
// First, make sure the preference is set
print("DEBUG: Checking preference setting...");
var currentValue = RSettings.getValue("InfoStorePositions/PolylineNodes", false);
if (!currentValue) {
print("DEBUG: Setting preference 'InfoStorePositions/PolylineNodes' to true");
RSettings.setValue("InfoStorePositions/PolylineNodes", true);
print("Preference 'InfoStorePositions/PolylineNodes' set to true");
} else {
print("DEBUG: Preference is already set correctly");
}
// Get the document and document interface
print("DEBUG: Getting document interface and document");
var di = EAction.getDocumentInterface();
if (!di) {
print("ERROR: Document interface not available");
return;
}
print("DEBUG: Document interface obtained successfully");
var doc = di.getDocument();
if (!doc) {
print("ERROR: No document available");
return;
}
print("DEBUG: Document obtained successfully");
// Get the current selection
print("DEBUG: Getting current selection");
var selection = doc.getSelectionSet();
print("DEBUG: Selection size: " + selection.size());
if (selection.size() === 0) {
print("ERROR: Nothing selected. Please select a polyline first.");
return;
}
if (selection.size() > 1) {
print("ERROR: Please select only one polyline at a time.");
return;
}
// Get the ID of the selected entity
print("DEBUG: Getting selected entity");
var objectId = selection.at(0);
print("DEBUG: Selected object ID: " + objectId);
var object = doc.queryEntityDirect(objectId);
if (!object) {
print("ERROR: Could not query the selected object");
return;
}
print("DEBUG: Entity type: " + object.getType());
if (!isPolylineEntity(object)) {
print("ERROR: The selected object is not a polyline");
return;
}
print("DEBUG: Selected object is a polyline");
// Store positions of polyline nodes
print("DEBUG: Storing polyline node positions...");
var success = di.callCommand("InfoStorePositions", ["PolylineNodes"]);
if (!success) {
print("ERROR: Failed to store polyline positions");
return;
}
print("DEBUG: Polyline node positions stored successfully");
// Create spline from stored positions
print("DEBUG: Creating spline...");
success = di.callCommand("SplineFitPoints", []);
if (!success) {
print("ERROR: Failed to create spline");
return;
}
print("DEBUG: Spline created successfully");
// Use stored positions for the spline
print("DEBUG: Using stored positions for spline...");
success = di.callCommand("InfoUsePositions", []);
if (!success) {
print("ERROR: Failed to use stored positions");
return;
}
print("DEBUG: Process completed successfully - polyline converted to spline");
}
// Helper function to check if the entity is a polyline
function isPolylineEntity(entity) {
print("DEBUG: Checking if entity is a polyline");
if (!entity) {
print("DEBUG: Entity is null or undefined");
return false;
}
var type = entity.getType();
print("DEBUG: Entity type is: " + type + " (Polyline type would be: " + RS.EntityPolyline + ")");
return type === RS.EntityPolyline;
}