P3D v4 Capturing a source airport from a DirectTo function

#1
Hi guys,
I've been fiddling with a FMS utility (the pandoras box of XML it seems), and have run into some trouble.

When I use a Direct To function, it appears that when no flightplan is loaded, the sim creates a destination as specified by me, and an origin to the lat lon coords of my aircraft. What I'd like to do however, is create the destination using DirectTo, but then replace the origin with my closest airport.

I've tried this using a direct to function, then adding a new waypoint at zero of my closest airport, but I'm not sure if it's all supposed to work that way.

I apologise that I've not attached code as yet, but can someone tell me if the approach I'm aiming for seems sound?

David.
 
#2
After creating the flight plan using DirectTo and adding the closest airport at Index 0, then delete waypoint index 1, the current aircraft location (which was Index 0 before adding the closest airport at 0)

I'll need to go through this again to double check FlightPlanActiveWaypoint, but I guess it will return 1 - its been a while and my memory is foggy.

Anyway, as I recall, it should work this way.

Bob
 
#3
Hi David

The following is what I use .
The ICAO entry is by keyboard .

Step 1. This creates the DTO (Direct To)
Code:
            (L:DAT49 mode,enum) 4 == (L:Display mode,enum) 1.5 < (L:TypEntry, enum) 1 == and and
              if{ 'A' (>@c:IcaoSearchStartCursor)
                (L:F111-WPT-4,number) chr (L:F111-WPT-3,number) chr
                (L:F111-WPT-2,number) chr (L:F111-WPT-1,number) chr scat scat scat (>@c:IcaoSearchEnterChar)
                0 (>@c:FlightPlanWaypointIndex)
                (@c:IcaoSearchMatchedIcaosNumber,number) 0 >
                    if{ (@c:IcaoSearchCurrentICAO) (>@c:FlightPlanNewWaypointICAO) }
                1 (>@c:FlightPlanDirectToDestination)
                0 (>L:FPEntry, enum)
                0 (>L:F111-WPT-1,enum) 0 (>L:F111-WPT-2,enum) 0 (>L:F111-WPT-3,enum) 0 (>L:F111-WPT-4,enum)    }

Step 2. This creates a Replacement or a swap for the 0 (zero) Index waypoint in one click .
Code:
           (L:DAT49 mode,enum) 4 == (L:Display mode,enum) 1.5 < (L:TypEntry, enum) 2 == and and
               if{ 'A' (>@c:IcaoSearchStartCursor)
                (L:F111-WPT-4,number) chr (L:F111-WPT-3,number) chr
                (L:F111-WPT-2,number) chr (L:F111-WPT-1,number) chr scat scat scat (>@c:IcaoSearchEnterChar)
                0 (>@c:FlightPlanWaypointIndex)
                (@c:IcaoSearchMatchedIcaosNumber,number) 0 >
                    if{ (@c:IcaoSearchCurrentICAO) (>@c:FlightPlanNewWaypointICAO) }        
                (L:F111_Wpt_Sum, number) (>@c:FlightPlanAddWaypoint)
                (L:F111_Wpt_Sum, number) 1 + (>@c:FlightPlanDeleteWaypoint)              
                0 (>L:FPEntry, enum)
                0 (>L:F111-WPT-1,enum) 0 (>L:F111-WPT-2,enum) 0 (>L:F111-WPT-3,enum) 0 (>L:F111-WPT-4,enum)
                0 (>C:fs9gps:IcaoSearchStopCursor) }
Notice that I use " L:F111_Wpt_Sum, number " in lieu of the Flight Plan Index number so that I can replace any Wpt in a Flt Pln ,
in your case you would use 0 (zero) .

It is important to note that when you create a DTO ( Direct To ) it is a Pure DTO , now if you make any change to that
DTO it immediately becomes a FP ( Flight Plan ) .
You may think of it as still being a DTO , however the GPS module will not recognise it as a DTO following any changes no matter
how insignificant the change might be .
To understand the significance of this aspect please read the following link .
https://www.fsdeveloper.com/forum/threads/problems-with-fms-direct-to-wpt.437338/

