QCAD Project

Post to this forum to introduce yourself to this forum if you are new here. You might want to include some information about the work you are doing or planning to do with QCAD.

Moderator: andrew

Post Reply
cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

QCAD Project

Post by cjh » Tue Jul 19, 2016 10:19 pm

Hi!

I recently started working at a small control system business and I'm looking to replace AutoCAD with something a little more tailored to our needs. 16 years down the line, AutoCAD LT 2000 doesn't quite cut it. Newer versions of AutoCAD can handle some of the tasks I have planned, but if I can do these myself with a bit of programming, the purchase of full-blown AutoCAD (not LT*) is not justified. I've spent the last week learning ECMAscript and going through the QCAD tutorials.

My plan is to automate time consuming parts of drawing creation.
Automation plans include the following topics.
  • Title Block + Page Numbering
  • Part Library
  • Bill of Materials
  • Network Overview production
  • PDF export on all drawings in a folder into a single PDF
  • Integration with Microsoft Access database

Integration with the Access database is the key to the automation process.
All of the data required for Title Blocks + BOMs has already been entered into an Access database, so it is currently a massive waste of time to retype the data in AutoCAD.

Here's more detail on each of the points.
1. Title Block + Page Numbering
I currently have a Title Block with attributes (ex. JobName, JobNumber, JobAddress, Architect, Contractor, etc.).
Image
All of this information is previously entered into an Access database when the job is booked.
I need to query a table in my Access database to find the information, and fill the block attributes of the TitleBlock.
Page numbering is done in this format "[n] of [nTotal]." I can have a script count the number of drawings in the working directory to find nTotal, and require user input for individual page number [n].

2. Part Library
Our part library right now consists of a massive AutoCAD drawing with frequently used parts in it. No one knew exactly how blocks in AutoCAD worked and it just never became a priority. The QCAD part browser opens the door to MASSIVE improvement. I plan on having a script that users can run on blocks to add a relation between PartNames in the database and the blocks in the Part Library. This will facilitate easy production of Bills of Materials.

3. Bill of Materials
Image
Part information stored in Access will make BOM production much easier. The database stores Part Names/Descriptions that need to end up on the Bill of Materials. By linking parts in the Part Library to the database entries, I can pull the text into QCAD. I'm not sure what the best method of storing the BOM info is. I was thinking of using a block for each entry with the following attributes: [BlockRefID] [Abbreviation] [Quantity] [PartName] [PartDescription], but I need an overarching block to maintain headers/formatting. Is there a such thing as a dynamic block that I can use/create? I'm open to suggestions here.

4. Network Overview Production
Image
I'm not too concerned about this - it's pretty low on the priority list. I want to build a widget that takes user input to determine a quantity of blocks to insert onto a drawing. These blocks will be placed in a grid. I'll have to figure out how to store the input used for the generation of each network overview. This is similar to a persistent widget, but I need the data specific to the drawing in question to remain persistent.

5. PDF export on all drawings in a folder into a single PDF
This seems like it can be done with a simple script, but I may have to use a tool such as ghostscript to compile all of the output into a single PDF.

6. Integration with Microsoft Access database
This looks like it will be the biggest challenge. To be honest, I have not spent enough time looking into this yet to come up with a solid plan. Previous posts on the QCAD forum mentioned that writing a driver would be necessary, but I see that QT already has an ODBC driver. Is it possible to tap into that? I'll be researching this heavily soon.

I know this is a boatload of info to digest, but let me know if anyone has any suggestions!

Thanks,

Connor

cjh
Active Member
Posts: 31
Joined: Tue Jul 12, 2016 4:51 pm

Re: QCAD Project

Post by cjh » Thu Jul 21, 2016 5:24 pm

Hi!
Mods - if you want to move this thread to another section, please do so.
Maybe we could break the solutions down in the 'Developers and Contributors' section?

For now, I'll post my progress here.
I have figured out how to connect to my Access database using ODBC.
Steps:
1. Find out the version of QT running behind QCAD.
Using the ODBC driver from a newer/different version of QT did not work.
- In QCAD 3.15.4, Help --> About --> Qt Version = 5.5.1
2. Download/Install Qt 5.5.1
3. In the Qt 5.5.1 installation directory, find Plugins\sqldrivers\qsqlodbc.dll
4. Copy qsqlodbc.dll to the QCAD installation directory
Default: C:\Program Files\QCAD\plugins\sqldrivers\
5. Make sure your access database is configured in Data Sources (Windows machine).
6. Set up the QT ODBC connection in ECMAscript.
I used the QCAD\scripts\Misc\Tutorials\MenusAndToolBars\MyAction.js as a template to make my own custom menu item.

In MyAction.js, the beginEvent function only prints out a message to the user ("MyAction() is running...").
I changed this to run a test connection to my database.

***NOTE: this is meant to be a TEST only***

Code: Select all

BCS_TestAction.prototype.beginEvent = function() {
    // call base class implementation of beginEvent:
    BCS_Scripts.prototype.beginEvent.call(this);
    // get main application window:
    var appWin = EAction.getMainWindow();
    // name of ODBC connection is "BCS" 
    // can be found in Data Sources (ODBC) in Windows
    var db = QSqlDatabase.addDatabase("QODBC", "BCS");
	db.setDatabaseName("BCS");
	var success = db.open();
	
	if (success) {
		// create/execute a query to pull a single record from database
		var sql = "SELECT ID, JobName FROM JobT WHERE ID = 24;";
		var query = new QSqlQuery(db);
		query.exec(sql)
		while(query.next()) {
			appWin.handleUserMessage("ID = " + query.value(0).toString() + "\n" +
                               "Name = " + query.value(1).toString());
		}
	} else {
		appWin.handleUserMessage("Opening db = Failure" + " " + db.lastError().text());
	}
	db.close();
    // terminate the action
    this.terminate();
};
This prints the JobName of the record from the table JobT with ID=24. Success!

Now I will figure out how to set the attributes of the TitleBlock to the data I pull in from the database.

Post Reply

Return to “Introduce Yourself”