P3D v4 SimConnect: Loading into default scenario via code.

#1
Hello, I wanted to know if there is a way to load the user into the default scenario would that be via simconnect if possible.

What i am trying to achieve is:
Im starting the simulator up for the user, and i want it to load directly into the default scenario.

Is there maybe a parameter that i can pass while starting the process or is there a simconnect function for loading the default scenario?

Thanks,
Kuba
 
#2
If I'm reading this right, you don't need SimConect at all. There is a parameter in the sim itself that loads the default flight without displaying the UI.

In FSX.CFG, the parameter is

SHOW_OPENING_SCREEN=0

There is a switch for this somewhere in the FSX menu, I forgot where exactly.

If that's not what you're looking for, you're in luck, things couldn't be much simpler:

SimConnect call to SimConnect_FlightLoad()will do what you need, It works as advertised, I used it many times.
 
#4
Any time you start the simulator with a scenaro passed, it doesn't use the opening screen, so settings in the .CFG file don't matter. I do not recall of there being an actual default flight file so I don't know if it's possible to load the default flight by command.
 
#5
Another example is using command line switch for shortcuts.
Thanks! i think this could solve my issue. Although i do seem to struggle on how to pass on the directory to that argument. Because each time i do the full path to the File it does not work. the file i am trying to load is located in Prepar3d v4 Files/ directory. i tried passing on the full path but with p3d returning to me that the path is incorrect or file doesnt exist. but they are all correct. Any suggestions please let me know.
 
#7
"-fxml:%USERPROFILE%\Documents\Prepar3D v4 Files\Simple Cab.fxml"
Well i've tried this already, and it just returns with : The requested scenario, from command line arguments, is either corrupt or can't be found. Prepar3D will now try to load your default scenario.

Even when trying to load Previous Flight.fxml.
 
#8
this works for me.

change the values in the short cut to:

"C\Program Files\Lockheed Martin\Prepar3D v4\Prepar3D.exe" "-fxml:Simple Cab.fxml"


and the start folder to:

"%USERPROFILE%"\Documents\Prepar3D v4 Files\""

the extra quotes at the beginning and end is added by windows - I put in %USERPROFILE%"\Documents\Prepar3D v4 Files\"
 
#9
Still i have been having no luck. Here are a couple tries i did:
Because i am working in C# this is what i need to do . i pass on the .exe and then the arguments:

Process.Start(@"G:\Lockheed Martin Prepar3d V4\Prepar3D.exe", @"-fxml=%USERPROFILE%\Documents\Prepar3D v4 Files\Previous Flight.fxml");

that does not work. and p3d throws an error.
i have also tried doing the following:
"-fxml:previous Flight.fxml"
"-fxml:C:\Users\Ksimulations\Documents\Prepar3D v4 Files\Previous Flight.fxml"
"-Path=C:\Users\Ksimulations\Documents\Prepar3D v4 Files -fxml:previous Flight.fxml"
"-Path=%USERPROFILE%\Prepar3D v4 Files -fxml:previous Flight.fxml"
 
#10
try this:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace P3DProcessStart
{

    class Program
    {
        static void Main()
        {
            LaunchCommandLineApp();
        }

        /// <summary>
        /// Launch the application with some options set.
        /// </summary>
        static void LaunchCommandLineApp()
        {
            // get %USERPROFILE%
            var pathWithEnv = @"%USERPROFILE%\Documents\Prepar3D v4 Files\ITS A Test2.fxml";
            var filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);

            // Use ProcessStartInfo class
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "C:\\Program Files\\Lockheed Martin\\Prepar3D v4\\prepar3d.exe";
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.Arguments = "-fxml:\"" + filePath + "\"";

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch
            {
                // Log error.
            }
        }
    }
}
 
#11
try this:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace P3DProcessStart
{

    class Program
    {
        static void Main()
        {
            LaunchCommandLineApp();
        }

        /// <summary>
        /// Launch the application with some options set.
        /// </summary>
        static void LaunchCommandLineApp()
        {
            // get %USERPROFILE%
            var pathWithEnv = @"%USERPROFILE%\Documents\Prepar3D v4 Files\ITS A Test2.fxml";
            var filePath = Environment.ExpandEnvironmentVariables(pathWithEnv);

            // Use ProcessStartInfo class
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;
            startInfo.UseShellExecute = false;
            startInfo.FileName = "C:\\Program Files\\Lockheed Martin\\Prepar3D v4\\prepar3d.exe";
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.Arguments = "-fxml:\"" + filePath + "\"";

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch
            {
                // Log error.
            }
        }
    }
}
Thank you that does seem to work! thank you very much for your help, although this doesn't completely achieve what i hoped for. I hoped that it would load directly into the sim and not into the startup menu with the scenario loaded in. Is there maybe a extra argument i can add to load directly into the sim? i preferably do not want to edit the users .cfg to load directly into the sim.
 
#12
The only way I see you doing that is if you create your own prepar3d.cfg file with the scenario screen at startup set to false.
review the command line switches section under the Software develpment Kit (SDK) - Prepare3D SDK section

"-cfgdir:path_to_folder\"

This switch allows overriding the 3 configuration directories with the specified directory. The 3 directories that get overridden are:
  • %APPDATA%\Lockheed Martin\Prepar3D v4
  • %LOCALAPPDATA%\Lockheed Martin\Prepar3D v4
  • %PROGRAMDATA%\Lockheed Martin\Prepar3D v4
All files that would be written or read from those 3 directories will now be redirected to the provided directory. This includes the Prepar3D.cfg and SimConnect.xml files.

Prepar3D.exe -cfgdir:d:\Replacement\Directory\

I've not tried this, you may need to do some copy paste the users cfg files in your install file for your program - or just tell your user to turn off/uncheck Show scenario startup screen - in General Options
 
#13
Hi sorry for the late response but i have been busy IRL. Unfortunately this returns "Prepar3D cannot run because it could not write Prepar3D.cfg" when trying to load a different .cfg file using the command above.
 
Top