% Vytvoreni noveho projektu
App = actxserver('AnsoftHfss.HfssScriptInterface');
Desktop = App.GetAppDesktop();
Desktop.RestoreWindow;
Desktop.NewProject;
HProject = Desktop.GetActiveProject;

% Vytvoreni InsertDesign
invoke(HProject,'InsertDesign','HFSS','Example_antena','DrivenModal','');
Design = HProject.invoke('SetActiveDesign','Example_antena');
Editor = Design.invoke('SetActiveEditor','3D Modeler');

% Vytvoreni kvadru
invoke(Editor,'CreateBox',...
{'NAME:BoxParameters',...
'XPosition:=','-37.7mm',...
'YPosition:=','-28.4mm',...
'ZPosition:=','0mm',...
'XSize:=','113.1mm',...
'YSize:=','85.2mm',...
'ZSize:=','1.6mm'},...
{'NAME:Attributes',...
'Name:=','Dielektrikum',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','FR4_epoxy',...
'SolveInside:=',true})

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','0mm',...
'YStart:=','0mm',...
'ZStart:=','1.6mm',...
'Width:=','37.7mm',...
'Height:=','28.4mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Antena',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Antena'},...
{'NAME:ChangedProps',...
{'NAME:Color','R:=',202,'G:=',184,'B:=',123}}}});

% Nastaveni pruhlednosti objektu
invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Antena'},...
{'NAME:ChangedProps',...
{'NAME:Transparent','Value:=',0}}}});

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','0mm',...
'YStart:=','13.7mm',...
'ZStart:=','1.6mm',...
'Width:=','6mm',...
'Height:=','1mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Zarez1',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% vyriznuti materialu
invoke(Editor,'Subtract',...
{'NAME:Selections',...
'Blank Parts:=','Antena',...
'Tool Parts:=','Zarez1'},...
{'NAME:SubtractParameters',...
'SolveInside:=',false})

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','18.35mm',...
'YStart:=','0mm',...
'ZStart:=','1.6mm',...
'Width:=','1mm',...
'Height:=','6mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Zarez2',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% vyriznuti materialu
invoke(Editor,'Subtract',...
{'NAME:Selections',...
'Blank Parts:=','Antena',...
'Tool Parts:=','Zarez2'},...
{'NAME:SubtractParameters',...
'SolveInside:=',false})

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','31.7mm',...
'YStart:=','13.7mm',...
'ZStart:=','1.6mm',...
'Width:=','6mm',...
'Height:=','1mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Zarez3',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% vyriznuti materialu
invoke(Editor,'Subtract',...
{'NAME:Selections',...
'Blank Parts:=','Antena',...
'Tool Parts:=','Zarez3'},...
{'NAME:SubtractParameters',...
'SolveInside:=',false})

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','18.35mm',...
'YStart:=','22.4mm',...
'ZStart:=','1.6mm',...
'Width:=','1mm',...
'Height:=','6mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Zarez4',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% vyriznuti materialu
invoke(Editor,'Subtract',...
{'NAME:Selections',...
'Blank Parts:=','Antena',...
'Tool Parts:=','Zarez4'},...
{'NAME:SubtractParameters',...
'SolveInside:=',false})

% Vytvoreni ctverce
invoke(Editor,'CreateRectangle',...
{'NAME:RectangleParameters',...
'IsCovered:=',true,...
'XStart:=','-37.7mm',...
'YStart:=','-28.4mm',...
'ZStart:=','0mm',...
'Width:=','113.1mm',...
'Height:=','85.2mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Ground',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0.5,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Ground'},...
{'NAME:ChangedProps',...
{'NAME:Color','R:=',202,'G:=',184,'B:=',123}}}});

% Nastaveni pruhlednosti objektu
invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Ground'},...
{'NAME:ChangedProps',...
{'NAME:Transparent','Value:=',0}}}});

% Vytvoreni kruhu
invoke(Editor,'CreateCircle',...
{'NAME:CircleParameters',...
'IsCovered:=',true,...
'XCenter:=','26.85mm',...
'YCenter:=','21.3mm',...
'ZCenter:=','0mm',...
'Radius:=','2.7mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','G_Dira',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% vyriznuti materialu
invoke(Editor,'Subtract',...
{'NAME:Selections',...
'Blank Parts:=','Ground',...
'Tool Parts:=','G_Dira'},...
{'NAME:SubtractParameters',...
'SolveInside:=',false})

% Vytvoreni cylindru
invoke(Editor,'CreateCylinder',...
{'NAME:CylinderParameters',...
'XCenter:=','26.85mm',...
'YCenter:=','21.3mm',...
'ZCenter:=','0mm',...
'Radius:=','2.7mm',...
'Height:=','-8mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Koax',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% Vytvoreni cylindru
invoke(Editor,'CreateCylinder',...
{'NAME:CylinderParameters',...
'XCenter:=','26.85mm',...
'YCenter:=','21.3mm',...
'ZCenter:=','0mm',...
'Radius:=','0.5mm',...
'Height:=','-8mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Port1',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

invoke(Editor,'AssignMaterial',...
{'NAME:Selections',...
'Selections:=','Port1'},...
{'NAME:Attributes',...
'MaterialName:=','pec',...
'SolveInside:=',false});

invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Port1'},...
{'NAME:ChangedProps',...
{'NAME:Color','R:=',202,'G:=',184,'B:=',123}}}});

% Vytvoreni cylindru
invoke(Editor,'CreateCylinder',...
{'NAME:CylinderParameters',...
'XCenter:=','26.85mm',...
'YCenter:=','21.3mm',...
'ZCenter:=','0mm',...
'Radius:=','0.5mm',...
'Height:=','1.6mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','Pin',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

invoke(Editor,'AssignMaterial',...
{'NAME:Selections',...
'Selections:=','Pin'},...
{'NAME:Attributes',...
'MaterialName:=','pec',...
'SolveInside:=',false});

invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','Pin'},...
{'NAME:ChangedProps',...
{'NAME:Color','R:=',202,'G:=',184,'B:=',123}}}});

% Vytvoreni kvadru
invoke(Editor,'CreateBox',...
{'NAME:BoxParameters',...
'XPosition:=','-37.7mm',...
'YPosition:=','-28.4mm',...
'ZPosition:=','0mm',...
'XSize:=','113.1mm',...
'YSize:=','85.2mm',...
'ZSize:=','32mm'},...
{'NAME:Attributes',...
'Name:=','airvol',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','air',...
'SolveInside:=',true})

% Nastaveni pruhlednosti objektu
invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','airvol'},...
{'NAME:ChangedProps',...
{'NAME:Transparent','Value:=',0.9}}}});