Cheers
Karol
 
Last edited:
#4
Thanks Karol, Bob... :)

I've used both your resources as part of this process. I'll check it later today and see if I can make some magic happen. :)

Changing the process to a Flightplan is what I'm after. The aim is that the user can have the ability to create a two point (DEP and DEST) flightplan using the DEP and ARR fields. Though the easiest way I can think off currently to get me some of the way there is simply to have the user enter the destination ICAO and the system populate the plan from the users nearest airport (normally where-ever he or she is stationary.)

BTW Karol, I think I met you a few years back now at the Orbx stand at Avalon, where there was lots of chatting about the F-111. :) If that's so, it's good to see you again.

David.
 
#5
If the destination is an airport, then the user has to enter only the 3 or 4 character Ident, not the full 12 character ICAO. I think direct keyboard entry is an easy method for this. Karol notes the same, above.

Setting the origin to nearest airport is easy using NearestAirportCurrentICAO.

Bob
 
#6
Hi David

Yes , when I saw your original post it immediately took me back to our meeting at the Avalon airshow , wonderful times , good to see you too .

To the best of my knowledge if you start a flight without a Flight plan then the only way to create a Flight plan is by initially creating a DTO ,
once you have created that DTO you can then add as many Wpts as you desire , even creating a very long Flight Plan .
To add the extra Wpt's you need to create a number generator that allows you to produce the Flight Plan Index numbers , these numbers
are entered with each Wpt ( ICAO ) as it is added , then the next one , and so on , it is simple .

You might have a Plan with 30 Wpt's , then you might wish to insert a Wpt between Index 15 and 16 , just generate the number 16 and add
your new Wpt , it's that easy , of course you might wish to add a series of Wpt's to form a diversion around bad weather , just add that series
at the same place , it's extremely flexible .
You can also do a round robin flight , eg ; Brisbane YBBN to Sydney YSSY and back to Brisbane with as many intervening Wpt's as you desire.

At any time you can replace your current Flt Pln simply by creating a DTO , then building up a new series of Wpt's .

You can do the Flt Plan on the ground , or at any time or stage during any flight , your autopilot will enact thes Flight Plans .

It is incredible what you can do with these simple Flight Plan Editors .

Step 1 . Following adds a Wpt to your DTO or FP ,
Code:
           (L:DAT49 mode,enum) 4 == (L:Display mode,enum) 1.5 < (L:TypEntry, enum) 0 == and and
               if{ 'A' (>@c:IcaoSearchStartCursor)
                (L:F111-WPT-4,number) chr (L:F111-WPT-3,number) chr
                (L:F111-WPT-2,number) chr (L:F111-WPT-1,number) chr scat scat scat (>@c:IcaoSearchEnterChar)
                0 (>@c:FlightPlanWaypointIndex)
                (@c:IcaoSearchMatchedIcaosNumber,number) 0 >
                    if{ (@c:IcaoSearchCurrentICAO) (>@c:FlightPlanNewWaypointICAO) }
                (L:F111_Wpt_Sum, number) (>@c:FlightPlanAddWaypoint)
                0 (>L:FPEntry, enum)
                0 (>L:F111-WPT-1,enum) 0 (>L:F111-WPT-2,enum) 0 (>L:F111-WPT-3,enum) 0 (>L:F111-WPT-4,enum)    }
