CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ANSA (https://www.cfd-online.com/Forums/ansa/)
-   -   Ansa Script (https://www.cfd-online.com/Forums/ansa/111581-ansa-script.html)

ganesh0481 January 10, 2013 07:45

Ansa Script
 
HI All,
It will be great if anybody tell how to do automation using Ansa scripting.

ganesh0481 January 10, 2013 23:12

HI ,
It will be great if any of our members answer to my question.

rmaries January 11, 2013 03:01

Scripting
 
You can use scripting by their own scripting language which is like c++.

In ANSA - 14 onwards it is supporting python along with their own scripting language. You can use their scripting manual available in documentation to do the scripting.

ganesh0481 January 11, 2013 04:25

HI rmaries,
Thanks for your reply,can you tell whether we can create our own scripts like hypermesh does.As i came to know there some standard scripts that only can be used.Looking forward your support on this.

byee
Ganeshram

rmaries January 11, 2013 05:41

Yes You can create your own script. I don't know hypermesh so i can't able to tell about hypermesh scripting.

ganesh0481 January 11, 2013 07:05

Hi,
Thanks for reply,can you share some example or it is possible to have some personla discussion on this over phone.Let me know are you fine on this.

Suhas Konanur March 20, 2013 05:26

Ansa scripting
 
Hello members,

I created a curve with 2 points across a meshed plate. Then I selected the nearest nodes to the curve and aligned it with the curve.

I tried to automate the process using Ansa script. The program asks the user to select nodes on the mesh. It captures the nodes in a matrix, extract the coordinates in an array and then with CreateCurve function a curve is drawn.

For the alignment, I captured the NearestShell (function with same name) to these nodes and then the corresponding nodes in a matrix. These nodes were then aligned to the curve. However the results are satisfactory only when the nodes selected by the user are closely spaced. Is there are a function or an algorithm which searches for the nearest nodes to a curve?? Thanking you all for your suggestions. :)

Suhas

vangelis March 23, 2013 09:21

Dear Suhas
Can you give us a broaded view of what actually want to do with ANSA?
Are you sure that it is something that cannot already be done and you
try scripting?
Is it something that you want to do automatically without user interaction?

PAFortin April 16, 2013 11:57

Dear members,

I am a fresh begginer in ANSA scripting.
I am currently trying to script the creation of a aerdoynamic part with ANSA. My script will take a set of parameters (heigh, length etc...) and output a fully created part.

I need to create curves which follow a determined angle at the start and at the end. Until now I did this "by hand" by creating 2 straight curves following the desired angles and by enforcing a tangent condition between my final curves and these 2 curves at the start and at the end.
This is easy with the GUI but I can't find a function that would do the same operation within my script.

The function CreateCurve is not satisfactory as it cannot enforce tangent conditions.

I hope I was clear enough. Does any one know of a way to solve my problem?

Thank you for all your suggestions.

Regards,

Pierre

rmaries April 17, 2013 05:34

Hi,

Can you give an example of what you are doing. If possible with screen shots.
Which version of ANSA you are using. Because I can able to create python scripts which can be used only ANSA14x versions.

Regards
Maries



Quote:

Originally Posted by PAFortin (Post 420995)
Dear members,

I am a fresh begginer in ANSA scripting.
I am currently trying to script the creation of a aerdoynamic part with ANSA. My script will take a set of parameters (heigh, length etc...) and output a fully created part.

I need to create curves which follow a determined angle at the start and at the end. Until now I did this "by hand" by creating 2 straight curves following the desired angles and by enforcing a tangent condition between my final curves and these 2 curves at the start and at the end.
This is easy with the GUI but I can't find a function that would do the same operation within my script.

The function CreateCurve is not satisfactory as it cannot enforce tangent conditions.

I hope I was clear enough. Does any one know of a way to solve my problem?

Thank you for all your suggestions.

Regards,

Pierre


PAFortin April 17, 2013 08:25

Hi,

I work with ANSA 13.2.3.

Unfortunately, I cannont give you screenshots as this project is still confidential.
To make it short I juste need to find a script function that would do do same as TOPO>CURVES>NEW in the GUI in order to enforce tangent conditions.

Any ideas?

Regards,

Pierre

rmaries April 17, 2013 23:59

Hi Pierre,

According to my knowledge there is no direct script for function you told.

You can contact ansa@beta-cae.gr for further details.

If you find the script for that, post it here

Regards
Maries



CreateCurve,
NAME:
CreateCurve - Definition of 3D-curves.
SYNOPSIS:
CreateCurve(integer total,matrix x,matrix y,matrix z)
DESCRIPTION:
Creates smooth 3D-curve that passes from a number of points.
(total) is the number and (x),(y),(z) are the coordinates of the points.

RETURN:
Returns the pointer to the created 3D-curve.

EXAMPLE:

def main()
{
x[0] = 1;
x[1] = 1.1;
x[2] = 2;
y[0] = 1.5;
y[1] = 3.2;
y[2] = 2.7;
z[0] = 1.8;
z[1] = 3;
z[2] = 2.6;
CreateCurve(3,x,y,z);
}
-----------------------------------------------------------------




Quote:

Originally Posted by PAFortin (Post 421224)
Hi,

I work with ANSA 13.2.3.

Unfortunately, I cannont give you screenshots as this project is still confidential.
To make it short I juste need to find a script function that would do do same as TOPO>CURVES>NEW in the GUI in order to enforce tangent conditions.

Any ideas?

Regards,

Pierre


PAFortin April 19, 2013 10:06

Hi Maries,

I ended up contacting BETA CAE. Turns out what I was looking for cannot be done with ANSA v13.x. Something close enough can be done with ANSA v14.x using MORPHING.
Unfortunately, I do not have access to v14.x so I ended up creating my parametrized geometry with CATIA V5 and then importing it to ANSA for meshing.

Thank you for your help anyway.

Regards,

Pierre

rmaries April 20, 2013 11:45

Thanks Pierre

ganesh0481 August 20, 2013 02:58

Ansa scripts
 
Hi All,
can any one share how to get offset thickness value using script.

rmaries August 27, 2013 02:34

Quote:

Originally Posted by ganesh0481 (Post 446805)
Hi All,
can any one share how to get offset thickness value using script.

Hi Ganesh,

Did you get the solution. I think you are asking about offsetface option

You can use the below format to get the offset thickness by using script.

OffsetFaces, BETA SCRIPT development Manual
NAME:
OffsetFaces - Offset faces.
SYNOPSIS:
OffsetFaces(float d,string command)
DESCRIPTION:

Offset visible faces by a given distance d.
The string command can be DELETE or KEEP (deletes or keeps the original faces).

RETURN:

The function returns zero (0) upon successful execution, and 1 if an error occurs.

EXAMPLE:

OffsetFaces(2.5,"KEEP");

-----------------------------------------------------------------

If you are using ansa version >14 . You can use python also. If you need any further clarification call me.

Regards
Maries

mihaicris November 27, 2013 12:15

loading Python scripts
 
Hi all

We have developed a few python scripts for ANSA 14.
Does anybody know how to load them every time ANSA starts? And have them available to users of course...

rmaries November 27, 2013 21:30

Automatically loading ansa scripts
 
Hi,

Check this. Whether it will work.?

• FILE>Script>Default:

Sets a script as default. Selecting this button opens a window where all loaded and added scripts are

displayed. The index in front of each path indicates which is the default sequence. Always, the script with

zero index is the default. Select a script from the list and press the "Set as default" button to become the

default one. Press then OK to confirm.

Important Note: A loaded script takes always zero index while an added script takes the first available

index.


Regards
Maries

Quote:

Originally Posted by mihaicris (Post 463774)
Hi all

We have developed a few python scripts for ANSA 14.
Does anybody know how to load them every time ANSA starts? And have them available to users of course...


mihaicris November 28, 2013 01:20

Quote:

Originally Posted by rmaries (Post 463832)
Hi,

Check this. Whether it will work.?

• FILE>Script>Default:

Sets a script as default. Selecting this button opens a window where all loaded and added scripts are "...

Hello rmaries

Although I appreciate your effort...
- ANSA 14 does not have a FILE>Script menu
- it is about python scripts in ANSA
- the default setting only lists the loaded scripts, and my scripts are not listed because they where not loaded, that was the question, how can I load them automatically when ANSA starts?

vangelis November 28, 2013 02:20

Hi Mihai,

I suggest you place all your user scripts in a file named
ANSA_TRANSL
and place this in the following path
<homedir>/.BETA/ANSA/version_14.x.x/


Then when ANSA starts it will read all the scripts in the file.

If you want all users to read the same scripts, then
either
1) Do the above for each one
or
2) If you have permissions in the installation directory of ANSA
place this ANSA_TRANSL file in

