[Solved]How to Call Save function on my Script?

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: How to Call Save function on my Script?

Post by andrew » Mon May 30, 2016 11:07 am

Doesn't sound right. However, without context, I cannot help. Can you ZIP / attach your scripts/luSYS?

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: How to Call Save function on my Script?

Post by Ghost_of_Magellan » Mon May 30, 2016 11:22 am

Here it goes.

Sorry for the trouble, and thank you.
Last edited by Ghost_of_Magellan on Fri Jun 03, 2016 12:42 pm, edited 1 time in total.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: How to Call Save function on my Script?

Post by andrew » Mon May 30, 2016 1:57 pm

OK, thanks. I'll have a look when time allows.

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: How to Call Save function on my Script?

Post by Ghost_of_Magellan » Mon May 30, 2016 2:08 pm

Can't ask for anything more.

Thank you.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: How to Call Save function on my Script?

Post by andrew » Mon May 30, 2016 2:51 pm

Try adding this at the very end of your beginEvent function:
this.terminate();
This should fix the termination problem when the widget is shown.

However, it might also create other problems since your FirstWidget object is then immediately destroyed which means all references to this / self will stop working or crash. You can probably work around this by using EAction.getDocumentInterface instead of self.getDocumentInterface.

My recommendation would be:
- FirstWidget.init should create the dock widget (probably hidden by default).
- The class FirstWidget should only show / hide the dock widget in beginEvent.
- Everything else is handled by a separate class which is the actual implementation of your dock widget.

All QCAD dock widgets are built that way (LayerList, BlockList, etc.).

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: How to Call Save function on my Script?

Post by Ghost_of_Magellan » Tue May 31, 2016 2:49 pm

Well, it does work like this:
docInterface = EAction.getDocumentInterface();

widgets["cmd_Save"].clicked.connect(function () {
	
		if(nr_linhas > 0 && entityIds.length>0){
			if (vl_nr_selected > 0){
				entityIds = WipeLastCircle(doc, docInterface, entityIds);
				SetLastColors(doc, docInterface, entityIds, last_id, last_color);
			}
			nr_linhas = DoRefresh(doc, docInterface, widgets, entityIds, nr_linhas);

			var vl_save = new Save();
			docInterface.queueAction(vl_save);
		}
	});
this.terminate();
I have tried this with and without the this.terminate(); option. These are my observations:
With this.terminate(); The save function does work, however, when the button is pressed, nothing happens. The save is only concluded and the save window opened when I change windows(alt tab into another program, for example). After that the save window appears immediately. If I don't do this, the window will not appear no matter how much I wait.
Without this.terminate(); The first time I press save I can get the window to appear by right clicking or Esc. This only happens the first time. After that I have to change work windows, as described above.

So the this.terminate(); does not seem to be of great impact, on this matter, at least.

Your suggestion about the widget creation on initialization seems to be the most appropriate, and it is within my plans to follow it through when I have the time, though for now I'm somewhat eager just to have a decently functioning app. And though the app is, technically working, lets be frank, this error is stupid.

An off topic question, if I may.
Imagine that I have two entities on top of one another. I can change the colour of one of them to highlight it on the drawing board, but if it's UNDER the other entity, it will still be hard to see it. What command/function can I use to push to the entity back or to the front in relation to the other?

Thank you.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: How to Call Save function on my Script?

Post by andrew » Wed Jun 01, 2016 7:41 am

Try this to trigger Save / SaveAs:
var a = RGuiAction.getByScriptFile("scripts/File/Save/Save.js");
docInterface.setCurrentAction(new Save(a));
The problem is that those inline functions are running in whatever script context that is active when the user presses the button.
Ghost_of_Magellan wrote:Imagine that I have two entities on top of one another. I can change the colour of one of them to highlight it on the drawing board, but if it's UNDER the other entity, it will still be hard to see it. What command/function can I use to push to the entity back or to the front in relation to the other?
That would be the "Draw Order" property.

Ghost_of_Magellan
Full Member
Posts: 58
Joined: Wed Mar 16, 2016 5:10 pm

Re: How to Call Save function on my Script?

Post by Ghost_of_Magellan » Wed Jun 01, 2016 9:28 am

Works perfectly!!

Thank you, andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”