• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

P3D v4 XML Functions tool

Messages
9
Country
australia
I've just started to get to grips with the XML schema. The verbose and repetitive nature of it cries out for the ability to call functions or subroutines. As far as I'm aware that's not possible, please correct me if that's wrong.

So I've created a tool to provide the ability to incorporate Functions into the code. I'm not sure of the protocol on this forum... shall I upload the tool for others to try? How do I do that?

When you're editing a gauge it only adds a single button click into the workflow. You create and edit a "source" file, from which the tool generates an "output" file. The output file is the one in the 'gauges' folder that the simulator uses.

Here's an example of a Source file, followed by the Output file that the tool generates. In the Source file note the <Function> structure near the bottom and the <Call> tags that call it.

Regards,
David

SOURCE FILE:
Code:
<SimBase.Document Type="AceXML" version="1,0">
    <Descr>AceXML Document</Descr>
    <Filename>FunctionTest Source.xml</Filename>
    <SimGauge.Gauge id="Test" ArtDirectory=".">
        <Size>300,300</Size>
        
        <Element id="Debug">
            <FloatPosition>85,80</FloatPosition>
            <GaugeText>
                <Size>100,30</Size>
                <GaugeString>Something</GaugeString>
                <FontColor>0x111111</FontColor>
                <FontFace>Consolas</FontFace>
                <FontHeight>14</FontHeight>
                <HorizontalAlign>Center</HorizontalAlign>
                <Bright>True</Bright>
            </GaugeText>
        </Element>

        <Call id="hLine1" name="HorizontalLine" top="100" left="100" scale="200 1000 /" colour="0xFFFFFF"/>
        <Call id="hLine2" name="HorizontalLine" top="120" left="120" scale="180 1000 /" colour="0x00FFFF"/>
        <Call id="hLine3" name="HorizontalLine" top="140" left="140" scale="160 1000 /" colour="0xFF00FF"/>
        <Call id="hLine4" name="HorizontalLine" top="160" left="160" scale="140 1000 /" colour="0xFFFF00"/>
        <Call id="hLine5" name="HorizontalLine" top="180" left="180" scale="120 1000 /" colour="0xFF0000"/>
        <Call id="hLine6" name="HorizontalLine" top="200" left="200" scale="100 1000 /" colour="0x00FF00"/>

        <Function name="HorizontalLine">
            <Element id="@id">
                <TopScript>@top</TopScript>
                <LeftScript>@left</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>@scale</SizeScaleScript>
                    <LineColor>@colour</LineColor>
                </HorizontalLine>
            </Element>
        </Function>

    </SimGauge.Gauge>
</SimBase.Document>

OUTPUT FILE:
Code:
<SimBase.Document Type="AceXML" version="1,0">
    <Descr>AceXML Document</Descr>
    <Filename>FunctionTest Source.xml</Filename>
    <SimGauge.Gauge id="Test" ArtDirectory=".">
        <Size>300,300</Size>
        
        <Element id="Debug">
            <FloatPosition>85,80</FloatPosition>
            <GaugeText>
                <Size>100,30</Size>
                <GaugeString>Something</GaugeString>
                <FontColor>0x111111</FontColor>
                <FontFace>Consolas</FontFace>
                <FontHeight>14</FontHeight>
                <HorizontalAlign>Center</HorizontalAlign>
                <Bright>True</Bright>
            </GaugeText>
        </Element>

            <Element id="hLine1">
                <TopScript>100</TopScript>
                <LeftScript>100</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>200 1000 /</SizeScaleScript>
                    <LineColor>0xFFFFFF</LineColor>
                </HorizontalLine>
            </Element>
            <Element id="hLine2">
                <TopScript>120</TopScript>
                <LeftScript>120</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>180 1000 /</SizeScaleScript>
                    <LineColor>0x00FFFF</LineColor>
                </HorizontalLine>
            </Element>
            <Element id="hLine3">
                <TopScript>140</TopScript>
                <LeftScript>140</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>160 1000 /</SizeScaleScript>
                    <LineColor>0xFF00FF</LineColor>
                </HorizontalLine>
            </Element>
            <Element id="hLine4">
                <TopScript>160</TopScript>
                <LeftScript>160</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>140 1000 /</SizeScaleScript>
                    <LineColor>0xFFFF00</LineColor>
                </HorizontalLine>
            </Element>
            <Element id="hLine5">
                <TopScript>180</TopScript>
                <LeftScript>180</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>120 1000 /</SizeScaleScript>
                    <LineColor>0xFF0000</LineColor>
                </HorizontalLine>
            </Element>
            <Element id="hLine6">
                <TopScript>200</TopScript>
                <LeftScript>200</LeftScript>
                <HorizontalLine>
                    <LineWidth>1</LineWidth>
                    <Width>1000</Width>
                    <SizeScaleScript>100 1000 /</SizeScaleScript>
                    <LineColor>0x00FF00</LineColor>
                </HorizontalLine>
            </Element>

    </SimGauge.Gauge>
