I am using the code from ExText.js as a starting point, as it is very simple and easy to understand. I pulled everything out of the ExText.prototype.beginEvent (except the DrawExamples top line) and put it into another function and tried to call it. This didn’t work because of two related issues, the this.getDocument() in the new RTextEntity and the this.getDocumentInterface() at the end prior to terminate. Obviously, the prototype isn’t available in my new function.
I then referred to the CubeCuttingOut.js, which is a good example of the ability to create various functions that can be called as needed. Throughout the file, the parameter documentInterface is passed into nearly every function. However, I can’t find anywhere that this parameter has been defined. I looked in the included library.js and the CubeCuttingOut.js.
Can you provide the code necessary to define a variable, such as documentInterface or explain where it is defined in the CubeCuttingOut.js?
Thank you.
CubeCuttingOut.js Parameter Definition
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.
-
- Full Member
- Posts: 84
- Joined: Sat Nov 03, 2012 2:00 am
CubeCuttingOut.js Parameter Definition
Last edited by wildspidee on Wed Jan 21, 2015 5:03 pm, edited 1 time in total.
-
- Full Member
- Posts: 84
- Joined: Sat Nov 03, 2012 2:00 am
Re: CubeCuttingOut.js Parameter Definition
This works, but I wouldn't think this is correct long term -
Code: Select all
FMBodice.prototype.beginEvent = function() {
FMScripts.prototype.beginEvent.call(this);
FMBodice.fmtext(this.getDocument(), this.getDocumentInterface());
};
FMBodice.fmtext = function(gDocument, gDocumentInterface) {
var pos = new RVector(5,10)
// create an operation for adding objects:
var op = new RAddObjectsOperation();
// create a text entity and add it to the operation:
var text = new RTextEntity(
gDocument,
new RTextData(
pos, // position
pos, // alignment point
2.0, // height
2.0, // text width (ignored for now)
RS.VAlignTop, // alignments
RS.HAlignCenter,
RS.LeftToRight,
RS.Exact,
1.0, // line spacing factor
"New Test", // the text
"Arial", // font
false, // bold
false, // italic
0.0, // angle
false // simple text without formatting
)
);
op.addObject(text);
//qDebug();
// apply the operation to the current drawing:
gDocumentInterface.applyOperation(op);
}
Re: CubeCuttingOut.js Parameter Definition
QCAD calls these functions to generate the item or the item preview. You can simply rely on the parameter being passed to MyItem.generate and MyItem.generatePreview.wildspidee wrote:Can you provide the code necessary to define a variable, such as documentInterface or explain where it is defined in the CubeCuttingOut.js?
In other words
MyItem.generate = function(documentInterface) { ... };defines a function which is called by QCAD to generate the item's drawing entities when the item is inserted. documentInterface is a variable to the documentInterface of the document into which the item is being inserted. You need documentInterface to add the entities you want to insert when the user inserts your script item from the library browser.
-
- Full Member
- Posts: 84
- Joined: Sat Nov 03, 2012 2:00 am
Re: CubeCuttingOut.js Parameter Definition
Since CubeCuttingOut is an explicit example of a library part, this code is perfect for that purpose. Since eventually all my patterns will be parts, I'll switch over to this when the time comes.
I appreciate the great explanation.
Lori
I appreciate the great explanation.
Lori