Matlab STK connection: How to access available existing objects?

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

12 Comments

Okay, I found one solution where you need to know, which objects are existing. The GetObjectFromPath command was correct, but used in a wrong way.
You must create a handler to the object:
handler.Redu_Station = STK.root.GetObjectFromPath('/Facility/Redu_Station');
where it is important that the path points to the current working directory. Facility here is not a folder, it is the type of the object you want to access.
If you want to access a satellite, you need to write something like
handler.MySat = STK.root.GetObjectFromPath('/Satellite/MySat');
After creating that handler you can access the object by simply using
MySat.SPA.bound_radius = 3; % [m]
MySat.EPS.PanelGroupName = 'Panels'; % defined in the spacecraft model for STK
CmdString = ['VO */Satellite/MySat SolarPanel ' ...
'Visualization Radius On ', num2str(MySat.SPA.bound_radius),...
' AddGroup ',MySat.EPS.PanelGroupName]
STK.root.ExecuteCommand(CmdString);
I hope this helps.
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
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
maybe you check the relative path...could be the problem
Yes I checked, I really don't understand. I fear that it is a problem of the new STK version.
I am sorry. Maybe you check the STK direct support.
Which STK version do you have? Have you adapted the line
STK.app = actxserver('STK11.application');
to the correct version?
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;
Ever find the answer to this? I'm having the same issue. The docs don't explain how to build the path.

Sign in to comment.

Answers (2)

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;
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

Products

Release

R2020b

Asked:

on 15 Oct 2021

Moved:

on 7 Nov 2024

Community Treasure Hunt

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

Start Hunting!