% Ziskani cisla strany.
Module = Design.GetModule('BoundarySetup');
Module.AssignRadiation({'NAME:AirvolRad1',...
'Faces:=',{183}});

% Ziskani cisla strany.
Module = Design.GetModule('BoundarySetup');
Module.AssignRadiation({'NAME:AirvolRad2',...
'Faces:=',{185}});

% Ziskani cisla strany.
Module = Design.GetModule('BoundarySetup');
Module.AssignRadiation({'NAME:AirvolRad3',...
'Faces:=',{186}});

% Ziskani cisla strany.
Module = Design.GetModule('BoundarySetup');
Module.AssignRadiation({'NAME:AirvolRad4',...
'Faces:=',{188}});

% Ziskani cisla strany.
Module = Design.GetModule('BoundarySetup');
Module.AssignRadiation({'NAME:AirvolRad5',...
'Faces:=',{187}});

Module = Design.GetModule('BoundarySetup');
Module.AssignPerfectE({'NAME:PeE1',...
'InfGroundPlane:=',false,...
'Objects:=',{'Antena'}});

Module = Design.GetModule('BoundarySetup');
Module.AssignPerfectE({'NAME:PeE2',...
'InfGroundPlane:=',true,...
'Objects:=',{'Ground'}});

% Vytvoreni kruhu
invoke(Editor,'CreateCircle',...
{'NAME:CircleParameters',...
'IsCovered:=',true,...
'XCenter:=','26.85mm',...
'YCenter:=','21.3mm',...
'ZCenter:=','-8mm',...
'Radius:=','2.7mm',...
'WhichAxis:=','Z'},...
{'NAME:Attributes',...
'Name:=','WPort',...
'Flags:=','',...
'Color:=','(132 132 193)',...
'Transparency:=',0,...
'PartCoordinateSystem:=','Global',...
'MaterialName:=','vacuum',...
'SolveInside:=',true})

% Nastaveni pruhlednosti objektu
invoke(Editor,'ChangeProperty',...
{'NAME:AllTabs',...
{'NAME:Geometry3DAttributeTab',...
{'NAME:PropServers','WPort'},...
{'NAME:ChangedProps',...
{'NAME:Transparent','Value:=',1}}}});

Module = Design.GetModule('BoundarySetup');
Module.AssignWavePort({'NAME:WavePort',...
'NumModes:=',1,...
'PolarizeEField:=',false,...
'DoDeembed:=',false,...
'DoRenorm:=',true,...
'RenormValue:=','50Ohm',...
{'NAME:Modes',...
{'NAME:Mode1',...
'ModeNum:=',1,...
'UseIntLine:=',true,...
{'NAME:IntLine',...
'Start:=',{'26.85mm','21.3mm','-8mm'},...
'End:=',{'29.55mm','21.3mm','-8mm'}},...
'CharImp:=','Zpi'}},...
'Objects:=',{'WPort'}});

% Nastaveni analyzy
Module = Design.GetModule('AnalysisSetup');
Module.InsertSetup('HfssDriven',...
{'NAME:Setup3GHz',...
'Frequency:=','3GHz',...
'PortsOnly:=',false,...
'maxDeltaS:=',0.02,...
'UseMatrixConv:=',false,...
'MaximumPasses:=',25,...
'MinimumPasses:=',1,...
'MinimumConvergedPasses:=',1,...
'PercentRefinement:=',20,...
'ReducedSolutionBasis:=',false,...
'DoLambdaRefine:=',true,...
'DoMaterialLambda:=',true,...
'Target:=',0.3333,...
'PortAccuracy:=',2,...
'SetPortMinMaxTri:=',false})

% Nastaveni krokovani analyzy
Module = Design.GetModule('AnalysisSetup');
Module.InsertDrivenSweep('Setup3GHz',...
{'NAME:sweep1to3GHz',...
'Type:=','Fast',...
'SetupType:=','LinearCount',...
'StartFreq:=','1GHz',...
'StopFreq:=','3GHz',...
'Count:=',1000,...
'SaveFields:=',true,...
'ExtrapToDC:=',false});

% Spusteni analyzy
invoke(Design,'Solve',...
{'Setup3GHz'})

invoke(HProject,'SaveAs','C:/temp/tmpDataHfss.hfss',false);
Module = Design.GetModule('Solutions');
Module.ExportNetworkData('',...
{'Setup3GHz:sweep1to3GHz'},...
7,...
'C:/temp/tempDataExportHFSS.m',...
{'All'},...
true,...
50);

