Add new property in property editor for RTextEntity
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.
Add new property in property editor for RTextEntity
Hi, I'm new to QCAD, and I'm wondering how can I extend RTextEntity properties ? I want to add visibility property, so I can show/hide a text.
Thanks in advance
Thanks in advance
Re: Add new property in property editor for RTextEntity
The visibility of an entity would typically be controlled by its layer (preferred).
Text entities don't have a visibility flag. Adding such a feature would require adding this information to DXF/DWG when saving (as a custom property).
As an alternative, you could use block attributes instead of text labels.
Create a block with a single attribute definition: Insert an instance of that block for each text label in the drawing. This creates a single block attribute for every instance of the block: Block attributes (unlike text entities) do have a visibility property:
Text entities don't have a visibility flag. Adding such a feature would require adding this information to DXF/DWG when saving (as a custom property).
As an alternative, you could use block attributes instead of text labels.
Create a block with a single attribute definition: Insert an instance of that block for each text label in the drawing. This creates a single block attribute for every instance of the block: Block attributes (unlike text entities) do have a visibility property:
Re: Add new property in property editor for RTextEntity
Thanks Andrew for your reply. I understand the approch to use block because they have visibility property.
but still i need to know how it is possible to exted class such RLineEntity
because my goal is :
to be able with a custom tool line to develop, to draw a line that automaticaly draw with it dimention of line as text
and that tool line have a custom property further : visibility, that allow showig or hiding line dimension
but still i need to know how it is possible to exted class such RLineEntity
because my goal is :
to be able with a custom tool line to develop, to draw a line that automaticaly draw with it dimention of line as text
and that tool line have a custom property further : visibility, that allow showig or hiding line dimension
Re: Add new property in property editor for RTextEntity
You would have to work with custom properties and maybe a transaction listener to react to property changes.
Re: Add new property in property editor for RTextEntity
Thanks for your reply, working with custom properties shows perfecty the property in the editor roperty.
As you said now for tracking property changes, do you have an exemple using RTransactionListener ?
Thanks in advance !
As you said now for tracking property changes, do you have an exemple using RTransactionListener ?
Thanks in advance !
Re: Add new property in property editor for RTextEntity
Yes, a transaction listener example (as C++ plugin) is available at:
https://github.com/qcad/qcad/tree/maste ... onlistener
And the JS equivalent:
https://github.com/qcad/qcad/tree/maste ... onListener
https://github.com/qcad/qcad/tree/maste ... onlistener
And the JS equivalent:
https://github.com/qcad/qcad/tree/maste ... onListener
Re: Add new property in property editor for RTextEntity
I saw the JS transaction listener example, and the given Ids of objects affected.
For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?
A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?
For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?
A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?
Re: Add new property in property editor for RTextEntity
No. Your transaction listener is global and will always be triggered, for every change in every document. To find out what has changed you need to look into the RTransaction object.sarlaa wrote:For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
I've updated the example:sarlaa wrote:Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?
https://github.com/qcad/qcad/blob/maste ... istener.js
The entity pointer can be used just like the entity to retrieve data or change data. To pass a pointer to a function that expects an entity, you can use .data() to dereference. E.g.:sarlaa wrote:A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?
Code: Select all
entity2.copyAttributesFrom(entity1.data());
Re: Add new property in property editor for RTextEntity
Again thanks Andrew for your reply, that was very helpful.
Now that I have all these pieces, if you may I have just one a further question, assuming that I have the object RLineEntity and the object RTextEntity (line dimension), is there a way to set the text dimension as an attribute of RLineEntity object by JS ? And reach after the attribute of dimension base on the object RLineEntity ?
Now that I have all these pieces, if you may I have just one a further question, assuming that I have the object RLineEntity and the object RTextEntity (line dimension), is there a way to set the text dimension as an attribute of RLineEntity object by JS ? And reach after the attribute of dimension base on the object RLineEntity ?
Re: Add new property in property editor for RTextEntity
I'm not sure I understood this question correctly.
If you mean to reference an entity from another entity, the recommended way to do su is through the entity's handle (entity.getHandle()). Handles are persistent and don't change during the lifetime of an object. The dimension entity might have a handle of "0xa1" and the line entity might refer to the dimension entity through a custom property "dimension" with value "0xa1".
You can query objects by handle using
If you mean to reference an entity from another entity, the recommended way to do su is through the entity's handle (entity.getHandle()). Handles are persistent and don't change during the lifetime of an object. The dimension entity might have a handle of "0xa1" and the line entity might refer to the dimension entity through a custom property "dimension" with value "0xa1".
You can query objects by handle using
Code: Select all
document.queryObjectByHandle(handle);
Re: Add new property in property editor for RTextEntity
Hi Andrew,
Doing as you described, i'll need to hide the custom property. Is there a way to do that ?
Doing as you described, i'll need to hide the custom property. Is there a way to do that ?
Re: Add new property in property editor for RTextEntity
No, there is currently no easy way to hide custom properties.
Re: Add new property in property editor for RTextEntity
Okay.
I have 3 questions more please :
1- Can I hide the button : Add Custom Property, from property editor custom section ?
2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener
Thanks in advance.
I have 3 questions more please :
1- Can I hide the button : Add Custom Property, from property editor custom section ?
2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener
Thanks in advance.
Re: Add new property in property editor for RTextEntity
You could install an RPropertyListener and look up and hide the button every time the property editor layout is rebuilt:sarlaa wrote:1- Can I hide the button : Add Custom Property, from property editor custom section ?
Code: Select all
var appWin = RMainWindowQt.getMainWindow();
var dock = appWin.findChild("PropertyEditorDock");
var button = dock.findChild("AddCustomProperty");
button.hide();
Yes, you'd need to release the translations using lrelease (comes with Qt) to create a qm file. ts files are translation sources.sarlaa wrote:2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
Everything in init is called on start up. So you can simply place all code you want to run on start up into ExTransactionListener.init:sarlaa wrote:3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener
Code: Select all
ExTransactionListener.init = function(basePath) {
...
var adapter = new RTransactionListenerAdapter();
var appWin = EAction.getMainWindow();
appWin.addTransactionListener(adapter);
...
};
Re: Add new property in property editor for RTextEntity
Thanks very much Andrew, with your orientation all is working !