• 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 SimConnect: Loading into default scenario via code.

Messages
40
Country
netherlands
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
 
Messages
820
Country
ca-ontario
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.
 
Messages
2,079
Country
us-ohio
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.
 
Messages
40
Country
netherlands
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.
 
Messages
40
Country
netherlands
"-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.
 
Messages
1,243
Country
canada
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\"
 
Messages
40
Country
netherlands
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"
 
Messages
1,243
Country
canada
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.
            }
        }
    }
}
 
Messages
40
Country
netherlands
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.
 
Messages
1,243
Country
canada
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
 
Messages
40
Country
netherlands
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