</SimBase.Document>
 

Heretic

Resource contributor
Messages
6,830
Country
germany
Color me dumb, but I can't quite grasp any workflow inprovement from this.

I tend to build my 2D gauges piece by piece and in-sim, so even in complex, repetitive gauges, copy-paste-adapt-refresh yields instant results.
 
Messages
9
Country
australia
The benefit is in the coding, providing the advantages of Functions. Except for a single button click, the workflow is the same. Eg, Edit the code in your favourite XML editor, Save, Click the tool's button, Re-load panels in the sim.
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
I agree with Bjoern (Heretic)

Copy/Paste <Elements> is the simplest and fastest way to replicate XML code. Once you copied an element, the time you spend changing its reference values would be the same that you invest when coding one line of the function's source, and in the first case you don't need to care about parameter design.

Actually FS XML does have Macro structures to be used in RPN scripts; if properly programmed they can behave like functions (though complete code is parsed by the sim).

Tom
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
You also do have the ability to script "GoTo" forks in your logic. See the default G500 "GPS" for examples.
 
Messages
9
Country
australia
Thanks for the feedback. I don't want to sound like I'm pushing the tool, I made it for myself and I'm just offering it to anyone who's interested.

But I'm intrigued by the comments. I can think of a number of reasons why someone wouldn't want to use the tool, but you (Heretic and Tom) seem to be saying you'd prefer to copy/paste/edit blocks of similar code. It sounds like you wouldn't use Functions even if they were part of the FS9/FSX schemas.

This surprises me, I think Functions make code easier to write and manage. Parameter 'design' is no different to other languages, you invest a little time into setting up a Function then realise the benefits.

Of course the benefit will vary depending on the code's length and amount of repetition. My first 'project' is a Radio gauge, its code is quite repetitive in nature.

As far as I'm aware Macros are for scripts only, not for blocks of code like a whole Element... is this correct?

Please don't take these comments as adversarial, I'm the newbie here!

David
 

JB3DG

Resource contributor
Messages
1,325
Country
southafrica
Correct on the bit about macros. I don't think they quite understand what you have done here (downright excellent work. Would absolutely it if I still did XML gauges).
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
David,

It sounds like you wouldn't use Functions even if they were part of the FS9/FSX schemas.

But they're not, and I believe there are reasons for that.
Each programming tool -"language"- has its own characteristics, and XML format doesn't apart from that.

As far as I'm aware Macros are for scripts only, not for blocks of code like a whole Element... is this correct?

And that is the point.

When programming complex XML gauges, I would say 95 % of development time is taken by script design/coding, and 5 % by XML frame supporting that code (Elements and other structures).

Being the case, macros really make a difference; sometimes they behave like real functions.

On the other hand, copy/paste of XML structures can be a fast process once you get used with the "language".

In your example you are writing similar lines and a function might suit, but usually structures containing long scripts are not exactly the same hence turning difficult to parametrize.