ansa_v14.x.x/config/

Then all ANSA users will read these scripts upon startup

Hope this helps

Vangelis

mihaicris November 28, 2013 04:38

Quote:

Originally Posted by vangelis (Post 463847)
Hi Mihai,

I suggest you place all your user scripts in a file named
ANSA_TRANSL...

Hello Vanghelis

Thank you for answering me.
What exactly should I write in this ANSA_TRANSL? Please do not forget I want to load python scripts.

For old bs scripts it should be somethig like:
#include "/path_to_script/myscript.bs"

How should it be for python, just writing #include "/path_to_script/myscript.py" does not work...


Cheers
:)

vangelis November 28, 2013 05:16

Hello Mihai,

You are right, some clarifications for python scripts

1) The file must be called ANSA_TRANSL.py
2) In this file you must have entries like:

import ansa
ansa.ImportCode('/home/user/my_functions.py')
ansa.ImportCode('/home/user/my_functions2.py')
ansa.ImportCode('/home/user/my_functions3.py')

Vangelis

mihaicris November 28, 2013 05:40

Hello Vanghelis

Thank you again. I have the sensation that we are slowly converging to a solution. :) Just a few increments more...

So... if I include my scripts in the ANSA_TRANSL.py with the code you suggested:
- ANSA_TRANSL.py is loaded at ANSA start, shows up in Available modules section at Script>Run function
- none of the functions from "my_functions.py are" available, they do not appear in function list in the same dialog.

