Create Multi-Line RTextData with ECMA

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
wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Create Multi-Line RTextData with ECMA

Post by wildspidee » Fri Jan 30, 2015 11:26 pm

One of my dynamic text additions to my drawing requires a line return. I found reference to the "\P" in another forum post and tried to incorporate it. Unfortunately, it just prints out and doesn't generate a line return.

I am concatenating two variables as the QString and would like the second one to be on a new line. The RTextData is set to Simple false, so I should be able to do it. What would the syntax be for this?

Code: Select all

    var fileText = new RTextData(
        l9_10.getMiddlePoint(),                 
        l9_10.getMiddlePoint(),               
        0.5,         
        1.0,            
        RS.VAlignBottom,       
        RS.HAlignLeft,
        RS.LeftToRight,
        RS.Exact,
        1.0,                
        printFile + '\P' + dateFile,         // QString - the text
        "Arial",    
        false,    
        false,      
        (0),         
        false         
    );
Thank you.

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

Re: Create Multi-Line RTextData with ECMA

Post by andrew » Sat Jan 31, 2015 12:01 am

Try

Code: Select all

printFile + '\\P' + dateFile
Backslash is used to mark special sequences such as ASCII line breaks (\n), tabs (\t), etc. To get an actual backslash into a string, you have to use '\\' in JavaScript.

wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Re: Create Multi-Line RTextData with ECMA

Post by wildspidee » Sat Jan 31, 2015 12:13 am

Worked perfectly, of course. Thanks Andrew.

By the way, I have the entire sequence running. It opens the QT dialog for measurements, saves them to XML, opens the XML file, reads all the data and draws the pattern. I had to make some changes to the XML formatting to set my variables, but it runs perfectly now.

I have several more patterns to script out, but the process should be exactly the same. It should be easier from here. I may need some assistance packaging it up as a plug-in, but that won't be for a bit.

I couldn't have done this without all your help.

Lori

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

Re: Create Multi-Line RTextData with ECMA

Post by andrew » Sat Jan 31, 2015 12:21 pm

OK, good to hear!

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”