Hi ,there
I am a newbie to QCAD programming.
I want to rotate lines with some degree for learning how to code with QCAD.
So I have given a try to write a simple GUIACTION test programming, but it does not works as expect in QCAD UI ( rotating a line with 90 degree)
hope someone can help me find problems in the code beblow ,thanks so much.
static RTransaction addObjOp(RDocumentInterface* di, const QSharedPointer<RObject>& obj) {
RAddObjectOperation* op = new RAddObjectOperation;
op->addObject(obj);
return di->applyOperation(op);
}
void demo_rotation(RDocumentInterface* di,RDocument& doc)
{
//1.block
QString blkName = "TestBlk";
QSharedPointer<RBlock> blk(new RBlock(&doc, blkName, RVector(0,0)));
addObjOp(di, blk);
RBlock::Id blkId = doc.getBlockId(blkName);
// 2. a horiztonal line starting from (0,0) to (10,0)
QSharedPointer<RLineEntity> lineInBlock(new RLineEntity( &doc, RLineData(RVector(0,0), RVector(10,0))));
lineInBlock->setBlockId(blkId);
addObj(di, lineInBlock);
REntity::Id childLineId = lineInBlock->getId();
// 3) switch to model space, one blockref for rotation,one without rotation
doc.setCurrentBlock(doc.getModelSpaceBlockId());
// 3.1) one without rotation,horizontal line
{
RBlockReferenceData brd(blkId,
/*position*/ RVector(0,0),
/*scale*/ RVector(1,1,1),
/*rotation*/ 0.0);
QSharedPointer<RBlockReferenceEntity> br(new RBlockReferenceEntity(&doc, brd));
br->setBlockId(doc.getCurrentBlockId());
addObjOp(di, br);
}
// 3.2) rotation 90 degree
{
RBlockReferenceData brd(blkId,
/*position*/ RVector(0,0),
/*scale*/ RVector(1,1,1),
/*rotation*/ M_PI/2);
QSharedPointer<RBlockReferenceEntity> br(new RBlockReferenceEntity(&doc, brd));
br->setBlockId(doc.getCurrentBlockId());
addObjOp(di, br);
}
di->regenerateScenes();
di->repaintViews();
}
How to Rotate a BlockReferenceEntity by code
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
-
- Registered Member
- Posts: 1
- Joined: Fri Sep 19, 2025 11:29 am
-
- Premier Member
- Posts: 4919
- Joined: Wed Sep 27, 2017 4:17 pm
Re: How to Rotate a BlockReferenceEntity by code
Hi, and welcome to the QCAD forum.
First:
Please include code on the forum in a code panel.
Edit your topic, select the textual code and hit the [</>] button above the text area.
Same for creating a new post or replying to one.
Second:
How do you intend to run this code?
I presume that it is written in C++ and then your sole option would be as a plugin
Perhaps as an RCC Plugin, see tutorial: Creating an RCC Plugin
The other options are a Script Add-on, a simple script to execute (with GE or XC) or a Command Line script.
Scripts are written in ECMAScript.
Also see the tutorial: Script Programming
Not a specialist on the C++ level myself.
If your code creates a Block definition with a line in it and inserts a Block Reference angled at zero rads ...
But doesn't for a different angle ...
Are you sure that M_PI is defined without including something?
Regards,
CVH
First:
Please include code on the forum in a code panel.
Edit your topic, select the textual code and hit the [</>] button above the text area.
Same for creating a new post or replying to one.
Second:
How do you intend to run this code?
I presume that it is written in C++ and then your sole option would be as a plugin
Perhaps as an RCC Plugin, see tutorial: Creating an RCC Plugin
The other options are a Script Add-on, a simple script to execute (with GE or XC) or a Command Line script.
Scripts are written in ECMAScript.
Also see the tutorial: Script Programming
Not a specialist on the C++ level myself.
If your code creates a Block definition with a line in it and inserts a Block Reference angled at zero rads ...
But doesn't for a different angle ...

Regards,
CVH