Step 2. This first part detail how the Index number is created ,
Code:
<!-- ZZZZZZZZZZZZZZZThumbwheel text display    TENS and UNITS ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ   -->           
    <!--Thumbwheel text display    #2B2B3B  TENS and UNITS-->   
            <Element>
                <Position X="138" Y="150"/>
              <FormattedText X="40" Y="10" Font="Tahoma" FontSize="8" LineSpacing="10" Adjust="LEFT" Color="#349F34" Bright="Yes">
            <String>%"SEQ"%</String>
          </FormattedText>
            </Element>
            <Element Name="Box">   
              <Position X="104" Y="153"/>
              <Rectangle Width="32" Height="20" Color="#2B2B3B" LineWidth="2" Bright="Yes"/>           
            </Element>
            <Element Name="10 BORDER">   
              <Position X="108" Y="156"/>
              <Rectangle Width="12" Height="13" Color="#2B2B2B" Bright="Yes"/>           
            </Element>
            <Element>
              <Position X="109" Y="158"/>
              <Text X="10" Y="9" Bright="Yes" Length="2" Font="Arial" Color="0xB9B9B9" Adjust="Center" VerticalAdjust="Center" Multiline="No" Fixed="No">
                <String>%((L:F111_Wpt_10s, number))%!d!%</String>
              </Text>
            </Element>
            
            <Element Name="1 BORDER">   
              <Position X="119" Y="156"/>
              <Rectangle Width="12" Height="13" Color="#2B2B2B" Bright="Yes"/>           
            </Element>
            <Element>
              <Position X="121" Y="158"/>
              <Text X="10" Y="9" Bright="Yes" Length="2" Font="Arial" Color="0xB9B9B9" Adjust="Center" VerticalAdjust="Center" Multiline="No" Fixed="No">
                <String>%((L:F111_Wpt_1s, number))%!d!%</String>
              </Text>
            </Element>
    <!--Thumbwheel  SUM defined  -ADDS tens and units-->               
            <Element>
              <Position X="55" Y="3"/>
              <Text X="1" Y="1" Bright="Yes" Length="3" Font="Arial" Color="0x000000" Adjust="Center" VerticalAdjust="Center" Multiline="No" Fixed="No">
                <String>%((L:F111_Wpt_10s, number) 10 * (L:F111_Wpt_1s, number) + (&gt; L:F111_Wpt_Sum, number))%!02d!%</String>
              </Text>
            </Element>
Step 3. This is the mouse section to set the Index numbers detailed at Step 2 ,
Code:
    <!-- Thumbwheel setting for Wpt index "SEQ"  -->
    <Macro Name="Button1">(M:Event) 'RightSingle' scmp 0 == if{ (L:F111_Wpt_10s, number) -- 0 max (&gt; L:F111_Wpt_10s, number) }
        (M:Event) 'LeftSingle' scmp 0 ==  if{ (L:F111_Wpt_10s, number) ++ 9 min (&gt; L:F111_Wpt_10s, number) }
        (M:Event) 'WheelUp' scmp 0 == if{ (L:F111_Wpt_10s, number) ++ 9 min (&gt; L:F111_Wpt_10s, number) }
        (M:Event) 'WheelDown' scmp 0 == if{ (L:F111_Wpt_10s, number) -- 0 max (&gt; L:F111_Wpt_10s, number) }</Macro> 
        <Area Left="102" Top="150" Width="16" Height="25">
            <Tooltip>Tens</Tooltip>
            <Click Kind="LeftSingle+RightSingle+WheelUp+WheelDown">@Button1</Click>
            <Cursor Type="Hand" />
        </Area>
 
    <Macro Name="Button2">(M:Event) 'RightSingle' scmp 0 == if{ (L:F111_Wpt_1s, number) -- 0 max (&gt; L:F111_Wpt_1s, number) }
        (M:Event) 'LeftSingle' scmp 0 ==  if{ (L:F111_Wpt_1s, number) ++ 9 min (&gt; L:F111_Wpt_1s, number) }
        (M:Event) 'WheelUp' scmp 0 == if{ (L:F111_Wpt_1s, number) ++ 9 min (&gt; L:F111_Wpt_1s, number) }
        (M:Event) 'WheelDown' scmp 0 == if{ (L:F111_Wpt_1s, number) -- 0 max (&gt; L:F111_Wpt_1s, number) }</Macro> 
        <Area Left="119" Top="150" Width="16" Height="25"> <Position X="119" Y="154"/>
            <Tooltip>Units</Tooltip>
            <Click Kind="LeftSingle+RightSingle+WheelUp+WheelDown">@Button2</Click>
            <Cursor Type="Hand" />
        </Area>
NOTE ; You will notice that in Step 2 the index number ( L:F111_Wpt_Sum, number ) was created , and this is what was
paired with the ICAO in previous Wpt entries .

