Matlab STK connection: How to access available existing objects?
Show older comments
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.
Also those pageas are not helpful: https://help.agi.com/stkdevkit/11.4.0/Content/stkObjects/ObjModMatlabCodeSamples.htm#1
Please help me!
Christina
12 Comments
Christina Jetzschmann
on 23 May 2022
Shreya Kandagal
on 23 May 2022
Thank you so much.
LUCA SEVERIN
on 29 Jun 2022
Hi,
I am using your code to load an existing scenrio bu it keeps saying that "One or more output arguments not assigned during call to "LoadScenario". " I can't find the problem
Christina Jetzschmann
on 30 Jun 2022
LUCA SEVERIN
on 30 Jun 2022
Yes, it's identical to yours.
The error occurs when it calls the LoadScenario function.
STK.app = actxserver('STK12.application')
STK.root =STK.app.Personality2;
checkempty = STK.root.Children.Count;
if checkempty == 0
STK.app.visible = 1;
else
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
currentFolder = pwd;
STK.scenario.name = append(pwd,'\QuantumShip\QuantumShip.sc');
scenario = STK.root.LoadScenario(STK.scenario.name);
lat = 0 + (60-0).*rand(10,1);
long = -90 + (0+90).*rand(10,1);
coord = [lat,long]
f = cell(length(coord), 1);
for i = 1 : length(coord)
f{i} = strcat('Target', num2str(i));
facility(i) = root.CurrentScenario.Children.New('eTarget', f{i});
facility(i).Position.AssignGeodetic(coord(i,1),coord(i,2),0)
facility(i).UseTerrain = true;
end
Christina Jetzschmann
on 1 Jul 2022
LUCA SEVERIN
on 1 Jul 2022
Yes I checked, I really don't understand. I fear that it is a problem of the new STK version.
Christina Jetzschmann
on 1 Jul 2022
LUCA SEVERIN
on 1 Jul 2022
Yes, I did.
Thanks anyway
Mohamed Dewedar
on 28 Oct 2023
In LoadScenario Method documentation : https://help.agi.com/stkdevkit/Content/DocX/STKObjects~IAgStkObjectRoot~LoadScenario.html
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;
Troy McClure
on 6 Nov 2023
Moved: Walter Roberson
on 7 Nov 2024
Ever find the answer to this? I'm having the same issue. The docs don't explain how to build the path.
Christina Jetzschmann
on 17 Nov 2023
Moved: Walter Roberson
on 7 Nov 2024
Answers (2)
Christina Jetzschmann
on 17 Nov 2023
john
on 7 Nov 2024
The way I got valid path names for GetObjectFromPath was:
STK.root.AllInstanceNamesToXML
and it prints all the available objects in the scenario.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!