Using a Script to Navigate Around the GUI
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.
-
- Junior Member
- Posts: 24
- Joined: Fri Apr 28, 2023 12:39 pm
Using a Script to Navigate Around the GUI
Hello everyone:
How do I make my script tell where in the GUI the user currently is (i.e., are they viewing the model space? or a layout? or a block?) and/or how do I have a script force the user around the GUI (for example, if they click something in a layout the script would automatically move them to the model space)?
Thanks in advance for your time/replies.
How do I make my script tell where in the GUI the user currently is (i.e., are they viewing the model space? or a layout? or a block?) and/or how do I have a script force the user around the GUI (for example, if they click something in a layout the script would automatically move them to the model space)?
Thanks in advance for your time/replies.
Re: Using a Script to Navigate Around the GUI
The Block List will tell you that.333onlyhalfevil wrote: ↑Sat Jun 17, 2023 4:07 pmi.e., are they viewing the model space? or a layout? or a block?
If that is not showing then menu View .. Block List (GB) or by its shortcut: Type 'G' and then 'B'.
I don't see any reason for that. One can have Viewports that refer to Model_Space on a Layout but any other entity will do.333onlyhalfevil wrote: ↑Sat Jun 17, 2023 4:07 pmfor example, if they click something in a layout the script would automatically move them to the model space
Remark that Model_Space is basically not more than a Block and Layouts are that too.
You probably need 'Listeners' for that:
https://github.com/qcad/qcad/tree/maste ... erExamples
Regards,
CVH
-
- Junior Member
- Posts: 24
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Using a Script to Navigate Around the GUI
Thank you for the reply.
For the first part, I meant how do I figure that out programmatically? If I'm programming a coordinateEvent() function, how do I get the script to tell whether the user clicked inside of the modelspace block or inside of a layout block?
For the first part, I meant how do I figure that out programmatically? If I'm programming a coordinateEvent() function, how do I get the script to tell whether the user clicked inside of the modelspace block or inside of a layout block?
Re: Using a Script to Navigate Around the GUI
333onlyhalfevil wrote: ↑Wed Jun 21, 2023 5:34 pmhow do I get the script to tell whether the user clicked inside of the modelspace block or inside of a layout block?
Code: Select all
var document = this.getDocument();
var currentBlockId = document.getCurrentBlockId();
Code: Select all
var currentBlockName = document.getCurrentBlockName();
Regards,
CVH
-
- Junior Member
- Posts: 24
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Using a Script to Navigate Around the GUI
Thank you.
I was close. I was trying to use the getActiveBlockId function from Block.js. You can see it on line 113 in the source code of Block.js (https://github.com/qcad/qcad/blob/maste ... k/Block.js). Curiously, this method isn't in the ECMAscript Block class reference section of the developer documentation here (https://qcad.org/doc/qcad/3.0/developer ... block.html).
My next question seems to be with getting the block listener to work. Referring to this thread (https://qcad.org/rsforum/viewtopic.php? ... 8a03f2c20b) and this example code (https://github.com/qcad/qcad/blob/maste ... ner.js#L49); they are using an RTransactionListenerAdapter class within the code but I can't find this class within the developer documentation. Where can I find information regarding the Adapter classes and what constructors/functions they contain?
Am I even trying to do this right? If I do a doc.setCurrentBlock(modelSpace) line, it doesn't seem to do anything. At this time, I'm assuming that it does something behind the scenes and I need to use the RBlockListener to update the program to show the change. I was trying to do a this.updateBlocks(di) with di being the this.getDocumentInterface() line with no luck. What do you think?
I was close. I was trying to use the getActiveBlockId function from Block.js. You can see it on line 113 in the source code of Block.js (https://github.com/qcad/qcad/blob/maste ... k/Block.js). Curiously, this method isn't in the ECMAscript Block class reference section of the developer documentation here (https://qcad.org/doc/qcad/3.0/developer ... block.html).
My next question seems to be with getting the block listener to work. Referring to this thread (https://qcad.org/rsforum/viewtopic.php? ... 8a03f2c20b) and this example code (https://github.com/qcad/qcad/blob/maste ... ner.js#L49); they are using an RTransactionListenerAdapter class within the code but I can't find this class within the developer documentation. Where can I find information regarding the Adapter classes and what constructors/functions they contain?
Am I even trying to do this right? If I do a doc.setCurrentBlock(modelSpace) line, it doesn't seem to do anything. At this time, I'm assuming that it does something behind the scenes and I need to use the RBlockListener to update the program to show the change. I was trying to do a this.updateBlocks(di) with di being the this.getDocumentInterface() line with no luck. What do you think?
Re: Using a Script to Navigate Around the GUI
.getCurrentBlockId() or .getCurrentBlockName() are functions of the RDocument class: https://qcad.org/doc/qcad/3.0/developer ... ument.html
It is not listed in https://qcad.org/doc/qcad/3.0/developer ... block.html as do all functions that don't have the prototype mentioned.
And then there is also the RBlock class, what is all about the actual blocks: https://qcad.org/doc/qcad/3.0/developer ... block.html
That makes the forum searchable.
With doc.setCurrentBlock(modelSpace) you set the current block of the reference in doc to the content of the variable called "modelSpace".
There is no transaction involved to return that to the RDocument.
I think you are better off with the paved path of 'Return to Main Drawing (EM)': https://github.com/qcad/qcad/blob/maste ... Drawing.js
or
'Edit Block (BE)': https://github.com/qcad/qcad/blob/maste ... itBlock.js
They check for the Block List and block/unblock the signals of the Block list.
Eventually they will call this.editBlock (Block.prototype.editBlock) and thus Block.editBlock(di, blockName): https://github.com/qcad/qcad/blob/maste ... k/Block.js
Straightforward with Model_Space as that is a default block in each document.
For other block you need to check if the document has the intended block.
Still I wonder why you want to navigate to the blocks by custom script ... Simply double click on a Block Reference will switch to that block in edit mode or type the key-in shortcut EM to return to Model_Space ...
Regards,
CVH
getActiveBlockId is a function of the base class for QCAD block tools.333onlyhalfevil wrote: ↑Sun Jun 25, 2023 4:54 pmCuriously, this method isn't in the ECMAscript Block class reference section of the developer documentation here (https://qcad.org/doc/qcad/3.0/developer ... block.html).
It is not listed in https://qcad.org/doc/qcad/3.0/developer ... block.html as do all functions that don't have the prototype mentioned.
And then there is also the RBlock class, what is all about the actual blocks: https://qcad.org/doc/qcad/3.0/developer ... block.html
Please post one question per topic, see above forum rules in red.333onlyhalfevil wrote: ↑Sun Jun 25, 2023 4:54 pmMy next question seems to be with getting the block listener to work.
That makes the forum searchable.
With doc.setCurrentBlock(modelSpace) you set the current block of the reference in doc to the content of the variable called "modelSpace".
There is no transaction involved to return that to the RDocument.
I think you are better off with the paved path of 'Return to Main Drawing (EM)': https://github.com/qcad/qcad/blob/maste ... Drawing.js
or
'Edit Block (BE)': https://github.com/qcad/qcad/blob/maste ... itBlock.js
They check for the Block List and block/unblock the signals of the Block list.
Eventually they will call this.editBlock (Block.prototype.editBlock) and thus Block.editBlock(di, blockName): https://github.com/qcad/qcad/blob/maste ... k/Block.js
Straightforward with Model_Space as that is a default block in each document.
For other block you need to check if the document has the intended block.
Still I wonder why you want to navigate to the blocks by custom script ... Simply double click on a Block Reference will switch to that block in edit mode or type the key-in shortcut EM to return to Model_Space ...
Regards,
CVH
-
- Junior Member
- Posts: 24
- Joined: Fri Apr 28, 2023 12:39 pm
Re: Using a Script to Navigate Around the GUI
Thank you for the help.
I seem to have it working as expected now.
To satisfy your curiosity, I'm trying to program a custom search function that basically searches through the drawing to find common mistakes and bring the user to them, similar to how ctrl+F does it with text in word docs. When you click the 'next' button (presumably inside a widget which I haven't started trying to figure out how to do yet), the program would bring you to wherever in the drawing the mistake is. If the user is currently viewing a layout and the next one is in the model space, when they click next, the program would have to move them to the model space.
To sum up (for someone who might find themselves here in the future), I got it working using a line of code out of the link from this part of CVH's previous reply:
Another thing to note is that the RBlock class has a public attribute called modelSpaceName so you don't need to get the model space block's id into a variable before trying to use that variable to move the user to the model space. You can just use modelSpaceName.
Anyways, thanks again for the help. I really appreciate it. If I come across another issue that I need help with, I'll be sure to post it in a new thread.
I seem to have it working as expected now.
To satisfy your curiosity, I'm trying to program a custom search function that basically searches through the drawing to find common mistakes and bring the user to them, similar to how ctrl+F does it with text in word docs. When you click the 'next' button (presumably inside a widget which I haven't started trying to figure out how to do yet), the program would bring you to wherever in the drawing the mistake is. If the user is currently viewing a layout and the next one is in the model space, when they click next, the program would have to move them to the model space.
To sum up (for someone who might find themselves here in the future), I got it working using a line of code out of the link from this part of CVH's previous reply:
In particular, I used the commented out line of code: this.getDocumentInterface().setCurrentBlock(RBlock.modelSpaceName);I think you are better off with the paved path of 'Return to Main Drawing (EM)': https://github.com/qcad/qcad/blob/maste ... Drawing.js
Another thing to note is that the RBlock class has a public attribute called modelSpaceName so you don't need to get the model space block's id into a variable before trying to use that variable to move the user to the model space. You can just use modelSpaceName.
Anyways, thanks again for the help. I really appreciate it. If I come across another issue that I need help with, I'll be sure to post it in a new thread.
Re: Using a Script to Navigate Around the GUI
That was commented out by a commit on Mar 30, 2013: "remember zoom and offset when switching blocks".333onlyhalfevil wrote: ↑Mon Jun 26, 2023 2:55 pmIn particular, I used the commented out line of code: this.getDocumentInterface().setCurrentBlock(RBlock.modelSpaceName);
The paved method also checks if the user is not by any chance editing a block "In-Place".
Regards,
CVH