If you choose to use Keyboard entry and need the complete instrument code it is available freeware at Simviation and Flightsim
just do a Search for " F-111 Pig HUD " get the Build standard 8 .

Cheers
Karol
 
#7
Hi David

Just out of curiosity what are you using in your instrument ,
1. An Alpha/Numeric keypad integrated into the instrument as per the usual FMS/CDU units.
or ,
2. Are you utilising the computer keyboard for the ICAO entry .

Cheers
Karol
 
#8
Hi Karol,

I'm currently using keyboard entry as the code seems easier, though their are Lvars attached to each button should interaction via the VC FMS.

Thanks to yours and Bob's help, I've been able to add functionality to create a new flightplan via DTO and source waypoint, then add remove or set active various waypoints, which is far more than I had previously.

I'm still working the duplicate waypoint issue, though at the moment, I've got an fail condition added where the user interaction is reset if the Ident is invalid or duplicate, which will do for the moment.

The next thing I want to look into adding is functionality of listing destination airport approaches and transitions.

The hard thing for me is that each line on the FMS screen is it's own String Element, to provide more control over FMS window/button spacing, if that makes sense.
eg.
XML:
<Element>
<Position X="30" Y="65"/>
    <Text X="240"    Y="30" Bright="Yes" Length="5" Font="IRIS-21-FMS"  Bold="True" Color="lime"  Adjust="Left" VerticalAdjust="Center">
        <String>%((@c:FlightPlanIsActiveFlightPlan))%{if}%( 1 (>@c:FlightPlanWaypointIndex, enum) (@c:FlightPlanWaypointIdent) d slen 0 == if{ p '' })%!s!%{else}%{end}</String>
    </Text>           
</Element>
The above works well as part of the below button logic. Apologies for the long winded code, I'm not the most concise programmer. :)


