CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > ANSYS Meshing & Geometry

[DesignModeler] How to write a such script?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 2, 2016, 18:23
Default How to write a such script?
  #1
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
Hello everyone,

I'm facing a headache problem right now. Say I'm having 10,000 bodies imported from .stp file, each of them has different name, end with plate thickness at the last two characters, like 'body1_PL12', 'body2_PL14'.

The question is how can I use script to parse the body name and assign it to the body thickness properties?

Many thanks if anyone can shed light here.

Regards
Huisky
huisky is offline   Reply With Quote

Old   February 3, 2016, 00:24
Default
  #2
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
never done something like that but I guess ...use excel for that.
call body by given name and assign thickness for that body name!
Kapi is offline   Reply With Quote

Old   February 3, 2016, 03:40
Default
  #3
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
Ok, as a rookie, i don't know how to make DM interact with excel.
any hints?

Quote:
Originally Posted by Kapi View Post
never done something like that but I guess ...use excel for that.
call body by given name and assign thickness for that body name!
huisky is offline   Reply With Quote

Old   February 3, 2016, 16:24
Default
  #4
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
First place I will look is "help section" in Ansys!
they have explained it with small example, try that and see if it will help you in some way

Also look into scripting guide in help section as to how you can bring excel and Ansys together.
If you dont understand anything please ask!
Kapi is offline   Reply With Quote

Old   February 4, 2016, 05:03
Default
  #5
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
Ok, I will do that. But I still wonder will that make the operation quicker?

To start with, i found a .js script located under ansys installation path.

Will it be straightforward to modify this script a little bit and achive my goal?


/************************************************** *****************
Function to set Material, 2D behavior, and thickness for Bodies from Excel
The Excel file contains data as 4 columns:
NS_Name Mat_Name Behavior Thickness
Line-1 is header
Line-2 to "n" contains valid data
Behavior options are: Axisymmetric, Plane Stress and Plane Strain
Thickness input is valid only for Plain Stress
Assumptions:
1. Model is 2D
2. The materials are already defined in Engineering Data
3. There are no empty cells between two rows of data in Excel
4. The Excel file contains valid NamedSelections of the surface bodies
The script is developed/tested for Mechanical in WB 13.0
************************************************** ********************/
// Ask the user to choose the excel file
var dlg = DS.Script.AnsObjectFactory.CreateDispatchObject(DS .Script.GenWBProgId("WBControls.WBFileDialog"));
dlg.DefaultFile = "InputData.xlsx";
dlg.DefaultDirectory = "./";
dlg.Filter = "Excel files (*.xls; *.xlsx)|*.xls;*.xlsx";
dlg.FilterIndex = 0;
dlg.ForOpen = true;
dlg.Popup(0); // Popup the file browser
var ExcelFilename = dlg.SelectedFile;
var oScript = DS.Script;
var BodyGName = new Array();
var BodyMat = new Array();
var BodyType = new Array();
var BodyThick = new Array(); // Valid if BodyType == Plane Stress
// Read the Excel file and store all data in Arrays
if (ExcelFilename != "") {
var Excel = new ActiveXObject("Excel.Application");
Excel.Workbooks.Open(ExcelFilename);
var sheet = Excel.ActiveWorkbook.ActiveSheet;
var i=2; // We will start on line 2 in the excel spreadsheet
// Read all the required data from Excel
while (String(sheet.Cells(i,1))!= "undefined") {// Scan first column until empty cell
BodyGName[i-2] = String(sheet.Cells(i,1));
BodyMat[i-2] = String(sheet.Cells(i,2));
BodyType[i-2] = String(sheet.Cells(i,3));
if (BodyType[i-2] == "Plane Stress")
BodyThick[i-2] = Number(sheet.Cells(i,4));

i++;
}
Excel.Application.Quit(); // Kill Excel Application
Excel= null;
}
// If Excel contained any valid data Proceed....
if (BodyGName.length > 0) {
var branch = DS.Tree.FirstActiveBranch;
var matList = branch.Project.MaterialNames; // Access all available materials
var GeomGrp = branch.Model.PrototypeGroup; // Access all bodies
var componentGroup = oScript.GetNode(branch.ComponentGroup.ID); // Access the NamedSelections
var cCount = branch.ComponentGroup.Components.Count;
var component;
var body = null;
oScript.changeActiveObject(GeomGrp.ID);
// Set 2D Behavior
ListView.ActivateItem("2D Behavior");
ListView.ItemValue = "By Body";
// Now loop over the NS read from Excel and apply properties
for (var i=0; i< BodyGName.length; i++) {
var bodyG = BodyGName[i];
// Loop over the defined NS and check the name
for( var j = 1; j <= cCount; j++ ) {
var compI = branch.ComponentGroup.Components.Item(j);
SM.Clear();
if (compI.Name.toLowerCase() == bodyG.toLowerCase()) {
// Select the Specific NS in the Tree
oScript.changeActiveObject(compI.ID);
// Add the component to Selection Set
oScript.doTreeActivateSelection();
// Apply properties to each body in the selection set
assignProps_onSelectedBodies(i);
}
}
}
WBScript.Out("All inputs are now set...", true,"Message");
}
else
WBScript.Out("Unable to use the inputs from Excel file..." + "\n" + "Please check the Excel file", true,"Error");

