Duplicate Layout Block

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
dmitpon
Junior Member
Posts: 21
Joined: Sun Mar 14, 2021 10:15 am

Duplicate Layout Block

Post by dmitpon » Wed Jan 12, 2022 5:54 am

I have written a script to duplicate a layout block. But it uses the proprietary LayoutDialog class. Is it allowed to publish it on the forum or is it a violation of the license? The source code of the LayoutDialog class is not used in the script, only the method is overridden.

Code: Select all

var dlg = new LayoutDialog(doc, undefined, false);

    // override method LayoutDialog.show()
    dlg.show = function (layoutName) {
        this.dialog = WidgetFactory.createDialog(LayoutDialog.includeBasePath, "LayoutDialog.ui", EAction.getMainWindow());
        ...........................................................................
        return layout;
    };


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

Re: Duplicate Layout Block

Post by andrew » Wed Jan 12, 2022 9:42 am

Yes, that's fine. Be sure to exclude your script from the QCAD Community Edition in your init:

Code: Select all

MyAction.init = function() {
    if (!hasPlugin("PROTOOLS")) {
        return;
    }
    
    ...
};

User avatar
ryancousins
Premier Member
Posts: 307
Joined: Thu Mar 19, 2020 3:47 am
Location: Michigan, USA

Re: Duplicate Layout Block

Post by ryancousins » Thu Jan 13, 2022 4:08 pm

dmitpon,

Thank you for doing this! I'm looking forward to trying the script out as I often need to duplicate layout blocks.

dmitpon
Junior Member
Posts: 21
Joined: Sun Mar 14, 2021 10:15 am

Re: Duplicate Layout Block

Post by dmitpon » Sat Jan 15, 2022 4:58 am

ONLY FOR PRO VERSION!
DuplicateLayoutBlock.zip
(3.97 KiB) Downloaded 127 times

To duplicate the layout block, right-click on the desired layout block and select Duplicate Layout Block from the context menu

dmitpon
Junior Member
Posts: 21
Joined: Sun Mar 14, 2021 10:15 am

Re: Duplicate Layout Block

Post by dmitpon » Sat Jan 15, 2022 5:16 am

duplicate-layout-block.gif
duplicate-layout-block.gif (88.45 KiB) Viewed 2292 times

CVH
Premier Member
Posts: 1786
Joined: Wed Sep 27, 2017 4:17 pm

Re: Duplicate Layout Block

Post by CVH » Sat Jan 15, 2022 7:25 am

Thank you for your contribution. :P

There the script is that basic ...
... I now start to wonder why this wasn't implemented by Duplicate Block (BY) in the first place.

Regards,
CVH

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

Re: Duplicate Layout Block

Post by Husky » Sun Jan 16, 2022 1:16 am

dmitpon wrote:
Sat Jan 15, 2022 4:58 am

To duplicate the layout block, right-click on the desired layout block and select Duplicate Layout Block from the context menu
Looks good so far. Thank you!

Question: I noticed that the entities in a copied layout block use the same Draw Order numbers like the source. Does that doesn't causes any trouble?
Work smart, not hard: QCad Pro

If a thread is considered as "solved" please change the title of the first post to "[solved] Title...". Thanks!

CVH
Premier Member
Posts: 1786
Joined: Wed Sep 27, 2017 4:17 pm

Re: Duplicate Layout Block

Post by CVH » Sun Jan 16, 2022 5:18 am

Husky wrote:
Sun Jan 16, 2022 1:16 am
I noticed that the entities in a copied layout block use the same Draw Order numbers like the source.
Duplicate drawing orders are never an issue.
CVH wrote:
Thu Jan 13, 2022 4:59 am
e.g. Open a file, select 10 entities, MB, all 10 have order -1, save & close, re-open ...
The new drawing order of those 10 is 0-9 and correlates with their handles, the rest is shifted.
Also try:
DP or copy/paste, the draw order of the duplicate is the same as the original.
That is, until you re-open the file.
The handle is not, that is unique.

Regards,
CVH

CVH
Premier Member
Posts: 1786
Joined: Wed Sep 27, 2017 4:17 pm

Re: Duplicate Layout Block

Post by CVH » Sun Jan 16, 2022 8:40 am

dmitpon,

Entities drawn in a layout block (e.g. Viewports) that are on locked layers are not copied.
This may be intentional or not.

One can set AllowAll() for an ROperation:
https://qcad.org/doc/qcad/3.0/developer ... 52dc203696

But I don't see how that would work using CreateBlock.createBlock(...) :?

The workaround would be:
- 'As is' add layer state (YM) for safekeeping
- Unlock all layers (YN)
- Duplicate Layout (22)
- Activate the original layer state back

Regards,
CVH

dmitpon
Junior Member
Posts: 21
Joined: Sun Mar 14, 2021 10:15 am

Re: Duplicate Layout Block

Post by dmitpon » Sun Jan 16, 2022 9:46 am

Hello CVH,

Duplicate Block (BY) also does not copy entities on locked layers. Prints a warning message on the Command Line:

Code: Select all

Transaction failed. Please check for block recursions and locked or invisible layers or blocks.
IMHO, this is normal behavior

CVH
Premier Member
Posts: 1786
Joined: Wed Sep 27, 2017 4:17 pm

Re: Duplicate Layout Block

Post by CVH » Sun Jan 16, 2022 10:00 am

dmitpon wrote:
Sun Jan 16, 2022 9:46 am
IMHO, this is normal behavior
I was aware of that, it uses the same resources.
Wouldn't it be nice that a copy of a block is simply a copy without the hustle with the layer states?

Regards,
CVH

dmitpon
Junior Member
Posts: 21
Joined: Sun Mar 14, 2021 10:15 am

Re: Duplicate Layout Block

Post by dmitpon » Sun Jan 16, 2022 12:13 pm

CVH wrote:
Sun Jan 16, 2022 10:00 am
I was aware of that, it uses the same resources.
Wouldn't it be nice that a copy of a block is simply a copy without the hustle with the layer states?
I can't answer this question. For a year of work of the QCAD (more than 50 real projects), I have never experienced such a problem. Maybe I have a different workflow.

CVH
Premier Member
Posts: 1786
Joined: Wed Sep 27, 2017 4:17 pm

Re: Duplicate Layout Block

Post by CVH » Sun Jan 16, 2022 12:31 pm

dmitpon wrote:
Sun Jan 16, 2022 12:13 pm
Maybe I have a different workflow.
Maybe you don't need to or use locked layers at all. :wink:
I many cases I can't work without.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”