Just to eliminate a possible question, I can manually load my script without ANSA_TRANSL and run it, so it is a valid script.

vangelis November 28, 2013 05:45

Hello Mihai,

When you place your scripts in ANSA_TRANSL.py
and start ANSA, what are the messages reported
in the ANSA Info Window when ANSA starts?
Can you copy paste all messages?

Vangelis

mihaicris November 28, 2013 06:16

Hello Vanghelis


Error messages are... a lot of messages, but unimportant now, It is finally solved now.
With help from you and from the manual of course, it was there all along. Again! :) I do not know how I could miss it. Again!

So... for anybody else, if you have a file named say.. myLibrary.py importing all the functions from that file at ANSA start, using ANSA_TRANSL is done this way:

import ansa
ansa.ImportCode("/path_to_file/myLibrary.py")
from myLibrary import *


The last line appears in the ansa_python document as import myLibrary, it does not offer acces to the functions inside the file (at least in my case).

vangelis November 28, 2013 07:39

glad you've worked it out!

ANSA_User April 8, 2014 02:02

Good Morning all,


can anyone kindly guide me for my question below please.


1. how to read excel file in ansa scripting( i want to import it and read it while executing it).



thank you very much for time taken to read it.

rmaries April 8, 2014 08:35

You can do that with python and pyxll library
 
Quote:

Originally Posted by ANSA_User (Post 484554)
Good Morning all,


can anyone kindly guide me for my question below please.


1. how to read excel file in ansa scripting( i want to import it and read it while executing it).



thank you very much for time taken to read it.

Hi,

You can write the script using python. There is an external library pyxll(and many more are there), you can use it to open the excel file.

you can download the library here

https://www.pyxll.com

ANSA_User April 8, 2014 22:54

hi maries,

thank you very much for your suggestion, but i would lik to know how to do it ANSA too.

rmaries April 8, 2014 23:37

Quote:

Originally Posted by ANSA_User (Post 484813)
hi maries,

thank you very much for your suggestion, but i would lik to know hot to do it ANSA too.

You can run the python script in ANSA. Can you give an example sheet and give the example sheet. If i have time i will try

Regards
Maries

ANSA_User April 8, 2014 23:52

Good morning Maries ,

Currently i am working in Beta script and have to execute that in ANSA. I ll check that and i will come back to you.actually i m kinda new to scripting so may take time.

Warm regards
Sajun

rmaries April 8, 2014 23:56

Quote:

Originally Posted by ANSA_User (Post 484817)
Good morning Maries ,

Currently i am working in Beta script and have to execute that in ANSA. I ll check that and i will come back to you.actually i m kinda new to scripting so may take time.

Warm regards
Sajun

If you are using ANSA version > 14. Better do your scripting in python. You can find lot of materials and libraries available in internet for python.

Ansa version < 14 doesn't support python scripting. You can do scripting only in Beta script.

Thanks & Regards
Maries

ANSA_User April 15, 2014 06:56

hi maries,

there is a inbuilt function in ANSA itself ,to read and access the excel file. anyways thanks for your help.

Regards
sajun

sbharatk May 6, 2014 03:37

ansa scripting
 
I am a new and just started scripting in ANSA_v15.
1. If I have to add Menu button just next to "File, Window, Containers, Tools, MyMenu, Utilities, Assembly, Help". How can I add?
2. How to attach a script in User Button Script window?
3. If I create "User Menu" from Settings>Buttons Manager > Create Menu, do we attach script to it?
4. Where to see available APIs to call functionality from ANSA?

B.

ganesh0481 May 25, 2014 03:29

Storing XML connection data
 
Hi All,

I used Read connections command for reading connection file. I like to store the information after reading the data.
e.g : dia, x.y.z

let me know if anyone has some method on the same.

Thanks
Ganesh

felipecunha2002 June 1, 2015 15:37

How to convert .py to .pyb
 
Hi Members...

I'm new in ANSA and I created a simple script with extension .py, I just want to know how can I convert it to encripted .pyb file?

Thanks,
Felipe:)

rmaries June 2, 2015 03:06

You can use Projects>compile in script editor menu to create .pyb file from python.



Quote:

Originally Posted by felipecunha2002 (Post 548478)
Hi Members...

I'm new in ANSA and I created a simple script with extension .py, I just want to know how can I convert it to encripted .pyb file?

Thanks,
Felipe:)


felipecunha2002 June 2, 2015 07:19

Thanks rmaries !!!!:)

Sastry July 30, 2015 11:09

ANSA script to create cylinder
 
Hi all,

Can anyone please tell how to create a cylindrical surface in ANSA using script? I am trying to sweep a curve but couldn't.

Thanks in advance.

Sastry

rmaries July 31, 2015 05:03

You can create
 
Hi Sastry,

You can create cylinder by script. use the script function

ansa.base.CreateVolumeCylinder(point1, point2, length, radius, part, property)

I find this function is ANSA v15.

Regards
Maries


Quote:

Originally Posted by Sastry (Post 557695)
Hi all,

Can anyone please tell how to create a cylindrical surface in ANSA using script? I am trying to sweep a curve but couldn't.

Thanks in advance.

Sastry



All times are GMT -4. The time now is 00:23.