By Adjusting Deformation scaling in Mechanical, one could scale the Deformed shape for any standard result. But, this doesn't seem to work for Python Result (scaling is greyed out).
One would just need to add the below line to the default code when one inserts Python result to deform the plot based on Deformation scaling.
dpf_workflow.SetOutputWarpField(u)
def post_started(sender, analysis):# Do not edit this line define_dpf_workflow(analysis) # Uncomment this function to enable retrieving results from the table/chart # def table_retrieve_result(value):# Do not edit this line # import mech_dpf # import Ans.DataProcessing as dpf # wf = dpf.Workflow(this.WorkflowId) # wf.Connect('contour_selector', value) # this.Evaluate() def define_dpf_workflow(analysis): import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) u = dpf.operators.result.displacement() nrm = dpf.operators.math.norm_fc() # timeScop = dpf.Scoping() # timeScop.Ids = [1] # u.inputs.time_scoping.Connect(timeScop) u.inputs.data_sources.Connect(dataSource) nrm.Connect(u) dpf_workflow = dpf.Workflow() dpf_workflow.Add(u) dpf_workflow.Add(nrm) dpf_workflow.SetOutputWarpField(u) # dpf_workflow.SetInputName(u, 0, 'time') # dpf_workflow.Connect('time', timeScop) dpf_workflow.SetOutputContour(nrm) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
@Rohith Patchigolla There is no scaling factor above. So the undocumented SetOutputWarpField has no effect
def post_started(sender, analysis):# Do not edit this line define_dpf_workflow(analysis) # Uncomment this function to enable retrieving results from the table/chart # def table_retrieve_result(value):# Do not edit this line # import mech_dpf # import Ans.DataProcessing as dpf # wf = dpf.Workflow(this.WorkflowId) # wf.Connect('contour_selector', value) # this.Evaluate() def define_dpf_workflow(analysis): import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) u = dpf.operators.result.displacement() # Scale the displacement field by 4 scale_op = dpf.operators.math.scale() scale_op.inputs.field.Connect(u) scale_op.inputs.factor.Connect(4.0) u_scaled = scale_op.outputs.field.GetData() nrm = dpf.operators.math.norm_fc() # timeScop = dpf.Scoping() # timeScop.Ids = [1] # u.inputs.time_scoping.Connect(timeScop) u.inputs.data_sources.Connect(dataSource) nrm.Connect(u) dpf_workflow = dpf.Workflow() dpf_workflow.Add(u) dpf_workflow.Add(nrm) dpf_workflow.SetOutputWarpField(u_scaled) # dpf_workflow.SetInputName(u, 0, 'time') # dpf_workflow.Connect('time', timeScop) dpf_workflow.SetOutputContour(nrm) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
I grabbed some ansysgpt suggestions but that also is not complete (and references unfinished script in the dev forum). The above script also fails. Any ideas?
The end goal here is to have a image that scales the chosen result (here, deformation) by the scaling factor. Not sure that is possible, at least none of the dev forum examples work.
I think there is a comprehension problem here. Ansys mechanical uses the term scale with reference to the figure generated in a result plot. Naturally those here who can't solve the problem take the mathematical definition of scaling (which must be what dpf is using, but it is not clearly documented) and think they have provided a solution and it is a user issue. I would surmise the problem comes from the dual definitions of the term scale.
Any mechanical user would use scale and expect a python result would use the same definition as mechanical.
I took me a bit to understand @Rohith Patchigolla's solution, so I am posting this note to help anyone who might come across this thread. Adding the dpf_workflow.SetOutputWarpField(u) simply enables the scaling functionality within Mechanical UI:
I am not sure if the .SetOutputWarpField() is a "scaler" method itself. But it can provide a workaround for any user fom whom it is acceptable to manually set the scale in Mechanical UI. Unless of course this is exposed through the API and can be automated, but I could not find this yet.
.SetOutputWarpField()
@Tasos I also couldn't find this exposed via API. With a bit of digging into the internal object you can access it via below until it's exposed in the API directly. Worth noting that the below is undocumented and put together largely via trial and error: '''python # Deformation scale: -1.0 = auto, 0.0 = true scale
from System import Array, Object from System.Reflection import BindingFlags
_SET = BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance _MTH = BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance
_ds_gfx = ExtAPI.Graphics.InternalObject _prefs = _ds_gfx.ResultPrefs() _prefs.GetType().InvokeMember("deformedScale", _SET, None, _prefs, Array[Object]([0.0])) #Edit this value for deformation scale _prefs.update() _ds_gfx.GetType().InvokeMember("Redraw", _MTH, None, _ds_gfx, Array[Object]([1])) ''' You do need to trigger some kind of event to get GUI to refresh ("Redraw" in the above example). If you have a result object it's easier to just activate it. '''python # Deformation scale: -1.0 = auto, 0.0 = true scale
deformation_result = Model.Analyses[0].Solution.AddTotalDeformation() Model.Analyses[0].Solution.EvaluateAllResults()
_prefs = ExtAPI.Graphics.InternalObject.ResultPrefs() _prefs.GetType().InvokeMember("deformedScale", BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance, None, _prefs, ArrayArray[Object]([0.0])) #Edit this value for deformation scale _prefs.update()
deformation_result.Activate() '''