How to use qcad enumeration objects in a script?

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
mrhickman53
Active Member
Posts: 25
Joined: Thu Sep 07, 2023 1:17 am
Location: USA

How to use qcad enumeration objects in a script?

Post by mrhickman53 » Thu Nov 14, 2024 5:40 pm

My general goal is to create shapes from information in a csv file and store the shapes in an array till I am ready to create a document and place entities into the document. I am currently working with RTextData, RPolyline and RLine. While it is not strictly necessary for my application I have been experimenting with querying the references I've stored in an array in order to determine the type of object is being referenced. All RShapes have a method, getShapeType() that returns a value from the enumeration:
<code>
Type
enum RShape::Type
Enumerator
Unknown
Point
Line
Arc
Circle
Ellipse
Polyline
Spline
Triangle
XLine
Ray
</code>

How is this enumeration accessed in a script? RShape.getShapeType() returns a value from this enumeration, but I would like to test against the key, not the value. How would this be performed?

The RTextData uses getType(), which returns a value from a different enumeration, which is unfortunate, but a separate issue. I would expect the same procedure to access the key associated with the value would apply.

If the answer to this is obvious from the documentation, what documentation am I not apparently aware of?

Thanks.

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

Re: How to use qcad enumeration objects in a script?

Post by andrew » Thu Nov 14, 2024 5:46 pm

In a script, you can use

Code: Select all

RShape.Line
RShape.Arc
...

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

Re: How to use qcad enumeration objects in a script?

Post by CVH » Fri Nov 15, 2024 12:48 am

Hi,
mrhickman53 wrote:
Thu Nov 14, 2024 5:40 pm
The RTextData uses getType(), which returns a value from a different enumeration, which is unfortunate, but a separate issue. I would expect the same procedure to access the key associated with the value would apply.
I think that the main difference is RShape's vs REntity's

Shapes are low-level mathematical representations.
You will find them in the Math module, these are nothing compared with drawing entities.
A text or a dimension and onther are part of the Entity module.

It is not uncommon to use the functions in library.js to diversify.
For example:
- isLineEntity(obj)
- isArcEntity(obj)
- isTextEntity(obj)
Or
- isLineShape(obj)
- isArcShape(obj)

Regards,
CVH

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

Re: How to use qcad enumeration objects in a script?

Post by CVH » Fri Nov 15, 2024 9:14 am

mrhickman53 wrote:
Thu Nov 14, 2024 5:40 pm
My general goal is to create shapes from information in a csv file and store the shapes in an array till I am ready to create a document and place entities into the document.
For the record: Menu .. Import/Export .. Draw From CSV creates drawing entities based on commands in a CSV.
DrawFromCSV is part of the open source.

It doesn't really store intermediates in an array.
If all validates well, an new entity is added to an operation, continuing with the next entry.
In the end all new objects are added by applying the operation.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”