[Solved] Add Custom Property to Library Item

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

[Solved] Add Custom Property to Library Item

Postby Taygete » Mon May 19, 2014 6:46 pm

Hi,

I am a new user to QCad and cad development, I have a good few years of C++, C# etc under my belt but little JavaScript.

I have been asked to create a plugin for a customer which talks to a database, I send information to the backend which is used to search the database and return results.

The idea is the customer will only need to drop items onto the drawing I provide via the QCad Library.

I worked my way through the user guide today and can see we can add a custom properties to an entity then selecting multiple entites create a Library Item, would it be possible to add custom properties to a Library item rather than the entites contained in the Library item?

There may be a reason why this is not worth while or even technically possible but I thought for my needs (and maybe others) it might be a worth while feature as I can search the document for certain properties on the Library item rather than individual entites?

The plan for the plugin I am writing is once the customer has placed the Library Items onto the drawing they will click a button which will tell the plugin to search through the drawing for items the backend is interested in, once a list is built up we can search the database. I can work around not having the custom property but thought it my be worth adding it in the future?

Thanks,

Andrew.
Last edited by Taygete on Thu May 22, 2014 10:56 am, edited 1 time in total.
Taygete
Active Member
 
Posts: 25
Joined: Wed May 14, 2014 8:53 am

Re: Add Custom Property to Library Item

Postby andrew » Tue May 20, 2014 9:15 am

Taygete wrote:would it be possible to add custom properties to a Library item rather than the entites contained in the Library item?


That's not possible at the moment since QCAD creates a block and block reference for the library item at the time when it is inserted. I.e. those objects don't exist before the insertion.

I can think of the following solution:
- A library item could contain a block definition with the same name as the file name and a single block reference to that block. That block reference could have custom properties assigned to it.
- QCAD could then copy that block reference with custom properties when inserting an item.

This functionality would have to be implemented first. At this point, QCAD would create a block recursion if a library item contains a block with the same name as the file name.

Do you think the above solution would solve the problem for your use case?
User avatar
andrew
Site Admin
 
Posts: 2539
Joined: Fri Mar 30, 2007 6:07 am

Re: Add Custom Property to Library Item

Postby Taygete » Tue May 20, 2014 9:41 am

Hi Andrew,

Your solution sounds like it should work, my current work around was going to query on block name which would be unique to each Library Item (I add for the customer).

But I think your solution would offer a lot more scope.

Thanks,

Andrew.
Taygete
Active Member
 
Posts: 25
Joined: Wed May 14, 2014 8:53 am

Re: Add Custom Property to Library Item

Postby andrew » Tue May 20, 2014 10:57 pm

This has been implemented.

You can instantly update your QCAD installation to support library items with custom properties by downloading the latest version of the file InsertBlockItem.js from the git repository at:
https://raw.githubusercontent.com/qcad/ ... ockItem.js

Save this file to <QCAD installation directory>/scripts/Block/InsertBlockItem/InsertBlockItem.js

The expected structure of a part library item with custom properties is:
- File name is for example 'myitem.dxf'.
- Contains a block definition with name 'myitem'.
- Contains a block reference to that block, typically at position 0/0. That block reference may have custom properties assigned to it.

Please let me know if that supports your use case as expected.
User avatar
andrew
Site Admin
 
Posts: 2539
Joined: Fri Mar 30, 2007 6:07 am

Re: Add Custom Property to Library Item

Postby Taygete » Wed May 21, 2014 3:15 pm

Wow Andrew,

That was quick thank you so much.

I just need to finish up some code changes I am currently making then will try it a bit later and reply here.

Andrew.
Taygete
Active Member
 
Posts: 25
Joined: Wed May 14, 2014 8:53 am

Re: Add Custom Property to Library Item

Postby Taygete » Thu May 22, 2014 10:56 am

Hi Andrew,

Just tested this and it works great, exactly what I wanted, thanks so much.

Andrew.
Taygete
Active Member
 
Posts: 25
Joined: Wed May 14, 2014 8:53 am

Re: [Solved] Add Custom Property to Library Item

Postby andrew » Thu May 22, 2014 11:02 am

Great, thanks for the feedback.
This will also be part of the upcoming 3.5.2 release.
User avatar
andrew
Site Admin
 
Posts: 2539
Joined: Fri Mar 30, 2007 6:07 am


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 0 guests

cron