new dovetail script

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

new dovetail script

Post by caigner » Tue Feb 14, 2017 1:23 pm

Changelog: I removed the old, defect script from this post and added a working copy at the end of this thread.

My goal was to create a dovetail script with the following parameters:

- number of dovetails,
- height of dovetail,
- dovetail gradient (usually 7:1, 6:1, 5:1 and 4:1)
- dovetail/pin ratio

By selecting start and end point, you define the width of the board.

First let my say, that I am not a javascript programmer, and I have no clue how all this QCAD scripting works.
I took the boxjoint script from Matthias Melcher and tried to implement the mathematical calculations for the dovetails.

I have tried my best during the last 3 days to come up with a working dovetail script, but I have failed. I get no errors but noting is drawn on the screen.

Maybe someone with more scripting knowledge can have a look at the script and find out, why it does not work.

I have attached a drawing so it is easy to figure out, what the variables in the script relate to.
Attachments
Dovetail_Calculation.dxf
(109.25 KiB) Downloaded 874 times
Last edited by caigner on Thu Feb 16, 2017 12:53 pm, edited 1 time in total.
QCAD Pro on Gentoo Linux

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

Re: new dovetail script

Post by andrew » Thu Feb 16, 2017 8:34 am

First, please make sure that your script has a unique name, for example LineDove2. All your files and the class defined inside have to use that same name.

I can see that your script produces lines which cannot be shown because they have invalid coordinates.

Here are some tips for debugging:
- Use qDebug(...) statements to print variables, for example:
qDebug("myVector: ", myVector);
- Alternatively, use EAction.handleUserMessage(...) to print information to the QCAD command line history.
- Start QCAD with the command line argument -enable-script-debugger and place a debugger statement to stop your script at that line and show a debugger which you can use to step through code, observe variables, set variables, etc:
debugger;
Note that the script debugger can lead to crashes due to immediate event processing, so this should really only be used if you intend to debug a script.

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 11:01 am

Thanks! I have used qDebug() to find out, what values my parameters have, and I found out, that they are all "undefined".
So my problem is, that I don't know, how to get values from the UI to the script.

For example, I can input "Number of Dovetails", but the value is not transfered to the script.

Any suggestions? How do I access input parameters in the script?
QCAD Pro on Gentoo Linux

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

Re: new dovetail script

Post by andrew » Thu Feb 16, 2017 11:34 am

Whenever the user changes the values in the UI, a signal is fired which calls the corresponding slot in your class. The slot name is fixed and contains the name of the object in the UI file. For example, for your input "DovetailNumber", the signal "slotDovetailNumberChanged" is called, etc.

You can use qDebug again to check if these slots are called correctly. You might also want to have a look at the other scripts that come with QCAD for plenty of example code.

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 11:50 am

Ok, this problem is solved. It was an uppercase/lowercase problem.

Now something is drawn, but it doesn't look like a dovetail. The lengths are correct, but the angle of two lines is not.
qcad_dovetails1.png
qcad_dovetails1.png (3.53 KiB) Viewed 23817 times
QCAD Pro on Gentoo Linux

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 12:23 pm

I am sooo close to finishing this script.

The dovetails are drawn correctly, but at the end of the second mouse click.
qcad_dovetails2.png
qcad_dovetails2.png (5.34 KiB) Viewed 23815 times
QCAD Pro on Gentoo Linux

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 12:51 pm

I proudly present: The Dovetail Script v2.0 :-)

Thanks to Matthias Melcher for his first dove tail script, which inspired me to follow in his steps.
And thank you, Andrew, for your help.

Please feel free to include this dovetail script in the next QCAD release.
Attachments
LineDove2.zip
(6.21 KiB) Downloaded 871 times
QCAD Pro on Gentoo Linux

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 1:25 pm

Bonus: When entering a dovetail gradient of 9999 or higher you get a fine finger joint with ≤0,005 mm error, with half fingers at the ends.
QCAD Pro on Gentoo Linux

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

Re: new dovetail script

Post by andrew » Thu Feb 16, 2017 2:29 pm

Excellent, thanks! Looks great from what I've seen so far :)

Your script will be included in future QCAD releases and now lives at:
https://github.com/qcad/qcad/tree/maste ... /LineDove2

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 4931
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: new dovetail script

Post by Husky » Thu Feb 16, 2017 6:26 pm

caigner wrote:I proudly present: The Dovetail Script v2.0 :-)
Congratulation! :D

Should this script replace the old one? If not we have the same name twice ...
Husky-2017.02.16-01.png
Husky-2017.02.16-01.png (23.63 KiB) Viewed 23800 times
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

User avatar
caigner
Full Member
Posts: 83
Joined: Wed Jan 30, 2013 5:24 pm
Location: Austria

Re: new dovetail script

Post by caigner » Thu Feb 16, 2017 8:06 pm

I think the old dovetail script started as an example for scripting in QCAD. It didn't do more than draw one dovetail of fixed geometry.
I suggest to move the old script to the example scripts and replace it in its current place with my new one.
QCAD Pro on Gentoo Linux

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

Re: new dovetail script

Post by andrew » Fri Feb 17, 2017 7:53 am

caigner: yes, agreed.

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”