Wallchart and 'Run Script'

This forum is for 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: Clive, andrew, Husky

Wallchart and 'Run Script'

Postby riverbuoy » Sun May 11, 2014 10:45 pm

Wallchart
Several years ago I was asked if I could draw a wallchart (or wall-planner). Nothing fancy, just a simple grid with the day numbers 1 to 31 down the left hand side, and months across the top, starting with october through to september of the following year. At the time I was using Autocad, and thought 'No problem'. Then they asked if I could put the name of the day in each box, and highlight in some way, every weekend.
I realised immediately that doing this manually would be tedious, time-consuming and error-prone. So I set about writing an autolisp routine to draw the chart automatically.
This script draws that same wallchart in QCad. It is self-contained in that it needs no external files to be included, and can therefore be stored anywhere on your computer.
Initially I wrote this to use the '-autostart' command line option, but then changed it to use the '-exec' command line option. The exec option starts QCad normally and then runs the script as the first command. I did this so that I could use Qt's QInputDialog class to get the two arguments needed by this script, 'Start Year' and 'Start Month'. (See the two functions 'getYearArg()' and getMonthArg()').
This worked fine, but I still had to use the command line to run it. I thought it would be nice if I could run this script from inside QCad, at any time and also be able to run it more than once. So I came up with the command 'Run Script'.

Run Script
This command is in the File menu between 'Close' and 'Bitmap Export'. It is the same as File->Open, but instead of listing drawing files, it lists script files (*.js). For the shortcut command I chose 'XC', as RS, XS etc are already taken.
Now I can run the wallchart script by selecting it in the file open dialogue, and it will draw the wallchart in the current drawing.
Two points to note.
First if your script contains an error this command does not return any information about what or where the error is.
Secondly if your script requires arguments, this command does not ask for arguments. Your script needs to handle getting the arguments. For example see Wallchart_en.js and the two functions, 'getYearArg()' and 'getMonthArg()'.

xcExample
This is a simple script to check that 'run script' works. It simply draws a small triangle in the current drawing.


LineP
This directory is a copy of the Line2PEx directory, renamed to avoid name collisions. You can use 'run script' to run 'LinePInit.js' to create a new RGuiAction named LineP. The init file only contains one function. The function won't run without being called. You need to add a line to the end of LinePInit,js.

init("/absolute/path/to/Scripts/Qcad/LineP");

Change the path to point to the directory where you have saved LineP.

Next you need to change the 'include' line in LineP.js.

include("/absolute/path/to/QCAD/qcad-3.5.0.0/scripts/Draw/Line/Line.js");

Change the path to point to the Line.js file.

Having made these changes you can use 'run script' to run LinePInit.js. This will add LineP to the Draw->Line menu, and the toolbar. Choosing the menu item or toolbar icon will run the command. (It is exactly the same as Line2PEx).

The attached file contains two directories, RunScript and Scripts.
Copy RunScript to QCad's /scripts/File directory to add the run script command.

Next you can copy the Scripts directory to anywhere on your disk.
I have included several language versions of wallchart, using Google translate, so I can't guarantee they are correct. If you want to change them, use a text editor that supports utf8 format. I have added an underscore and two letters to indicate the language. So 'Wallchart_en.js' is the english version. 'Wallchart_fr.js' is the french version etc.
Attachments
RunScript.zip
(70.18 KiB) Downloaded 18 times
riverbuoy
Active Member
 
Posts: 37
Joined: Thu Oct 03, 2013 5:37 pm

Return to QCAD 3 ' script Add-On & Plug-in challenge '

Who is online

Users browsing this forum: No registered users and 2 guests