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()
This should work, but you have to set the Mechanical scaling factor to 1.0.
def post_started(sender, analysis):# Do not edit this line define_dpf_workflow(analysis) scale = 10.0 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() scale = dpf.operators.math.scale_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) scale.inputs.fields_container.Connect(u) scale.inputs.weights.Connect(scale) dpf_workflow.SetInputName(u, 0, 'time') dpf_workflow.Connect('time', timeScop) dpf_workflow.SetOutputContour(nrm) dpf_workflow.SetOutputWarpField(scale.outputs.fields_container) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
ibid
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() '''