XML:
<!-- ADD WPT IN LSK L1 Position -->
                    (L:PC21_BTN_FS_FMS_L_L1_EXEC,enum) 1 ==
                        if{
                            <!-- If on LEGS Page -->
                            (L:FMS1-PG,enum) 51 ==
                                if{
                                    <!-- If WPT MOD in ADD WPT Mode -->
                                    (L:WPT-MOD,enum) 1 ==
                                        if{
                                            <!-- If Waypoint scratch-pad not active -->
                                            (L:WPT-INPUT-VALID,bool) 0 ==
                                                if{
                                                    <!-- Make Waypoint scratchpad active -->
                                                    1 (>L:WPT-INPUT-VALID,bool)
                                                    
                                                    <!-- Clear Departure Scratchpad values -->
                                                    0 (>L:FMS-WPT-1,number)
                                                    0 (>L:FMS-WPT-2,number)
                                                    0 (>L:FMS-WPT-3,number)
                                                    0 (>L:FMS-WPT-4,number)
                                                    0 (>L:FMS-WPT-5,number)
                                                    
                                                    <!-- Close Left LSK 1 -->
                                                    0 (>L:PC21_BTN_FS_FMS_L_L1_EXEC,enum)
                                                }
                                                els{
                                                    <!-- If Departure scratchpad active and 3 or more IDENT fields populated -->   
                                                    (L:FMS-WPT-1,number) 0 !=
                                                    (L:FMS-WPT-2,number) 0 != and
                                                    (L:FMS-WPT-3,number) 0 != and   
                                                        if{
                                                            <!-- Search Database for Airport, VOR or Waypoint Ident matching up to five character IDENT -->
                                                            'AVW' (>@c:IcaoSearchStartCursor)
                                                            (L:FMS-WPT-5,number) chr
                                                            (L:FMS-WPT-4,number) chr (L:FMS-WPT-3,number) chr
                                                            (L:FMS-WPT-2,number) chr (L:FMS-WPT-1,number) chr scat scat scat scat (>@c:IcaoSearchEnterChar)
                                                            
                                                            <!-- Set Flightplan index to waypoint 1 -->
                                                            1 (>@c:FlightPlanWaypointIndex)

                                                            <!-- If the Database does not find a match to ICAO Ident, run the fail routine -->
                                                            (@c:IcaoSearchMatchedIcaosNumber,number) 0 ==
                                                                if{
                                                                    1 (>L:FMS1-ERROR,enum)
                                                                }
                                                                els{
                                                                   <!-- If the Database finds a match for the ICAO Ident, create it as a new waypoint -->
                                                                    (@c:IcaoSearchMatchedIcaosNumber,number) 1 ==
                                                                        if{
                                                                            (@c:IcaoSearchCurrentICAO) (>@c:FlightPlanNewWaypointICAO)
                                                                            1 (>@c:FlightPlanAddWaypoint)
                                                                        }
                                                                        els{
                                                                            <!-- If the Database finds more than 1 match for the ICAO Ident, run the duplicate waypoint routine -->
                                                                            (@c:IcaoSearchMatchedIcaosNumber,number) 1 &gt;
                                                                                if{
                                                                                    1 (>L:FMS1-WPT,enum)
                                                                                }                                                                       
                                                                        }
                                                                }
                                                                                                                        
                                                            <!-- Set the system to note that an FMS WPT value has been entered, close the departure input and Close Left LSK 1 -->
                                                            0 (>L:WPT-INPUT-VALID,bool)
                                                            0 (>L:PC21_BTN_FS_FMS_L_L1_EXEC,enum)   
                                                        }
                                                        els{
                                                            <!-- If Departure scratchpad active and 3 or more IDENT fields NOT populated -->   
                                                            <!-- Close the departure scratchpad and Close Left LSK 1 -->
                                                            0 (>L:WPT-INPUT-VALID,bool)
                                                            0 (>L:PC21_BTN_FS_FMS_L_L1_EXEC,enum)
                                                        }
                                                }
                                        }
                                        els{
                                            (L:WPT-MOD,enum) 0 ==
                                                if{
                                                    <!-- If Departure scratchpad active and 3 or more IDENT fields NOT populated -->   
                                                    <!-- Close the departure scratchpad and Close Left LSK 1 -->
                                                    0 (>L:WPT-INPUT-VALID,bool)
                                                    0 (>L:PC21_BTN_FS_FMS_L_L1_EXEC,enum)
                                                }
                                        }   
                                }
                                        
                        }
                        els{}
 

n4gix

Resource contributor
#9
Actually David, your approach is much preferred to the typical amateurish scripting. Creating copious comments to document each bit of scripting is a very wise step and well worth the effort. Believe me, you'll thank yourself several months or possibly years when you need to go back and make changes or improvements. :wave:
 
#10
The hard thing for me is that each line on the FMS screen is it's own String Element, to provide more control over FMS window/button spacing, if that makes sense.
eg.
XML:
<Element>
<Position X="30" Y="65"/>
    <Text X="240"    Y="30" Bright="Yes" Length="5" Font="IRIS-21-FMS"  Bold="True" Color="lime"  Adjust="Left" VerticalAdjust="Center">
        <String>%((@c:FlightPlanIsActiveFlightPlan))%{if}%( 1 (>@c:FlightPlanWaypointIndex, enum) (@c:FlightPlanWaypointIdent) d slen 0 == if{ p '' })%!s!%{else}%{end}</String>
    </Text>     
</Element>
Have you tried FormattedText, %{loop} %{next}, and LineSpacing="x"?

I'm still working the duplicate waypoint issue, though at the moment, I've got an fail condition added where the user interaction is reset if the Ident is invalid or duplicate, which will do for the moment.
Resolving multiple Ident matches is covered in the guidebook, so that should be able to get you started. I'm sure you will get it working. If you use code to select the preferred ICAO then an ICAO transfer will likely be involved in the process. The tricky part is to insure that sufficient gauge update cycles are skipped before returning values such as distance to the particular navaid or intersection. My advice is to play it safe and start with 4 cycle skip.

Bob
 
Last edited:
#11
Hi David