Anyway, I'm speakyng for myself of course. I appreciate your offer and hope you stay on that road as I'm sure other people will find your tool very useful.


Tom
 

JB3DG

Resource contributor
Messages
1,325
Country
southafrica
Tom, when developing complex XML gauges you would be surprised how much time gets wasted scrolling through vast amounts of lines taken up by Elements and other structures. His function system ought to increase efficiency considerably for XML programmers.
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
Jon, that's not the case if you use proper tools for edition. With editors like Notepad++ you can collapse/expand structures to minimize scrolling.

I must honestly say that long time ago, in my beginings with XML code I also thought of writing some kind of functions to hande frame structures, but desisted after evaluating pros and cons.

Again, that was me; it is reasonable that others like you might find it useful.

Tom
 

Heretic

Resource contributor
Messages
6,830
Country
germany
Fair enough, David.

Johan's comment about scrolling made me think: I'd be game for a tool that manages to collapse Elements into functions and do some automated sorting. Not for use in 2D XML gauges, mind you, but to make the horribly large Modeldef.xml file from the Modeling SDK easier to work with. Despite using CTRL+F and all, working with that file is a royal PITA. I'm amazed that my index finger hasn't fallen off after all those years working with it.
 
Messages
9
Country
australia
All good points, thanks. Thinking about my motives a bit more... Prior to this I haven't encountered a language that doesn't support reusable blocks of code, and it seemed daunting and inelegant to manage dozens of similar Elements. To me it feels more structured to make high level calls to reusable code when applicable.

I get that it's not hard to use scroll & search to change a value in multiple Elements, and it can be done quickly particularly in an editor that provides code folding. But I'd rather just see and edit a single value in a Function.

Each programming tool -"language"- has its own characteristics, and XML format doesn't apart from that.

I'm sure there are excellent reasons why the FS creators chose XML, but I don't think XML was designed for efficiency when coding it manually.

When programming complex XML gauges, I would say 95 % of development time is taken by script design/coding, and 5 % by XML frame supporting that code (Elements and other structures).

Ok, accepted. In the Radio gauge that I've started as my own tutorial there are numerous lines and numbers with similar characteristics, and the Functions have reduced the code length and made it easier to tweak. And to my eyes, more structured. I don't anticipate any complex scripting so perhaps a Radio gauge is non-typical in that respect.


Thanks for the points of view.
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
I've been using Visual Studio for years, but until today I've never truly looked at the "Help" file. Lo and behold, there is a quick way to collapse/expand all [-] expanded blocks to [+] collapsed blocks:
Code:
      <!--BU_Switch_Fwd-->
[+]  <PartInfo>... </PartInfo>

      <!--TCAS_Switch_Fwd-->
[+]  <PartInfo>....</PartInfo>
Hovering the mouse over any <PartInfo>...[/PartInfo] block will popup a window showing the expanded contents.

However, because of the way the collapse is made, unless I also put a 'comment' just above the collapsed block of script, I'd have no way to identify the blocks quickly!

I've found that this does reduce the amount of on-screen clutter and makes searching and scrolling much, much faster.
 

Roy Holmes

Resource contributor
Messages
1,803
Country
us-virginia
Like many others here, I have resisted the FSX schema for the fact that it requires big globs (technical term) of code which means it takes ages to track down what you want to find.
I'm surprised that no one has mentioned the simplicity and clarity of FS9 XML code which even with 1000 lines is easy to sort out.
I know it is not structured etc but it sure is easy to work with.
Roy
 
Messages
1,468
Country
italy
I have a control gauge in the VC10 in FS9 which is about 2,000 lines long. Each element is annotated. So I just do a search for the process rather than the code.
 

Roy Holmes

Resource contributor
Messages
1,803
Country
us-virginia
the horribly large Modeldef.xml file
Fr Bill posted some time back the idea of having a unique modeldef file for each project. I took up that idea, it ends the problem and is simple to do and implement
Roy
 
Top