Matlab STK connection: How to access available existing objects?

119 views (last 30 days)
Dear all,
I am trying to command STK from Matlab. Connection is running well, but now I am seeking for how I access objects in an existing STK scneario. Everything I found in the internet is how to create a new object.
%%Open STK and Scenario
STK.app = actxserver('STK11.application');
STK.root = STK.app.Personality2;
checkempty = STK.root.Children.Count;
if checkempty == 0
%If a Scenario is not open, create a new scenario
STK.app.visible = 1;
else
%If a Scenario is open, prompt the user to accept closing it or not
rtn = questdlg({'Close the current scenario?',' ','(WARNING: If you have not saved your progress will be lost)'});
if ~strcmp(rtn,'Yes')
return
else
STK.root.CurrentScenario.Unload
STK.app.visible = 1;
end
end
%%Get current working folder path
currentFolder = pwd;
%Define STK scenario name (already existing scenario)
STK.scenario.name = append(pwd,'\Test_Mission\Test_Mission.sc');
%Load STK scenario (must be located in the working path)
scenario = STK.root.LoadScenario(STK.scenario.name);
%%Extract scenario data
% Here I want to get information of a ground station and later also a
% satellite in order to calculate e.g. access
Redu_Station = STK.root.GetObjectFromPath('.\Test_Mission\Redu_Station.f');
%...
%%Leave STK scenario and instance
%Close the scenario
STK.root.CloseScenario;
%Close STK instance
STK.app.Quit;
The error message is:
Check for missing argument or incorrect argument data type in call to function 'GetObjectFromPath'.
Unfortunately I do not find any description for the different funcions and how to use them.
Please help me!
Christina
  10 Comments
Mohamed Dewedar
Mohamed Dewedar on 28 Oct 2023
It appears that it has a return type "Void" and you can't assign void to the vaiable "scenario". So use:
STK.root.LoadScenario(STK.scenario.name);
without output variable.
You can refer to the senario object afterwards using:
scenario = STK.root.CurrentScenario;

Sign in to comment.

Answers (2)

Troy McClure
Troy McClure on 6 Nov 2023
Ever find the answer to this? I'm having the same issue. The docs don't explain how to build the path.

Christina Jetzschmann
Christina Jetzschmann on 17 Nov 2023
For me, this solution is now working:
%% Open STK and Scenario
STK.app = actxserver('STK11.application');
STK.root = STK.app.Personality2;
checkempty = STK.root.Children.Count;
if checkempty == 0
% If a Scenario is not open, create a new scenario
STK.app.visible = 1;
else
% If a Scenario is open, prompt the user to accept closing it or not
rtn = questdlg({'Close the current scenario?',' ','(WARNING: If you have not saved your progress will be lost)'});
if ~strcmp(rtn,'Yes')
return
else
STK.root.CurrentScenario.Unload
STK.app.visible = 1;
end
end
%% Get current working folder path
currentFolder = pwd;
% Define STK scenario name (already existing scenario)
STK.scenario.name = append(pwd,'\Test_Mission\Test_Mission.sc');
% Load STK scenario (must be located in the working path)
scenario = STK.root.LoadScenario(STK.scenario.name);
%% Create handler
% Create handler for spacecraft by using path
handler.MySat = STK.root.GetObjectFromPath('/Satellite/MySat');
% Create handler for facility by using path
handler.Redu_Station= STK.root.GetObjectFromPath('/Facility/Redu_Station');
% Create handler for sensor on spacecraft by using path
handler.MySat_Sensor= STK.root.GetObjectFromPath('/Satellite/MySat/Sensor/Sensor1');
%% Define overall stepsize in [s]
stepsize = 60;
%% Create access
% Define ground station and spacecraft of interest for access calculations.
facility = handler.Redu_Station;
spacecraft = handler.MySat;
sensor = handler.MySat_Sensor;
access_name = 'Redu_Station2MySat_access';
% Call access function (incl. intervals, statistics and AER)
Redu_Station2MySat_access = STKaccess(facility, spacecraft,scenario,stepsize);
Redu_Station2Sensor1_access = STKaccess(facility, sensor,scenario,stepsize);
% ...
%% Leave STK scenario and instance
% Close the scenario
STK.root.CloseScenario;
% Close STK instance
STK.app.Quit;

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!