function assignProps_onSelectedBodies(index)
{
var iNumSelected = SM.SelectedCount;
var aPartIds = new Array();
var aTopoIds = new Array();

// Access each bodies and store their PartIds and TopoIds
for( var k = 1; k <= iNumSelected; k++ )
{
aPartIds.push(SM.SelectedPartID(k));
aTopoIds.push(SM.SelectedEntityTopoID(k));
}

// Loop over the stored list, select one body at a time and apply proprties
for ( var l = 0; l < iNumSelected; l++ )
{
SM.Clear();
SM.AddToSelection(aPartIds[l], aTopoIds[l], false );
// Go the selected Body in Tree
oScript.doGoToCorrespondingParts();
//var item = oScript.tv.FirstSelectedItem;
oScript.tv.SelectedItem.Tag.MaterialName = BodyMat[index]; // Apply Material
// Apply Behavior
ListView.ActivateItem("Behavior");
ListView.ItemValue = "" + BodyType[index];
// Apply Thickness
if (BodyType[index] == "Plane Stress") {
ListView.ActivateItem("Thickness");
ListView.ItemValue = "" + BodyThick[index];
}
}
DS.Script.fillTree();
}


Quote:
Originally Posted by Kapi View Post
First place I will look is "help section" in Ansys!
they have explained it with small example, try that and see if it will help you in some way

Also look into scripting guide in help section as to how you can bring excel and Ansys together.
If you dont understand anything please ask!
huisky is offline   Reply With Quote

Old   February 4, 2016, 17:04
Default
  #6
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
Quote:
But I still wonder will that make the operation quicker?
what are you comparing it against? manually feeding thickness in 10,000 bodies?
HELL YEA!

Quote:
Will it be straightforward to modify this script a little bit and achive my goal?
Looks close enough to help you atleast start what you want. Go line by line and see how it works and then modify as per your need.
Use "Debugger" in this script and see what each line is doing.

u r on the right path!

Cheers
KAPI
Kapi is offline   Reply With Quote

Old   February 8, 2016, 14:19
Default
  #7
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
Thanks for your comments. However, things are not so easy, especially when the API documents are rare for DM scripting.




Quote:
Originally Posted by Kapi View Post
what are you comparing it against? manually feeding thickness in 10,000 bodies?
HELL YEA!


Looks close enough to help you atleast start what you want. Go line by line and see how it works and then modify as per your need.
Use "Debugger" in this script and see what each line is doing.

u r on the right path!

Cheers
KAPI
huisky is offline   Reply With Quote

Old   February 8, 2016, 16:20
Default
  #8
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
can you take a pic of DM on how you are doing it and what functions you are using in DM? I can have a look and give you suggestions!

