Automate Creating Hatches with Specific Properties

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
BrianZ111
Newbie Member
Posts: 3
Joined: Sun Feb 05, 2023 9:05 pm

Automate Creating Hatches with Specific Properties

Post by BrianZ111 » Fri Jun 09, 2023 1:18 am

Is it possible to write a script to do the following:
  1. Select all entities on a layer
  2. Hatch from selection
  3. Set hatch to be solid, specify color and alpha
  4. Move hatch to a separate layer
All four steps automated would be ideal but the main thing I don't want to do manually for every layer is setting the color and alpha. What I need to set them to is different for every layer and I don't want to have to keep looking back at my reference to what I need to input into the properties. I just want a series of *.js files that I pick the right one to run.

I spent a few hours searching around the forum and playing around with code but wasn’t able to get anywhere. Closest I got was with this thread: https://qcad.org/rsforum/viewtopic.php? ... ary#p21671

I wasn’t able to figure out how to change addBoundry in the above thread to work with the selected entities though.

Thanks for any help.

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

Re: Automate Creating Hatches with Specific Properties

Post by CVH » Fri Jun 09, 2023 5:11 am

BrianZ111 wrote:
Fri Jun 09, 2023 1:18 am
Is it possible to write a script to do the following:
Yes, for sure, but there are some conditions to meet.
The entities on the layer in question should form one or more perfectly closed contours.
Entities in the drawing are of the type REntity() or more specific RLineEntity, RArcEntity, ...
Not all types of entities can readibly be part of a polyline, e.g. ellipses, blocks, text, ...

You need to merge them at shape level to an RPolyline.
Matching endpoints, reversing if required and chaining them until you have a closed contour.

In the GUI we do that with Polyline from Selection (OC) what is part of QCAD Pro.
https://www.qcad.org/rsforum/viewtopic. ... 567#p36567
Make sure you have read Andrew's last entry there.
This will turn everthing in selection to one or more polyline entities if possible and closed if so.
That starts with selecting everything on a given layer.
Calling PolylineFromSelection.js (= QCAD Pro)
Filtering the resulting selection on closed RPolylineEntity

These closed polylines can then be hatched with again a Pro feature.
Or directly by creating one or more RHatchEntity as in the given example.
Remark that a hatch has loops and boundary shapes.
boundary shapes can be one closed polyline or a list of proper chained and oriented shapes.
One could already set the specific layer of the newly formed RHatchEntity before adding it.

Changing the layer of an entity is not a big deal.
After querying it from the drawing simply change the layer and put it back.
Best done with an RModifyObjectOperation.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”