CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSYS Meshing & Geometry (https://www.cfd-online.com/Forums/ansys-meshing/)
-   -   [ANSYS Meshing] Script Model - Mechanical (https://www.cfd-online.com/Forums/ansys-meshing/154552-script-model-mechanical.html)

USER1234 June 17, 2015 03:04

Script Model - Mechanical
 
Hello everyone,

I have to script a complete ANSYS analysis and allready managed to write a script with MATLAB which generates the engineering data and the geometry of a tooth from a gear-wheel (by importing points and create Skin's out of these).
Now I have to script all the meshing and external loads, fixed supports, ... by using the ANSYS Mechanical Feature (Model).

My question: Does anybody know where I can find information how to script the Mechanical feature of ANSYS? I couldn't find any helpful information in the "ANSYS Scripting Guide" or in the "Mechanical Application" directory (ANSYS HELP). Or does anybody has done some scripting on ANSYS Mechanical in the past?

Edit: Maybe I can solve the problem by using Icem CFD and do it manually and record all of my steps - does anybody tried this before?

Best Regards
Max

Kapi June 17, 2015 18:38

Hi Max,

By quick search thru JS files in Ansys folder, I found this!
Code:

//Accesing the boundary conditions properties
var Env = DS.Tree.FirstActiveBranch.Environment;DS.Script.SelectItems(""+Env.ID);
//Creating force at the top of the structure
DS.Script.doInsertEnvironmentForce(1)
ListView.ActivateItem("Scoping Method");
ListView.ItemValue = "Named Selection" ;
ListView.ActivateItem("Named Selection");
ListView.ItemValue = "T1" ;
ListView.ActivateItem("Define By");
ListView.ItemValue = "Components" ;
ListView.ActivateItem("X Component");
ListView.ItemValue = "-10000"
ListView.SelectedItem.IsChecked="true"
ListView.ActivateItem("Y Component");
ListView.ItemValue = "0"
ListView.SelectedItem.IsChecked="true"
ListView.ActivateItem("Z Component");
ListView.ItemValue = "-810.42"
ListView.SelectedItem.IsChecked="true"

It looks like most of the function used in Mechanical has prefix of "doInsertEnvironment..." but I could be wrong.
Similar to this you can create, fixed support

You need to create Named Selection for the faces where you are applying force and support so that you can call them when you are running your script.

Hope it helps

Cheers
KAPI

USER1234 June 26, 2015 04:19

Quote:

Originally Posted by Kapi (Post 550835)
fixed support

Hi Kapi,

I managed to script MeshSizing and some other things but at the moment I have problems to find the "DS.Script.doInsert.." for FixedSupport in the .xml and .js files in Ansys directory. This here doesn't work .. it says that "DS.Script.doInsertEnvironmentFixedSupport();" doesn't exist:


Code:

var SelStatStruc=DS.Tree.FirstActiveBranch.Environment;
DS.Script.changeActiveObject(SelStatStruc.ID);
DS.Script.doInsertEnvironmentFixedSupport();


Best Regards,Max


EDIT: this one doesn't work ether:

Code:

DS.Script.localString("ID_EnvironmentInsertDisplacementFixedSupport");

Kapi June 28, 2015 18:47

Hi Max,

Good Day!!
Try this!

Code:

DS.Script.doInsertEnvironmentFixedDisplacement(1)
It should help you solve your problem!


Cheers
KAPI

USER1234 June 30, 2015 06:34

1 Attachment(s)
Quote:

Originally Posted by Kapi (Post 552473)
Code:

DS.Script.doInsertEnvironmentFixedDisplacement(1)

Thanks - this one worked! :)

I have another problem in Mechanical when it comes to mesh my geometry:

I don't have problems to change the value of "Physics Preference" for example but I don't know how to access the parameters for "Sizing" (it is closed and has to be opened with the "+" infront)

When I want to change the "Sizing" -> "Min Size" an error says, that "Min Size" doesn't exist. I hope you understand what I mean - I have attached an example.

Best regards,
Max

Kapi June 30, 2015 21:08

Hi Max,

You need to find particular functions just like you found physics preference, just search more!

Anyways this will help!

Code:

meshGroup.MinSizeSF = 0.0001;

Cheers
KAPI

USER1234 July 13, 2015 10:07

Quote:

Originally Posted by Kapi (Post 552768)
You need to find particular functions...

Hi KAPI,

I have another question: I couldn't find anything for selecting a force in my mechanical tree outline and activate this one.
I tried several codes like this ones:

Code:

var SelForce=DS.Tree.FirstActiveBranch.Environment.Load(1);
or
var SelForce=DS.Tree.FirstActiveBranch.Environment.Force(1);
or
var SelForce=DS.Tree.FirstActiveBranch.Environment.Force;
or
var SelForce=DS.Tree.FirstActiveBranch.Load(1);
or
var SelForce=DS.Tree.FirstActiveBranch.Force(1);
or
var SelForce=DS.Tree.FirstActiveBranch.Environment.Item(1);
...

DS.Script.changeActiveObject(SelForce.ID);

Maybe you know how to acces this force.

Thank you for all your help!


Best regards,
Max

Kapi July 13, 2015 18:21

Hi Max,

Quote:

I couldn't find anything for selecting a force in my mechanical tree outline
How did you get your force in your tree outline?
What I mean is you can give values of force when you first created the force by the below code (for ex: force at top of the strcuture)
Code:

DS.Script.doInsertEnvironmentForce(1)
so you dont have access it again but if you need then I will check how to do it and get back to ya!

Cheers
KAPI

USER1234 July 14, 2015 00:14

Quote:

Originally Posted by Kapi (Post 555302)
so you dont have access it again but if you need then I will check how to do it and get back to ya!

I want to run the analysis and after getting the result I want to change the force which I have created (change the position where the force is pointing at my surface) and want tu run the analysis again and again and again ..

So it would be nice if you could check this!

Best regards
Max

USER1234 July 14, 2015 02:10

.. I will try to delete this force and create a new force .. maybe this works

.. have you used "commands" in the tree outline of Mechanical Ansys? Can I change the material by overwrite the material properties in APDL code?

Kapi July 14, 2015 20:09

Hi Max,

Yea you can try to delete force and add new one. You can try to make it parametric as well so that you can run the same simulation by only changing force.
I have not done much on Ansys mechanical Tree outline so I have limited knowledge.

Cheers
KAPI

USER1234 July 15, 2015 04:30

I figured out how to access features (pressure, fiexed support, force, ..) in the tree outline:

Code:

DS.Tree.FirstActiveBranch.Environment.Loads.Item(i);

Kapi July 15, 2015 18:13

Good Job Max,

I have been busy lately, will get back to CFDOnline by tuesday most likely!

joxen July 22, 2015 03:09

Quote:

Originally Posted by USER1234 (Post 555522)
I figured out how to access features (pressure, fiexed support, force, ..) in the tree outline:

Code:

DS.Tree.FirstActiveBranch.Environment.Loads.Item(i);


Hi, I'm working with a similar project and have the same problem as you have. I'd like to select an already existing load in the tree and make changes. Lets say that we have a pressure load and we like to supress it. Would the code be like:


Code:

DS.Tree.FirstActiveBranch.Environment.Loads.Pressure(i);
ListView.ActivateItem("Suppressed");
ListView.ItemValue="No";

[/QUOTE]

I'm not sure if i should change item to pressure or ad a number instead of i?

USER1234 July 22, 2015 03:25

Quote:

Originally Posted by joxen (Post 556430)
I'm not sure if i should change item to pressure or ad a number instead of i?

hi,

"item" is for all of the different external inputs like pressure, force, .. the same. You get access to the different loads by replace the "i" with the position in your tree of the item which you want to select.

So for example you have in your "loads" a fixed support at first position and a pressure on second position.
to select the pressure and set it to "unsuppressed" the code should be the following:

Code:

var SelPressure = DS.Tree.FirstActiveBranch.Environment.Loads.Item(2);
DS.Script.changeActiveObject(SelPressure.ID);
ListView.ActivateItem("Suppressed");
ListView.ItemValue="No";

If it is not working - just let me know!

Best Regards,
Max

joxen July 22, 2015 04:05

Quote:

Originally Posted by USER1234 (Post 556432)
hi,

"item" is for all of the different external inputs like pressure, force, .. the same. You get access to the different loads by replace the "i" with the position in your tree of the item which you want to select.

So for example you have in your "loads" a fixed support at first position and a pressure on second position.
to select the pressure and set it to "unsuppressed" the code should be the following:

Code:

var SelPressure = DS.Tree.FirstActiveBranch.Environment.Loads.Item(1);
DS.Script.changeActiveObject(SelPressure.ID);
ListView.ActivateItem("Suppressed");
ListView.ItemValue="No";

If it is not working - just let me know!

Best Regards,
Max


Thank you so much, it work, but i also have a question regarding how to change the analysis settings, for example NumberOfSetps?


Code:

var SelAnslysis = DS.Tree.FirstActiveBranch.Environment.Loads.Item(2);
DS.Script.changeActiveObject(SelAnalysis.ID);
ListView.ActivateItem("NumberOfSteps");
ListView.ItemValue="2";

I
Thanks for your assistance

USER1234 July 24, 2015 07:51

Quote:

Originally Posted by joxen (Post 556440)
i also have a question regarding how to change the analysis settings, for example NumberOfSetps?

I will look at this on monday .. I don't have acces to ANSYS at the moment.


I also have another question:
in Mechanical you have the option to export a file with the result of the displacement. Does anybody know the code to do this export?

Best regards
Max

Kapi July 26, 2015 18:58

Hi Max,

I think you have to use "Send Command" in .wbjn file to export your result with Displacement. I have never used export command in mechanical but I used once for CFX result file.

Cheers
KAPI

USER1234 July 27, 2015 02:55

Quote:

Originally Posted by Kapi (Post 557067)
Hi Max,

I think you have to use "Send Command" in .wbjn file to export your result with Displacement. I have never used export command in mechanical but I used once for CFX result file.

Cheers
KAPI

Hi,

can you share the code for export CFX result file? Maybe it will be quite similar to export the Mechanical result file?!

Best regards,
Max

EDIT: I figured out how to export a specific solution (in my case: Displacement on a node) into a txt-file or in a Excel-file.
here is the code (to write in txt-file use:"DS.Script.doExportToTextFile(FilePath="XXX")" ):

Code:

var SelDis=DS.Tree.FirstActiveBranch.AnswerSet.Results.Item(1);
DS.Script.changeActiveObject(SelDis.ID);
DS.Script.doExportToTextFile(FilePath="XXX.xls")

now I have the problem that I want to change my force after output the displacement result in Excel and will output the new result in the same excel file .. it will overwrite it in excel -> so I have to tell excel in which cell it should write the new displacement result - does anybody know how to do that?

Best regards,
Max

joxen July 27, 2015 07:36

Quote:

Originally Posted by Kapi (Post 557067)
Hi Max,

I think you have to use "Send Command" in .wbjn file to export your result with Displacement. I have never used export command in mechanical but I used once for CFX result file.

Cheers
KAPI


Hi Kapi,

Do you know how to handle the command snippet with the journal script?`
I can access all loads and results with the codes:

Code:

var SelExtMoment = DS.Tree.FirstActiveBranch.Environment.Loads.Item(2);
DS.Script.changeActiveObject(SelExtMoment.ID);
ListView.ActivateItem("Suppressed");
ListView.ItemValue="No";

and

Code:

var SelCommands = DS.Tree.FirstActiveBranch.AnswerSet.Item(1);
DS.Script.changeActiveObject(SelCommands.ID);
ListView.ActivateItem("Suppressed");
ListView.ItemValue="Yes";

to suppress and unsuppress each item. I have some command snippets in the Environment section that I want to suppress and unsuppress and also in the solution/AnswerSet but I can't control them.

If the snippet is in place 3 and I choose Item(3) it skips the snippet and suppress the next item. Do you know how to handle this?

Thanks
// Joakim


All times are GMT -4. The time now is 19:34.