Setting file export path
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Setting file export path
Hi,
I'm still new to Qcad scripting, I've just finished working through the scripting tutorials, I need help to find the function that sets the export path it appears the default path is the Qcad folder.
I'm using the exportFile() function of the RdocumenIInerface Class for saving dxf files.
thanks for your help,
ash120
I'm still new to Qcad scripting, I've just finished working through the scripting tutorials, I need help to find the function that sets the export path it appears the default path is the Qcad folder.
I'm using the exportFile() function of the RdocumenIInerface Class for saving dxf files.
thanks for your help,
ash120
Re: Setting file export path
exportFile takes a file name with path if desired. The path can be absolute or relative to the QCAD directory. Example:
QDir has some static functions to get paths that might be useful:
Code: Select all
var di = new RDocumentInterface(document);
...
di.exportFile("/home/user/data/example.dxf", "DXF 2000");
Code: Select all
QDir.homePath() // system's temporary directory
QDir.tempPath() // user's home directory
QDir.rootPath() // absolute path of the root directory
Re: Setting file export path
Hi Thanks for that it works well now..
Can you give an example how to implement Qdir, is it a Qt class? as I could not find it in the Application framework documentation.
thnaks
Can you give an example how to implement Qdir, is it a Qt class? as I could not find it in the Application framework documentation.
thnaks
Re: Setting file export path
Yes, all classes starting with letter 'Q' are Qt classes. The Qt reference is available from here:
http://doc.qt.nokia.com/4.7/index.html
QDir documentation:
http://doc.qt.nokia.com/4.7/qdir.html
http://doc.qt.nokia.com/4.7/index.html
QDir documentation:
http://doc.qt.nokia.com/4.7/qdir.html
Re: Setting file export path
Thanks Andrew,
Is there an easy way to script the loading of a drawing file that was created using the RdocumentInterface , into the GUI?
Either before or after it is exported to dxf.
regards
Is there an easy way to script the loading of a drawing file that was created using the RdocumentInterface , into the GUI?
Either before or after it is exported to dxf.
regards
Re: Setting file export path
To open a drawing in the GUI (as a new tab with all the bells and whistles), you can use the same script that is also used to open a file when the user clicks on File - Open:
Depending on your context, you might have to include the script first:
Then open a given file like this:
Depending on your context, you might have to include the script first:
Code: Select all
include("scripts/File/OpenFile/OpenFile.js");
Code: Select all
var open = new OpenFile();
open.openFile("/path/to/my/file.dwg");
open.finishEvent();
Re: Setting file export path
Hi Andrew,
Thanks that was easy and it worked well.
my next question (sorry about all the questions) is how to add new layers and set the current layer so that when I use the apply function, the new entities are added to the current layer.
I tried declaring a new layer object as in OpenFile but it doesn't seem to work.
thanks again.
Thanks that was easy and it worked well.
my next question (sorry about all the questions) is how to add new layers and set the current layer so that when I use the apply function, the new entities are added to the current layer.
I tried declaring a new layer object as in OpenFile but it doesn't seem to work.
thanks again.
Re: Setting file export path
Layers can be added just like other objects:
See also RLayer constructor API doc:
http://www.ribbonsoft.com/doc/qcad/3.0/ ... 43dca108fc
Setting the current layer:
See also API doc at:
http://www.ribbonsoft.com/doc/qcad/3.0/ ... 869bf198f4
Code: Select all
// create an operation:
var operation = new RAddObjectsOperation();
// create layer:
var linetypeId = document.getLinetypeId("continuous");
var layer = new RLayer(document, "MyLayer", false, false, new RColor("white"), linetypeId, RLineweight.Weight025);
// add layer to operation:
operation.addObject(layer);
// apply operation to document:
operation.apply(document);
// OR (if you have a GUI that needs to be updated):
// documentInterface.applyOperation(operation);
http://www.ribbonsoft.com/doc/qcad/3.0/ ... 43dca108fc
Setting the current layer:
Code: Select all
// Without GUI update:
document.setCurrentLayer("MyLayer");
// With GUI update:
// documentInterface.setCurrentLayer("MyLayer");
http://www.ribbonsoft.com/doc/qcad/3.0/ ... 869bf198f4
Re: Setting file export path
Hi Andrew,
thanks for the help with the layers..
Could you advise me on how to convert a a series of lines and curves (that form a closed shape) that i've programmed using the Rdocumentinterface into a single polyline. So for example if I have all my line and curve entities in a single operation object can i convert then to a polyline before using the: operation.apply(document);
And then I'd like to be able to create a offset polyline like you can with the polyline equidistant command in the GUI.
Thanks and regards..
thanks for the help with the layers..
Could you advise me on how to convert a a series of lines and curves (that form a closed shape) that i've programmed using the Rdocumentinterface into a single polyline. So for example if I have all my line and curve entities in a single operation object can i convert then to a polyline before using the: operation.apply(document);
And then I'd like to be able to create a offset polyline like you can with the polyline equidistant command in the GUI.
Thanks and regards..
Re: Setting file export path
The API does not work like that. If you add a line to an operation, the operation will add a line to the document. If you want to have a polyline, you need to add a polyline to the operation. Entities in an operation cannot be modified before the operation has been applied.ash120 wrote:Could you advise me on how to convert a a series of lines and curves (that form a closed shape) that i've programmed using the Rdocumentinterface into a single polyline. So for example if I have all my line and curve entities in a single operation object can i convert then to a polyline before using the: operation.apply(document);
Possible solutions for your use case are:
- Update file PolylineFromSegments.js (see attachment).
- Add loose line and arc entities to the drawing in one operation.
- Convert those lines and arcs into a polyline in a separate operation using "PolylineFromSegments.createPolyline":
Code: Select all
var op = new RMixedOperation();
var polylineEntity = PolylineFromSegments.createPolyline(op, entity, document, new RVector(1.0e-3, 1.0e-3));
polylineEntity = op.addObject(polylineEntity, false);
documentInterface.applyOperation(op);
Or:
- create a polyline entity directly instead of loose line and arc entities.
BTW: I assume that by 'curve' you mean arcs and not splines. Polylines can only contain line and arc segments, not spline segments.
- Attachments
-
- PolylineFromSegments.js
- Replaces file ./scripts/Draw/Polyline/PolylineFromSegments/PolylineFromSegments.js
- (8.59 KiB) Downloaded 1078 times
Re: Setting file export path
Hi Andrew,
I want to use the polylinefromsegments function, but I need help in how to find particular entity that I have added to a Document through an operation. If for example I've added several RlineEntity objects to single operation and then applied that operation to a document, How do I then search the document to extract particular Entities that i can pass as an argument to the above function?
I want to use the polylinefromsegments function, but I need help in how to find particular entity that I have added to a Document through an operation. If for example I've added several RlineEntity objects to single operation and then applied that operation to a document, How do I then search the document to extract particular Entities that i can pass as an argument to the above function?
Re: Setting file export path
There are several ways to query entities (have a look at the RDocument::query* functions).
If you need to know the entity IDs affected by a transaction, you can use the RTransaction object returned by RDocumentInterface::applyOperation:
If you need to know the entity IDs affected by a transaction, you can use the RTransaction object returned by RDocumentInterface::applyOperation:
Code: Select all
var transaction = di.applyOperation();
var ids = transaction.getAffectedObjects()
Re: Setting file export path
I tried using your code but the debugger has an exemption on line 122: of the polyinefromsegments script. I assume i'm still not finding a valid entity. Part of my code is as follows where Entity is the last segment of the geometry i want to convert to polyline.
I assume its not working because i need to pass the Entity object itself not its Id to the polylinefromsegments script when i try to pass the line Entity in the above code directly, I get a different error.
thanks for your continued help.
Code: Select all
traversed[entity.getId()] = true;
Code: Select all
//...
var Entity = new RLineEntity(document, new RLineData(t2p4, t2p1));
operation2.addObject(Entity);
var transaction = di.applyOperation(operation2);
var ids = transaction.getAffectedObjects()
var op = new RMixedOperation();
var polylineEntity = PolylineFromSegments.createPolyline(op, ids, document, new RVector(1.0e-3, 1.0e-3));
polylineEntity = op.addObject(polylineEntity, false);
di.applyOperation(op);
thanks for your continued help.
Re: Setting file export path
The second parameter of PolylineFromSegments.createPolyline is one entity object (your script is passing an array of entity IDs).
Note that although ECMAScript does not force you, it is strongly recommended to keep the first letter of all variable names small to keep them separate from class names (e.g. 'Polyline' is a class used in the QCAD 3 API. If you use a variable named 'Polyline' (e.g. 'var Polyline = new RPolyline(..)'), you actually overwrite that class which will break the QCAD 3 API. Good variable names are 'polyline', 'entity', 'upperLine', etc. Bad are 'Entity', 'Polyline', 'UpperLine', etc.
Code: Select all
...
var ids = transaction.getAffectedObjects();
var committedEntity = document.queryEntity(ids[0]);
...
var polylineEntity = PolylineFromSegments.createPolyline(op, committedEntity, document, new RVector(1.0e-3, 1.0e-3));
...
Re: Setting file export path
Hi Andrew,
Thanks a lot for that, and for your tips on variable names.. my script works well now.
Can you show an example of how to now use the PolylineEquidistant class for crating a "parallel" polyline using the polyline entity created above?
I Assume we use PolylineEquidistant::createEquidistantParallel function but i don't know the format of the three parameters.
thanks again.
Thanks a lot for that, and for your tips on variable names.. my script works well now.
Can you show an example of how to now use the PolylineEquidistant class for crating a "parallel" polyline using the polyline entity created above?
I Assume we use PolylineEquidistant::createEquidistantParallel function but i don't know the format of the three parameters.
thanks again.