Hi @mszlez , I think I figured it out. I'll share my thought process so that you can reuse this (ugly) debugging method in the future.
When I need to understand what's happening with a custom object, I usually create global variables for debugging:
Then, in Mechanical, take the actions to trigger the callback calling that function (here, click on the "Generate Analyses" button). From the scripting console, switch to the tab related to your extension:
(in my case that extension is called "Stress Postprocessing", but in your case that would be "AF_Wizards_Rev_E".
You're then able to print those global variables in Mechanical:
From the above we see that "test2" variable (refering to "object"variable in the code) is actually the analysis. And indeed, this button is in the toolbar, so the variable passed to the function called in the "onclick" callback is the active analysis, in my case a static structural one:
This analysis object does not have a "pipe_side" property, it only has the properties shown in the details' view:
Hope this helps!
Hi all.
I'm trying to create some ACT Extension for ANSYS Mechanical. I've defined some properties in my .xml file, i.e.:
def GenerateAnalyses(object): in_file=object.Properties["input_file"].Value side=object.Properties["pipeside"].Value
In the extension log I see "expected int, got str" error. Have no clue why I'm seeing this as variables "in_file" and "side" are not used anywhere else in my script, i.e. it's their first declaration. How can I fix this?
Hi @mszlez , I tried your code and get no error messages on my side. A couple of things that come to mind:
Hi @Pernelle Marone-Hitz,
Many thanks for your answer. Actually that's only a small portion of the whole code, didn't want to paste everything as that's quite a lot of lines and most of them are not relevant 🙂 But, let me share with you whole .xml + relevant python functions and describe what I'm trying to do. So:
And then I'm in the place where I am now, i.e. I cannot read any property value due to the "expected int, got str" error 🙂 Actually I managed to overcome an issue with "fileopen" using python command "FileDialog.ShowOpenDialog", not the best solution I'd like to have, but working. But still, I have an issue with "select" control property, i.e. property named "pipe_side" in the code below.
Maybe one more thing, in ACT log it says:
line 2181, in GenerateAnalyses TypeError: expected int, got str
And it's clearly pointing towards the line:
side=str(object.Properties["pipe_side"].StringValue)
.XML file:
def SteupAnalyses(analysis): ExtAPI.DataModel.CreateObject("an_set", ExtAPI.ExtensionManager.CurrentExtension) def GenerateAnalyses(object): # Reading input file filters = "txt files (.txt)|.txt|All files (.)|." dir = "c:\\" res = FileDialog.ShowOpenDialog(ExtAPI.UserInterface.MainWindow,dir,filters,2,"Open FEA input file","") in_file=res[1] side=str(object.Properties["pipe_side"].Value)
with open(in_file, 'r') as f: inputs = [[float(num) for num in line.split(',')] for line in f] # Initial definitions model=ExtAPI.DataModel.Project.Model model.Geometry.DisplayStyle=PrototypeDisplayStyleType.Material Pe_empty=inputs[0][7] Pi_flooded=inputs[1][6] Pe_flooded=inputs[1][7] Pe_ops=inputs[2][7] Pi_ops=inputs[2][6]
Hi again @Pernelle Marone-Hitz,
Ok, seems like I found workaround. Instead of generating analyses with the button, I used a tree child object (i.e. the one visible after right click on the parent object in the tree) to invoke GenerateAnalyses() function. Works as expected and I'm pretty happy with that solution :) Not sure what was the problem with the one below, if you can see the issue and can let me know I'd be grateful :)
xml:
.py:
def SteupAnalyses(analysis): ExtAPI.DataModel.CreateObject("an_set", ExtAPI.ExtensionManager.CurrentExtension) def GenerateAnalyses(object): # Reading input file filters = "txt files (.txt)|.txt|All files (.)|." dir = "c:\" res = FileDialog.ShowOpenDialog(ExtAPI.UserInterface.MainWindow,dir,filters,2,"Open FEA input file","") in_file=res[1] side=str(object.Properties["pipe_side"].ValueString)
Amazing, thank you very much for your help. Many thanks for showing me the way how to debug, actually I was wondering if there is any possibility apart from looking on the errors in extension log :) Works perfectly now!
Hi @mszlez , thanks for your message, glad I could help :-) In think this debug method is the easiest one to use.