I know its very frustrating cuz of hardly any documentation but thats how it is!
On the other hand thats why its makes scripting more fun (not when you are in hurry for answers)

Happy scripting!

Cheers
KAPI
Kapi is offline   Reply With Quote

Old   February 8, 2016, 16:30
Default
  #9
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
yes, thanks in advance.
Here is the illustration of my procedure.




Quote:
Originally Posted by Kapi View Post
can you take a pic of DM on how you are doing it and what functions you are using in DM? I can have a look and give you suggestions!

I know its very frustrating cuz of hardly any documentation but thats how it is!
On the other hand thats why its makes scripting more fun (not when you are in hurry for answers)

Happy scripting!

Cheers
KAPI
Attached Images
File Type: png Assign_thickness_DM.png (38.7 KB, 93 views)
huisky is offline   Reply With Quote

Old   February 9, 2016, 16:39
Default
  #10
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
Alrighty, so what are things we need to do to arrive to your answer!
Steps:
1. Create geometry
2. Select Body in the list below one by one
3. Connect excel with WB
4. Transfer Names of body to excel
5. Extract thickness from name, make another column for thickness
6. Revert back to same body name
7. Rename the body or keep the same name
8. Pick thickness with body name from excel
9. Close Excel

So we gotta work on these steps one by one.
- First up, are your using scripting to import your geometry?
- Do you need to apply any other functions on this geometry?
- Which format are you importing geometry in?
- How are you naming each body?
- Any changes you need to do after import?

Hope this will give u path thru to work on!
I normally connect my mesh with excel and work thru but excel with DM is similar!

KAPI
Kapi is offline   Reply With Quote

Old   February 10, 2016, 03:08
Default
  #11
New Member
 
Sor-Trondelag
Join Date: Feb 2016
Posts: 6
Rep Power: 10
huisky is on a distinguished road
Thanks very much for your reply. Here are my comments:

1. I'm importing my geometry manually by click 'import' from DM;
2. Nope. Assign thickness is the only action that i want to do within DM;
3. The geometry was imported from .stp file;
4. The body names are shown as the picture. Only the last 3-4 characters are meaningful, T, stiffener, F, flat bar, PL, plate;
5. After importing, normally I will do a 'analysis' to the geometry quality via DM, but this is not required. What I need is only for assigning thickness to each body.

Thanks in advance.



Quote:
Originally Posted by Kapi View Post
Alrighty, so what are things we need to do to arrive to your answer!
Steps:
1. Create geometry
2. Select Body in the list below one by one
3. Connect excel with WB
4. Transfer Names of body to excel
5. Extract thickness from name, make another column for thickness
6. Revert back to same body name
7. Rename the body or keep the same name
8. Pick thickness with body name from excel
9. Close Excel

So we gotta work on these steps one by one.
- First up, are your using scripting to import your geometry?
- Do you need to apply any other functions on this geometry?
- Which format are you importing geometry in?
- How are you naming each body?
- Any changes you need to do after import?

Hope this will give u path thru to work on!
I normally connect my mesh with excel and work thru but excel with DM is similar!

KAPI
huisky is offline   Reply With Quote

Old   February 10, 2016, 19:09
Default
  #12
Senior Member
 
Join Date: Apr 2014
Location: Melbourne
Posts: 584
Rep Power: 14
Kapi is on a distinguished road
you can use the code you posted before to start.
Just change excel file name, body name and other things!
this way you know where you are having error and eradicate it and keep moving!

Sorry just dont have enough time to write code for you, pretty busy with work these day!
Kapi is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ICEM] Script: problems with face names Maweil ANSYS Meshing & Geometry 3 April 16, 2019 09:10
Have only process 0 write data syavash OpenFOAM Running, Solving & CFD 1 November 3, 2015 06:05
CFX mesh script error Malik77 CFX 0 June 24, 2011 07:42
Perl script for intialisation pratik mehta CFX 2 September 10, 2008 03:09
pmovlink script Arnab Siemens 4 August 1, 2004 22:50


All times are GMT -4. The time now is 03:50.