Setting file export path

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Setting file export path

Postby ash120 » Tue Apr 17, 2012 8:06 am

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
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Tue Apr 17, 2012 8:35 am

exportFile takes a file name with path if desired. The path can be absolute or relative to the QCAD directory. Example:

Code: Select all
var di = new RDocumentInterface(document);
...
di.exportFile("/home/user/data/example.dxf", "DXF 2000");


QDir has some static functions to get paths that might be useful:
Code: Select all
QDir.homePath()         // system's temporary directory
QDir.tempPath()         // user's home directory
QDir.rootPath()         // absolute path of the root directory
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Tue Apr 17, 2012 1:58 pm

Hi Thanks for that it works well now.. :D

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
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Tue Apr 17, 2012 6:46 pm

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
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Wed Apr 18, 2012 7:57 am

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
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Wed Apr 18, 2012 8:07 am

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:

Code: Select all
include("scripts/File/OpenFile/OpenFile.js");


Then open a given file like this:

Code: Select all
var open = new OpenFile();
open.openFile("/path/to/my/file.dwg");
open.finishEvent();
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Wed Apr 18, 2012 12:15 pm

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.
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Wed Apr 18, 2012 3:04 pm

Layers can be added just like other objects:

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);


See also RLayer constructor API doc:
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");


See also API doc at:
http://www.ribbonsoft.com/doc/qcad/3.0/ ... 869bf198f4
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Thu Apr 19, 2012 9:05 am

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..
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Thu Apr 19, 2012 2:40 pm

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);


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.

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);

- Note that entity has to be a valid entity with an ID that is part of the document (check entity.getId()).

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 286 times
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Mon Apr 23, 2012 2:42 pm

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?
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Tue Apr 24, 2012 12:19 pm

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:
Code: Select all
var transaction = di.applyOperation();
var ids = transaction.getAffectedObjects()
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Wed Apr 25, 2012 3:46 am

I tried using your code but the debugger has an exemption on line 122:
Code: Select all
 traversed[entity.getId()] = true;
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.
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);

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.
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Re: Setting file export path

Postby andrew » Wed Apr 25, 2012 9:11 am

The second parameter of PolylineFromSegments.createPolyline is one entity object (your script is passing an array of entity IDs).

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));
...


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.
User avatar
andrew
Site Admin
 
Posts: 2557
Joined: Fri Mar 30, 2007 6:07 am

Re: Setting file export path

Postby ash120 » Thu Apr 26, 2012 8:41 am

Hi Andrew,

Thanks a lot for that, and for your tips on variable names.. my script works well now. :D

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.
ash120
Newbie Member
 
Posts: 9
Joined: Tue Apr 17, 2012 7:50 am

Next

Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: andrew and 1 guest