The following shot shows the current state of my Flt Pln Editor .
As you can see with all the Lat/Longs it is military orientated .
I have the ability to move the Radar display to any location on Earth , it could be thousands of miles away from where the
aircraft is currently located .
So for a VOR I project the display to the vicinity of the VOR , call up the VOR symbols on the display , then click on
the desired VOR , it does a short ( 10 nm ) range Nearest search for a VOR from the click point .
Then in the Lat/Long Entry page I select the VOR button and set a SEQ , and click the Enter button and it's in .
Mission Adaptive Editor.jpg


EDIT : for details of VOR or facility button useage see Replies # 21 to 23 at this link ,
https://www.fsdeveloper.com/forum/threads/gps-vor-frequency-to-tuned-radio.425445/page-2

In your case it's going to be a bit more difficult .
VOR's can be a pain , you do a VOR Ident search and you get multiple returns , you then have to determine where each is
geographically located , then relate that to the locality of your Flt Pln , then select the appropriate one , then enter it .
I hope Bob can help you .

Cheers
Karol
 
Last edited:
#12
Nice doing, Karol !
You didn't load a flightplan! You created one using DTO and edited this way as explained above?
So your flightplan is only in the RAM store??
Have you written a utility to write this flightplan into a file?
Edi

Btw your last upload is dated from 2013. Is there a newer one?
 
#13
Hi Edi

You can start a flight sim session with either , no Flt Pln , or with a saved Flt Pln loaded , and use my Flt Pln Editor .
If ; no Flt Pln exists , create one starting with a DTO , then Add as many Wpt's as you desire up to 99 legs .
or ,
If ; you are flying a saved Flt Pln , you can Add or Delete Wpt's anywhere in that Flt Plan .

You can have 99 legs ( 100 Wpt's ) , if you changed the SEQ number generator from 2 to 3 digits you could create up to 999 legs .
Wpt's can be added or deleted at any point in the Flt Pln .

Wpt entry options are,
* Lat/Long in 3 different formats in either , Normal precision , or High precision accuracy levels ( by keyboard ) .
* Airport ICAO idents ( by keyboard ) .
* Lat/Long , Airport , VOR , NDB , Intersections ( by Radar Pick Up clicked on Radar display )

The STAND OFF projection of the Radar display is similar to , moving the map in the FS Flight Planner , or moving Google Earth ,
it's function is to move to an area that you have a specific interest in for whatever reason you might have .

All Flight Planning can be done in cockpit , either on the ground , or airborne at any stage of a flight , with or without
the autopilot engaged .
At any stage you can create anew Flt Pln simply by starting with a DTO and adding to it , you can do that as often as you want ,
it's an extremely flexible arrangement that provides the pilot with a host of options .

All Flt Plns created or modified by the Editor are only applicable to the current Sim flight session , you cannot save them .

Francois created a method of saving Flt Plns , but I did not want to include it in my panel , if you are interested in his work
see the following ,
FMC:-
Francois FMC Fs Developer thread link
https://www.fsdeveloper.com/forum/t...h-real-vertical-navigation-management.424559/

video of FMC see From 3:05 To 4:20 minutes at link

My last Upload was 2013 , had computer problems have not yet uploaded latest version , still need to write operating instructions
for several new or modified instruments , it's a complex task that I tend to keep avoiding .

Cheers
Karol
 
#14
Karol,
i'm able to change a loaded flight plan.
But i didn't know to create a plan by using DTO.
Francois did a very good job.
Yes, writing operating manuals is at all the hardest work.
Thanks!
Edi
 
#15
Hi Edi

If you have the 2013 version then you have that capability .
Grab the Right MFD and put it as a Pop Up in your plane , the Flight Manual details how to use it .
What the old version does not have is :- * the 4 Stand Off pages , * the Facility buttons , or the Revert ( Cancel DTO button ) .
You will be able to use the 3 Lat/Longs and the Airport ICAO , any Flt Pln will appear in your GPS unit if not using my Radar .
For Lat/Long locations read the margins in maps/atlas , Google search "Lat Long of ..... " any town , Dam or significant feature
eg ; Eiffel tower , Macchu Picchu , etc . , read LL off the Google Earth .
It's fun exploring it .

Cheers
Karol
 
Top