diff --git a/_unittest/example_models/T12/template.rpt b/_unittest/example_models/T12/template.rpt new file mode 100644 index 00000000000..bd301c52488 --- /dev/null +++ b/_unittest/example_models/T12/template.rpt @@ -0,0 +1,379 @@ +$begin 'ReportDefinitions' + $begin 'ReportSetup' + $begin 'Reports' + $begin 'Plot_6LKGC0' + ReportID=117 + $begin 'Report2D' + name='Plot_6LKGC0' + ReportID=117 + ReportType=9 + DisplayType=4 + Title='' + Domain='' + $begin 'Migration' + MigVersion(0, 0, 'mig(0.0)') + $end 'Migration' + $begin 'Graph2DsV2' + $begin 'Graph2D' + TraceDefID=116 + Type='Continuous' + Axis='Y1' + $end 'Graph2D' + $end 'Graph2DsV2' + $begin 'PlotDisplayDataManager' + NextUniqueID=9 + MoveBackwards=false + $begin 'PlotHeaderDataSource' + CompanyName='' + ShowDesignName=true + ProjectFileName='' + $end 'PlotHeaderDataSource' + StockNameIDMap(DataTable=3, Header=0, PrimarySweep=1) + $begin 'SourceList' + $end 'SourceList' + Version='17.0:20150830' + $begin 'DocAttributes' + $begin 'PlotAttributeStoreMap' + $end 'PlotAttributeStoreMap' + $end 'DocAttributes' + $begin 'DisplayTypeAttributes' + $begin 'PlotAttributeStoreMap' + $begin 'MainMapItem' + $begin 'SubMapItem' + DataSourceID=7 + $begin 'CurveCartesianAttribute' + YAxis='Y1' + $end 'CurveCartesianAttribute' + $end 'SubMapItem' + $end 'MainMapItem' + $begin 'MainMapItem' + $begin 'SubMapItem' + DataSourceID=7 + $begin 'CurveRenderAttribute' + $begin 'LineRenderAttribute' + LineStyle='Solid' + LineWidth=3 + ColorVersion=1 + LineColor(R=237, G=28, B=36) + $end 'LineRenderAttribute' + TraceType='Continuous' + SymbolType='HollowHorizontalLeftTriangle' + SymbolColor(R=155, G=93, B=112) + ShowSymbols=false + SymbolFrequency=15 + ShowArrows=false + $end 'CurveRenderAttribute' + $end 'SubMapItem' + $end 'MainMapItem' + $begin 'MainMapItem' + $begin 'SubMapItem' + DataSourceID=0 + $begin 'HeaderRenderAttribute' + $begin 'TitleFont' + $begin 'FontAttribute' + $begin 'Font' + HeightInPts=14 + Width=0 + Escapement=0 + Orientation=0 + Weight=400 + Italic=0 + Underline=0 + StrikeOut=0 + CharSet=0 + OutPrecision=7 + ClipPrecision=48 + Quality=6 + PitchAndFamily=0 + FaceName='Arial' + $end 'Font' + ColorVersion=1 + $end 'FontAttribute' + $end 'TitleFont' + $begin 'SubtitleFont' + $begin 'FontAttribute' + $begin 'Font' + HeightInPts=10 + Width=0 + Escapement=0 + Orientation=0 + Weight=400 + Italic=0 + Underline=0 + StrikeOut=0 + CharSet=0 + OutPrecision=7 + ClipPrecision=48 + Quality=6 + PitchAndFamily=0 + FaceName='Arial' + $end 'Font' + ColorVersion=1 + $end 'FontAttribute' + $end 'SubtitleFont' + $end 'HeaderRenderAttribute' + $end 'SubMapItem' + $end 'MainMapItem' + $end 'PlotAttributeStoreMap' + $end 'DisplayTypeAttributes' + $begin 'DocDefaultAttributes' + $begin 'PlotAttributeStoreMap' + $end 'PlotAttributeStoreMap' + $end 'DocDefaultAttributes' + $begin 'PerViewPlotAttributeStoreMap' + $begin 'MapItem' + ItemID=6 + $begin 'PlotAttributeStoreMap' + $begin 'MainMapItem' + $begin 'SubMapItem' + DataSourceID=5 + $begin 'BasicLayoutAttribute' + $begin 'LayoutRect' + Top=75 + Left=75 + Bottom=9925 + Right=814 + $end 'LayoutRect' + $end 'BasicLayoutAttribute' + $end 'SubMapItem' + $end 'MainMapItem' + $begin 'MainMapItem' + $begin 'SubMapItem' + DataSourceID=4 + $begin 'OverlayLayoutAttribute' + $begin 'BoundingRect' + Top=225 + Left=989 + Bottom=9775 + Right=9775 + $end 'BoundingRect' + ModifySize=false + ModifyPosition=false + $end 'OverlayLayoutAttribute' + $end 'SubMapItem' + $end 'MainMapItem' + $end 'PlotAttributeStoreMap' + PlotType=25 + $end 'MapItem' + $end 'PerViewPlotAttributeStoreMap' + IsViewAttribServer=false + ViewID=-1 + $begin 'SourceIDMap' + IDMapItem(116, 0, -1, 7) + $end 'SourceIDMap' + $begin 'TraceCharacteristicsMgr' + $end 'TraceCharacteristicsMgr' + $begin 'CartesianXMarkerManager' + RefMarkerID=-1 + CurrentMarkerID=-1 + $begin 'ReferenceCurves' + $end 'ReferenceCurves' + $end 'CartesianXMarkerManager' + $begin 'CartesianYMarkerManager' + $end 'CartesianYMarkerManager' + XAxisStackID=-1 + $begin 'AllTransSrcDwg' + $begin 'PT' + ID=25 + TransSrcDwg(-1, 0, 5) + $end 'PT' + $end 'AllTransSrcDwg' + $begin 'AllPtSVID' + $end 'AllPtSVID' + $end 'PlotDisplayDataManager' + $end 'Report2D' + $end 'Plot_6LKGC0' + $end 'Reports' + $end 'ReportSetup' + $begin 'Reports' + $begin 'Plot_6LKGC0' + ReportID=117 + ReportName='Plot_6LKGC0' + $begin 'TraceDef' + TraceDefinitionType='TraceDefinition' + $begin 'DesignSolnDefn' + $begin 'DESIGN_SOLUTION_SIM_VALUE_CONTEXT' + DesignID=4 + SolutionID=5484 + $begin 'REPORT_TYPE_SIM_VALUE_CONTEXT' + ReportType=9 + SimValueContext(0, 0, 2, 0, false, false, 49, 1, 0, 1, 1, '', 0, 0, 'SourceContext', false, '0') + $end 'REPORT_TYPE_SIM_VALUE_CONTEXT' + $end 'DESIGN_SOLUTION_SIM_VALUE_CONTEXT' + $end 'DesignSolnDefn' + ID=116 + VersionID=2217 + Name='db(PeakRealizedGain)' + TieNameToExpr=true + $begin 'Components' + $begin 'TraceComponentDefinition' + Expr='Freq' + $end 'TraceComponentDefinition' + $begin 'TraceComponentDefinition' + Expr='db(PeakRealizedGain)' + $end 'TraceComponentDefinition' + $end 'Components' + $begin 'ExtendedTraceInfo' + NumPoints=0 + TraceType=0 + Offset=0 + XLabel='' + SamplingPeriod='0' + SamplingPeriodOffset='0' + AutoDelay=true + DelayValue='0ps' + AutoCompCrossAmplitude=true + CrossingAmplitude='0mV' + YAxis=1 + AutoCompEyeMeasurementPoint=true + EyeMeasurementPoint='0ps' + EyePamLow() + EyePamVRef() + EyePamHigh() + EyePamNames() + EyePamStrictVRef=false + $end 'ExtendedTraceInfo' + $begin 'TraceFamiliesDisplayDefinition' + DisplayFamiliesType='DisplayAll' + $end 'TraceFamiliesDisplayDefinition' + $begin 'PointsetDefinition' + $begin 'SubsweepDefParamsContainer' + $begin '0' + SubsweepType='Regular' + SubsweepChoiceType='All' + SweepVariableName='Freq' + AllowSelecteValues=true + SweepHasConsistentValues=true + $end '0' + $begin '1' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='fc' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(30000000000) + ParameterType='DoubleParam' + Units='GHz' + $end '1' + $begin '2' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='w' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.02) + ParameterType='DoubleParam' + Units='' + $end '2' + $begin '3' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='rA' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.51) + ParameterType='DoubleParam' + Units='' + $end '3' + $begin '4' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='hA' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.5) + ParameterType='DoubleParam' + Units='' + $end '4' + $begin '5' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='rB' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.687) + ParameterType='DoubleParam' + Units='' + $end '5' + $begin '6' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='hB' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.585) + ParameterType='DoubleParam' + Units='' + $end '6' + $begin '7' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='rC' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.805) + ParameterType='DoubleParam' + Units='' + $end '7' + $begin '8' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='hC' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.661) + ParameterType='DoubleParam' + Units='' + $end '8' + $begin '9' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='rD' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(0.822) + ParameterType='DoubleParam' + Units='' + $end '9' + $begin '10' + SubsweepType='Regular' + SubsweepChoiceType='Selected' + SweepVariableName='hD' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(2.3) + ParameterType='DoubleParam' + Units='' + $end '10' + $begin '11' + SubsweepType='Specifiable' + SubsweepChoiceType='Selected' + SweepVariableName='PC' + AllowSelecteValues=true + SweepHasConsistentValues=true + ColumnValues(-0.073) + ParameterType='DoubleParam' + Units='' + $end '11' + $end 'SubsweepDefParamsContainer' + FamilyBlock() + $end 'PointsetDefinition' + DesignInstanceID=5 + $end 'TraceDef' + $end 'Plot_6LKGC0' + $end 'Reports' + $begin 'AllTracesInterpreter' + $begin 'PerTraceInterpreter' + $begin 'TraceInterpreter' + ID=116 + $begin 'ReportMgrTraceInterpreter' + SolutionName='Setup1 : LastAdaptive' + SolutionID=5484 + $end 'ReportMgrTraceInterpreter' + $begin 'ProductTraceInterpreterBlock' + EMContext='3D' + $end 'ProductTraceInterpreterBlock' + $end 'TraceInterpreter' + $end 'PerTraceInterpreter' + $end 'AllTracesInterpreter' +$end 'ReportDefinitions' diff --git a/_unittest/test_12_PostProcessing.py b/_unittest/test_12_PostProcessing.py index ecd36d9445d..181ef201e81 100644 --- a/_unittest/test_12_PostProcessing.py +++ b/_unittest/test_12_PostProcessing.py @@ -194,6 +194,15 @@ def test_09_manipulate_report_B(self, field_test): ) new_report4.report_type = "Data Table" assert new_report4.create() + if not config["NonGraphical"]: + local_path = os.path.dirname(os.path.realpath(__file__)) + template = os.path.join(local_path, "example_models", test_subfolder, "template.rpt") + assert new_report4.apply_report_template(template) + template = os.path.join(local_path, "example_models", test_subfolder, "template_invented.rpt") + assert not new_report4.apply_report_template(template) + template = os.path.join(local_path, "example_models", test_subfolder, "template.csv") + assert not new_report4.apply_report_template(template) + assert not new_report4.apply_report_template(template, property_type="Dummy") def test_09_manipulate_report_C(self, field_test): variations = field_test.available_variations.nominal_w_values_dict diff --git a/src/ansys/aedt/core/modeler/cad/components_3d.py b/src/ansys/aedt/core/modeler/cad/components_3d.py index bf1ea28b32e..3b802188ea2 100644 --- a/src/ansys/aedt/core/modeler/cad/components_3d.py +++ b/src/ansys/aedt/core/modeler/cad/components_3d.py @@ -280,7 +280,7 @@ def group_name(self, name): """ if "Group" in self._primitives.oeditor.GetChildObject(self.name).GetPropNames() and name not in list( - self._primitives.oeditor.GetChildNames("Groups") + list(self._primitives.oeditor.GetChildNames("Groups")) ): arg = [ "NAME:GroupParameter", diff --git a/src/ansys/aedt/core/modeler/cad/primitives.py b/src/ansys/aedt/core/modeler/cad/primitives.py index 98a0637a25e..ad48d2dad2e 100644 --- a/src/ansys/aedt/core/modeler/cad/primitives.py +++ b/src/ansys/aedt/core/modeler/cad/primitives.py @@ -5622,7 +5622,7 @@ def create_group(self, objects=None, components=None, groups=None, group_name=No if components is None and groups is None and objects is None: raise AttributeError("At least one between ``objects``, ``components``, ``groups`` has to be defined.") - all_objects = self.object_names[:] + self.oeditor.GetChildNames("Groups")[::] + all_objects = self.object_names[:] + list(self.oeditor.GetChildNames("Groups")) if objects: object_selection = self.convert_to_selections(objects, return_list=False) else: diff --git a/src/ansys/aedt/core/modeler/modeler_3d.py b/src/ansys/aedt/core/modeler/modeler_3d.py index d7b912647cd..77d55e504b6 100644 --- a/src/ansys/aedt/core/modeler/modeler_3d.py +++ b/src/ansys/aedt/core/modeler/modeler_3d.py @@ -1108,7 +1108,7 @@ def import_nastran( aedt_objs = self.object_names[::] for assembly, _ in nas_to_dict["Assemblies"].items(): assembly_group_name = assembly - if assembly in self.oeditor.GetChildNames("Groups"): + if assembly in list(self.oeditor.GetChildNames("Groups")): assembly_group_name = generate_unique_name(assembly, n=2) new_group = [] for el in nas_to_dict["Assemblies"][assembly]["Solids"].keys(): @@ -1121,7 +1121,7 @@ def import_nastran( ] if obj_names: new_group.append(self.create_group(obj_names, group_name=str(el))) - if assembly_group_name in self.oeditor.GetChildNames("Groups"): + if assembly_group_name in list(self.oeditor.GetChildNames("Groups")): self.oeditor.MoveEntityToGroup( [ "Groups:=", @@ -1180,7 +1180,7 @@ def import_nastran( id += 1 if group_parts: pids = [i.name for i in polys] - if assembly_name in self.oeditor.GetChildNames("Groups"): + if assembly_name in list(self.oeditor.GetChildNames("Groups")): self.oeditor.MoveEntityToGroup( [ "Objects:=", diff --git a/src/ansys/aedt/core/modules/post_processor.py b/src/ansys/aedt/core/modules/post_processor.py index aee16da526a..1cb0b19c183 100644 --- a/src/ansys/aedt/core/modules/post_processor.py +++ b/src/ansys/aedt/core/modules/post_processor.py @@ -4478,7 +4478,7 @@ def power_budget(self, units="W", temperature=22, output_type="component"): power_dict_obj = {} group_hierarchy = {} - groups = self._app.oeditor.GetChildNames("Groups") + groups = list(self._app.oeditor.GetChildNames("Groups")) self._app.modeler.add_new_user_defined_component() for g in groups: g1 = self._app.oeditor.GetChildObject(g) diff --git a/src/ansys/aedt/core/modules/report_templates.py b/src/ansys/aedt/core/modules/report_templates.py index 5eae5560eca..60bbaa415e0 100644 --- a/src/ansys/aedt/core/modules/report_templates.py +++ b/src/ansys/aedt/core/modules/report_templates.py @@ -2062,6 +2062,51 @@ def update_trace_in_report(self, traces, setup_name=None, variations=None, conte finally: self.expressions = expr + @pyaedt_function_handler() + def apply_report_template(self, input_file, property_type="Graphical"): # pragma: no cover + """Apply report template. + + .. note:: + This method works in only in graphical mode. + + Parameters + ---------- + input_file : str + Path for the file to import. The extension supported is ``".rpt"``. + property_type : str, optional + Property types to apply. Options are ``"Graphical"``, ``"Data"``, and ``"All"``. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + + References + ---------- + + >>> oModule.ApplyReportTemplate + """ + if not os.path.exists(input_file): # pragma: no cover + msg = "File does not exist." + self._post.logger.error(msg) + return False + + split_path = os.path.splitext(input_file) + extension = split_path[1] + + supported_ext = [".rpt"] + if extension not in supported_ext: # pragma: no cover + msg = "Extension {} is not supported.".format(extension) + self._post.logger.error(msg) + return False + + if property_type not in ["Graphical", "Data", "All"]: # pragma: no cover + msg = "Invalid value for `property_type`. The value must be 'Graphical', 'Data', or 'All'." + self._post.logger.error(msg) + return False + self._post.oreportsetup.ApplyReportTemplate(self.plot_name, input_file, property_type) + return True + class Standard(CommonReport): """Provides a reporting class that fits most of the app's standard reports."""