text position

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
Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

text position

Post by Surendranath » Sun Jan 13, 2013 3:18 pm

Thanks!

The following code inserts the text always at (0,0).

Code: Select all

var pos = event.getModelPosition();	
var text = new RTextEntity(this.getDocument(), 
    new RTextData(
              new RVector(pos.x,pos.y),   // position 
              new RVector(pos.x,pos.y),   // alignment point
              2.0,                 // height
              2.0,                 // text width (ignored for now)
              RS.VAlignTop,         // alignments
              RS.HAlignCenter,
              RS.LeftToRight,
              RS.Exact,
              1.0,          // line spacing factor
             "10 \u03bc F 100 \u03a9",   // some random text for checking
              "Arial",      // font
              false,        // bold
              false,        // italic
              0.0,          // angle
              false         // simple text without formatting
    )
);	
		
op.addObject(text);
What am I doing wrong?

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

Re: text position

Post by andrew » Mon Jan 14, 2013 11:03 am

I assume you already looked into the contents of pos?

e.g.

qDebug(pos)

Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: text position

Post by Surendranath » Mon Jan 14, 2013 12:04 pm

I did not know about this qDebug(pos)

but if I replace pos.x and pos.y with numerical values, the effect is same.

The text appears at 0,0.

Is there any script which allows me to insert a block after getting the name from the user, add some text at the insertion position.
Any good books you could suggest picking up ecma script. (I know java.)

Thanks

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

Re: text position

Post by andrew » Mon Jan 14, 2013 1:27 pm

Not sure what is wrong, the code looks fine. Can you try to do a text.move(pos) before adding it to the operation?
Is there any script which allows me to insert a block after getting the name from the user, add some text at the insertion position.
Please have a look at the scripts provided in the scripts directory of every QCAD installation. In particular the ones in scripts/Examples
E.g. scripts/Examples/BlockExamples/ExAddBlock/ExAddBlock.js
Any good books you could suggest picking up ecma script. (I know java.)
Please note that ECMAScript is the correct name of what is also known as JavaScript. There are plenty of resources on the web to learn JavaScript and to solve common problems, example algorithms and functions, etc.

Surendranath
Junior Member
Posts: 16
Joined: Mon Jan 07, 2013 9:43 am

Re: text position

Post by Surendranath » Mon Jan 14, 2013 2:18 pm

text.move(pos) works fine.

Thanks.

I have been going through the scripts directory to pick some useful code which with a little modification would serve my purpose.
It is bit time consuming and sometimes like groping in the dark. If a particular line is wrong, I have to close and restart qcad which is
a bit of a bother.(-always-load-scripts option does not work).

I will keep trying.

Best wishes

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

Re: text position

Post by andrew » Mon Jan 14, 2013 2:36 pm

-always-load-scripts has been fixed for the next snap-shot release:
http://www.ribbonsoft.com/bugtracker/in ... ask_id=745

Hopefully I will have time to compile a snap-shot release sometime next week.

If it helps, you might want to automatically launch your tool at start up:
./qcad -exec ./scripts/Path/To/MyScript/MyScript.js

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”