dwg2bmp output layer/block

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
zak
Junior Member
Posts: 11
Joined: Mon Apr 29, 2013 10:51 pm

dwg2bmp output layer/block

Post by zak » Tue Jun 06, 2017 4:58 pm

Ideally, I'd be able to specify a layer to select the output for dwg2bmp, but after looking at the documentation it seems like I should at least be able to specify a specific block. However that doesn't seem to work using the following command:

Code: Select all

$ dwg2bmp -a -b white -c -f -r 10  -block IHS_DOOR_BLOCK -o RS200-A_80x30.png RS200-A_80x30.dxf
I've verified that the block does exist, but the output is the whole drawing. While I've tried this using a block, like I mentioned earlier, I'd much rather be able to specify a layer since that is how all of these drawings are already formatted.

Thanks!

OS X 10.10.5
QCAD 3.1.5
Attachments
RS200-A_80x30.dxf
(99.99 KiB) Downloaded 389 times

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

Re: dwg2bmp output layer/block

Post by andrew » Tue Jun 06, 2017 5:55 pm

zak wrote:QCAD 3.1.5
Please note that the -block switch was added in QCAD 3.16.0:
https://qcad.org/en/changelog

You can also use -h to list all options in your version.

The correct usage is (note the "="):

dwg2bmp -block=MyBlock -f -o out.png out.dxf

zak
Junior Member
Posts: 11
Joined: Mon Apr 29, 2013 10:51 pm

Re: dwg2bmp output layer/block

Post by zak » Tue Jun 06, 2017 6:11 pm

Ah I was wondering why

Code: Select all

dwg2bmp -h 
didn't show -block. I've purchased the updated version of QCAD-CAM and the block output is working.

Any suggestions on how to output a specific layer?

zak
Junior Member
Posts: 11
Joined: Mon Apr 29, 2013 10:51 pm

Re: dwg2bmp output layer/block

Post by zak » Tue Jun 06, 2017 8:11 pm

I've another idea which would be to create a script that would select the entities on a layer, create a block, and save the modified dxf. I'd think that should be simple, but I am not yet up to speed with scripting. If anyone could point me in the right direction that would be great.

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

Re: dwg2bmp output layer/block

Post by andrew » Tue Jun 06, 2017 8:39 pm

Switching off the layers that are not to be exported would definitely be easier to achieve:

Code: Select all

    var op = new RAddObjectsOperation();
        var allLayerNames = doc.getLayerNames();
        for (var i=0; i<allLayerNames.length; i++) {
            var layerName = allLayerNames[i];
            var layer = doc.queryLayer(layerName);
            if (!isNull(layer)) {
                layer.setFrozen(true);      // true to hide (freeze), false to show. may be decided on layerName
                op.addObject(layer);
            }
        }
    }
    di.applyOperation(op);

zak
Junior Member
Posts: 11
Joined: Mon Apr 29, 2013 10:51 pm

Re: dwg2bmp output layer/block

Post by zak » Tue Jun 20, 2017 5:55 pm

That chunk of code has been super helpful. By digging into the merge tool, and elsewhere I was able get the first part working. Now I need to be able to handle some scaling. It looks like simple_modify.js will do the trick, but I haven't been able to figure out how to select the entities I want to scale.

Is there a best practice or recommended way to select or build a list of entities based on the layer?

Or is that even the right approach?

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

Re: dwg2bmp output layer/block

Post by andrew » Tue Jun 20, 2017 7:36 pm

You can get the IDs of all entities on a layer:

Code: Select all

doc.queryLayerEntities(layerId);
Or:

Code: Select all

doc.queryLayerEntities(doc.getLayerId(layerName));
You can then for example select those entities:

Code: Select all

var ids =  doc.queryLayerEntities(...);
di.selectEntities(ids);
And finally scale them by a given factor, using a given focus point:

Code: Select all

var op = new RScaleSelectionOperation(scaleFactor, new RVector(0,0));
di.applyOperation(op);
doc is your RDocument
di is your RDocumentInterface

zak
Junior Member
Posts: 11
Joined: Mon Apr 29, 2013 10:51 pm

Re: dwg2bmp output layer/block

Post by zak » Tue Jun 20, 2017 7:53 pm

Thank you, that is way better than the approach I was considering. I do really appreciate the amazingly quick response too.

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

Re: dwg2bmp output layer/block

Post by andrew » Fri Jun 30, 2017 3:27 pm

Meanwhile QCAD 3.17.2 is available with a new -layer switch (list of comma separated layers):

Code: Select all

./dwg2bmp -layer=layer1,layer2 -f -o drawing.png drawing.dxf
-zoomall might also come in handy to always zoom to all layers, even if only some are shown (useful for bitmaps that are to be overlayed on top of each other).

Code: Select all

./dwg2bmp -layer=layer1 -zoomall -background=transparent -f -o drawing_layer1.png drawing.dxf
./dwg2bmp -layer=layer2 -zoomall -background=transparent -f -o drawing_layer2.png drawing.dxf

Post Reply

Return to “QCAD 'How Do I' Questions”