Page 1 of 1

[Solved] Add Custom Property to Library Item

Posted: Mon May 19, 2014 6:46 pm
by Taygete
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.

Re: Add Custom Property to Library Item

Posted: Tue May 20, 2014 9:15 am
by andrew
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?

Re: Add Custom Property to Library Item

Posted: Tue May 20, 2014 9:41 am
by Taygete
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.

Re: Add Custom Property to Library Item

Posted: Tue May 20, 2014 10:57 pm
by andrew
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.

Re: Add Custom Property to Library Item

Posted: Wed May 21, 2014 3:15 pm
by Taygete
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.

Re: Add Custom Property to Library Item

Posted: Thu May 22, 2014 10:56 am
by Taygete
Hi Andrew,

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

Andrew.

Re: [Solved] Add Custom Property to Library Item

Posted: Thu May 22, 2014 11:02 am
by andrew
Great, thanks for the feedback.
This will also be part of the upcoming 3.5.2 release.