how to test text entity
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
how to test text entity
Hello,
Please how i test entities given by queryAllEntities ().
I need test if entity is RTextEntityPointer.
thanks.
Please how i test entities given by queryAllEntities ().
I need test if entity is RTextEntityPointer.
thanks.
Re: how to test text entity
Code: Select all
var document = this.getDocument(); // Reference to current document
var ids = document.querySelectedEntities(); // Qset with selected id's
var entity; // Entity in process (EntityPointer)
Skip on no Selection:
if (ids.length == 0) {
//
// .....
//
return;
}
// Find Type: Text Entity
for (i=0; i<ids.length; i++) { // Cycle through selection
// Get entity from document by id:
entity = document.queryEntity(ids[i]);
// Skip when no Entity:
if (isNull(entity)) {
continue;
}
// Filter on Text:
if (isTextEntity(entity)) {
//
// .....
//
} // End isText
} // Loop selection
// https://qcad.org/doc/qcad/3.0/developer/class_r_document.html#ab0c6b92bc6e4c3796aa17d79a957c678
//
// isTextEntity() among others in library.js
//
// There is also: doc.queryAllEntities(undone = false, allBlocks = false, RS.EntityText);
// What returns an id list of all Text entities.
CVH
Re: how to test text entity
thanks for answer but
9145 is "Text" in attribute editor
a.getData() is RTextData and then i can read values from text.
Code: Select all
ecma> a = doc.queryEntity(9145)
RTextEntityPointer(0x92d54e30)
ecma>isTextEntity(9145)
false
a.getData() is RTextData and then i can read values from text.
Re: how to test text entity
Loads variable 'a' with an REntityPointer to the entity in the document by current id = 9145.
Then one check if variable 'a' is a text entity:
Code: Select all
isTextEntity(a);
Re: how to test text entity
thanks.
this works.
this works.
Re: how to test text entity
Hello,
I have some time again, so I'm writing the script.
Of course, I also look at the manuals, I can't change the searched text or highlight it on the drawing.
Is there a special function that restores the drawing?
Thanks.
I have some time again, so I'm writing the script.
Of course, I also look at the manuals, I can't change the searched text or highlight it on the drawing.
Is there a special function that restores the drawing?
Thanks.
Code: Select all
var doc = this.getDocument();
var idx = doc.queryAllEntities();
var entity;
var text;
for(var i=0; i<idx.length; i++)
{
entity = doc.queryEntity(idx[i]);
if(isTextEntity(entity))
{
text = entity.getData().getText();
if(text.contains("GA"))
{
EAction.handleUserWarning("found " + text);
entity.getData().setText("only test");
}
}
}
Re: how to test text entity
Hi, that is more than one question.
RTextEntity has also the getPlainText() method.
Common is var ids from 'ID selected' or 'more ID's' but it is at your preference.
RTextEntity is a pointer to a clone of the actual entity.
https://qcad.org/doc/qcad/3.0/developer ... 79a957c678
var text is an RTextData.
(I prefer to name that var textData vs 'text' for a string)
You changed whole the RTextData.text to a newer value.
One needs to create a new RTextEntity from this.
And cast it back to the document overwriting the existent entity.
Processed entities are all in selection.
Remember changed text entities in an array with push ...
At the end of your code deselect all and select those listed in the array.
Regards,
CVH
RTextEntity has also the getPlainText() method.
Common is var ids from 'ID selected' or 'more ID's' but it is at your preference.
RTextEntity is a pointer to a clone of the actual entity.
https://qcad.org/doc/qcad/3.0/developer ... 79a957c678
var text is an RTextData.
(I prefer to name that var textData vs 'text' for a string)
You changed whole the RTextData.text to a newer value.
One needs to create a new RTextEntity from this.
Code: Select all
var newTextEntity = new RTextEntity(doc, text); // With text is an RTextData
Code: Select all
var di = this.getDocumentInterface();
var op = new RModifyObjectsOperation();
op.addObject(newTextEntity, false, true); // NOTuseCurrentAttributes, DOforceNew
di.applyOperation(op);
Remember changed text entities in an array with push ...
At the end of your code deselect all and select those listed in the array.
Code: Select all
var alteredList = [];
....
.... // your code
alteredList.push(idx[i]);
....
....
di.deselectAll();
di.deselectEntities(alteredList);
CVH
Re: how to test text entity
Thanks,
Now i know little more
a small plus to my zero knowledge of JS.
Text was modified but overlaped old text. so i add delete operation on old TextData and
now seems to work. Dirty solution i know but works
if I complete this script, my work will be reduced to a few minutes instead days.
thanks again for the explanation.
Now i know little more
a small plus to my zero knowledge of JS.
Text was modified but overlaped old text. so i add delete operation on old TextData and
now seems to work. Dirty solution i know but works
if I complete this script, my work will be reduced to a few minutes instead days.
thanks again for the explanation.
Code: Select all
var doc = this.getDocument();
var di = this.getDocumentInterface();
var idx = doc.queryAllEntities();
var entity;
var text;
for(var i=0; i<idx.length; i++)
{
entity = doc.queryEntity(idx[i]);
if(isTextEntity(entity))
{
text = entity.getData().getPlainText();
if(text.contains("GA"))
{
entity.setText("Pokus");
EAction.handleUserWarning("found " + text);
var newEntity = new RTextEntity(doc, entity.getData());
var op = new RModifyObjectsOperation();
op.addObject(newEntity, false, true);
di.applyOperation(op);
var de = new RDeleteObjectsOperation();
de.deleteObject(entity);
di.applyOperation(de);
}
}
}
Re: how to test text entity
Then NOT force new:
My bad (copy-paste issue)
Now you alter the text directly in the RTextEntity.
No need for the getData or to create a new RTextEntity.
That is, if this is all you need to do ...
RModifyObjectsOperation is plural.
One can set this once outside the loop together with di.applyOperation.
This groups operations, is faster and can be undone in one go.
CVH
Code: Select all
op.addObject(newTextEntity, false, false); // NOTuseCurrentAttributes, NOTforceNew
Now you alter the text directly in the RTextEntity.
No need for the getData or to create a new RTextEntity.
That is, if this is all you need to do ...
RModifyObjectsOperation is plural.
One can set this once outside the loop together with di.applyOperation.
This groups operations, is faster and can be undone in one go.
Code: Select all
var doc = this.getDocument();
var di = this.getDocumentInterface();
var idx = doc.queryAllEntities();
var entity;
var text;
var op = new RModifyObjectsOperation();
for(var i=0; i<idx.length; i++) {
entity = doc.queryEntity(idx[i]);
if(isTextEntity(entity)) {
text = entity.getPlainText();
if(text.contains("GA")) {
entity.setText("Pokus");
EAction.handleUserWarning("found " + text);
op.addObject(entity, false, false);
}
}
}
di.applyOperation(op);
Re: how to test text entity
Thanks again.
Now I'm going to solve the problem with Japanese fonts
Now I'm going to solve the problem with Japanese fonts