Jump to content
Sign in to follow this  
mvass

PCOMP(G) FROM EXCEL

Recommended Posts

Hi, has anybody an idea of how to import data from an excel file to setup the PCOMP or PCOMP(G) property in HM? I can do it with visual basic 2008 (read the .csv exported from the excel, write PCOMP(G) lines to a .bdf or .dat file and import it into HM), but I was wondering if someone from the MACRO-experts world knows a quicker (and probably more intelligent...) way to this.

Thanks in advance!

Share this post


Link to post
Share on other sites

you can use tcl in HM to parse the csv file and write out the cards into the file. I can try it out if you send me a test case (bdf/dat file and csv file)

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

Share this post


Link to post
Share on other sites

Thanks for the reply! No, problem, I'll send you a simple .csv file to test it. By the way, can't it be done directly with the excel (.xls) file? I mentioned the .csv because it is easier for the code I've written in VB2008 to read a text file instead of the excel itself. Not that .csv is a problem for me.

Share this post


Link to post
Share on other sites

csv is always easier compared to excel, because excel is a proprietry format of microsoft while csv is simple comma seperated values

i had couple of more observations

1. In VB you can directly read from excel, because VB is also from microsoft and VB has direct API's to do this

2, Excel can be read from TCL also, there is a package called as tcom which can be used to read all MS Office formats like word, excel, ppt etc , but its a bit complicated

3. Regarding your question about a smarter way, if you already have the model loaded in hypermesh, then doing in hypermesh would be faster, but if you have to load the file in hypermesh just for this, the loading operation may take some time for big models, in that case, using a VB exe to just append those cards at the end of the file would be a faster way

Share this post


Link to post
Share on other sites

I agree. I am not a VB expert, nor a software engineer however after consulting a good colleague of mine, you will be surprised to hear that even with MS Excel files VB is not as "flexible" as with good old text files like .csv. To answer to your call for an example, imagine a .csv file -exported from the respective excel- of the form:

2,1,0.125,45,YES

2,1,0.125,-45,YES

2,1,0.125,-45,YES

2,1,0.125,45,YES

where the first number is the PCOMP card ID (same for all lines), the second is the material assigned to PCOMP card ID, the third is the ply thickness, the fourth is the ply orientation and the last one is the SOUT option (YES or NO)

Using the above-mentioned information as an input for your MACRO the resulting output (RADIOSS bulk or NASTRAN) for import inside HM will be:

PCOMP,2

,1,0.125,45.0,YES

,1,0.125,-45.0,YES

,1,0.125,-45.0,YES

,1,0.125,45.0,YES

Similar rule applies for the PCOMP(G) (ply-based modeling) entry card.

I think it is useful to use excel tables or the respective .csv as an input (instead of filling the tables in hyperlaminate inside HM) especially when dealing with large number of plies, or receiving ply data from the CATIA users.

Thanks for your attention

mvass

Share this post


Link to post
Share on other sites

hi mvass,

use the following code, wil do your work, hope this helps

##have kept comments for each line so that you can understand it and modify if required

proc setupPCOMP {} {

set matId 0

set plyThk 0

set plyAng 0

set numPlies 0

##ask for the csv file

set types {

{{csv Files} {.csv} }

}

set fname [tk_getOpenFile -filetypes $types]

#set fname "c:/temp/pcomp.csv"

##read the file to get number of plies

set fp 0;

set ret [catch {set fp [open "$fname" r+]} msg];

while {![eof $fp]} {

gets $fp line;

incr numPlies

}

##get num of proerties

set numprops [hm_entitymaxid props]

incr numprops

##create a propertycollector

*collectorcreateonly properties "pcomp-$numprops" "" 5

*createmark prop 1 -1

set colId [hm_getmark prop 1]

##load PCOMP dictionary

set dict "$::env(ALTAIR_HOME)/templates/feoutput/nastran/general"

*createmark prop 1 -1

*dictionaryload properties 1 "$dict" "PCOMP"

##set it to created property collector

*initializeattributes properties "pcomp-$numprops"

##create mark

*createmark properties $colId "pcomp-$numprops"

##set num plies

*attributeupdateint properties $colId 3027 1 0 0 $numPlies

##loop through the file again to set mat, thickness and ply angle

set fp 0;

set ret [catch {set fp [open "$fname" r+]} msg];

set matId 0

set matName ""

set plyThk {}

set plyAng {}

set soutopt {}

while {![eof $fp]} {

gets $fp line;

set tmplist [split $line ,];

lappend matId [lindex $tmplist 1]

##set material, will work only if material already exists !! hence kept in catch

catch {set matName [hm_getentityvalue mats $matId name 1 -byid]}

catch {*materialupdate properties $colId $matName}

lappend plyThk [lindex $tmplist 2]

lappend plyAng [lindex $tmplist 3]

lappend soutopt [lindex $tmplist 4]

}

##set ply thickness

eval *createdoublearray $numPlies $plyThk

*attributeupdatedoublearray properties $colId 3024 1 2 0 1 $numPlies

##set ply angle

eval *createdoublearray $numPlies $plyAng

*attributeupdatedoublearray properties $colId 3025 1 2 0 1 $numPlies

##set SOUT

eval *createstringarray $numPlies $soutopt

*attributeupdatestringarray properties $colId 3026 1 2 0 1 $numPlies

}

setupPCOMP

Share this post


Link to post
Share on other sites

Thank you very much CAE.DEVELOPER! What a fantastic work! I'll try it and let you know about the results. I am sure that many people will appreciate your effort.

Share this post


Link to post
Share on other sites

Hi! I've created a new MAT8 (2D orthotropic) material and then ran your script. It asked for a csv file, I loaded a simple one (just like the one in my example with material ID = 1) and I got the following error message:

can't read "::env(ALTAIR_HOME)": no such variable

can't read "::env(ALTAIR_HOME)": no such variable

while executing

"set dict "$::env(ALTAIR_HOME)/templates/feoutput/nastran/general""

(procedure "setupPCOMP" line 33)

invoked from within

"setupPCOMP"

(file "G:/Documents and Settings/user/Desktop/pcomp_from_excel.tcl" line 88)

invoked from within

"source {G:/Documents and Settings/user/Desktop/pcomp_from_excel.tcl}"

("uplevel" body line 1)

invoked from within

"uplevel #0 "source {$file}""

(procedure "::HM_Framework::P_FileLoad" line 49)

invoked from within

"::HM_Framework::P_FileLoad 24"

(menu invoke)

Thank you in advance for your assistance.

Share this post


Link to post
Share on other sites

actually there will be an environment variable ALTAIR_HOME define in HM installation, which points to ../altair100/hw10.0 directory. In my case it is like c:/prog/altair100/hw10.0.

The script needs to know this location to load some libraries.

If it is not there, can you add this environment variable yourself and then run the script?

Share this post


Link to post
Share on other sites

Hi, thanks for the reply. I kinda understood that the script cannot find the environment variable, however I cannot locate it in our installation. We have HWs installed in C:\Altair\hw10.0\

So, can you please explain how to do this? I am sorry but I haven't programmed with tcl before.

Thank you in advance

Share this post


Link to post
Share on other sites

hi mvass,

try this

##have kept comments for each line so that you can understand it and modify if required

proc setupPCOMP {} {

set matId 0

set plyThk 0

set plyAng 0

set numPlies 0

##ask for the csv file

set types {

{{csv Files} {.csv} }

}

set fname [tk_getOpenFile -filetypes $types]

#set fname "c:/temp/pcomp.csv"

##read the file to get number of plies

set fp 0;

set ret [catch {set fp [open "$fname" r+]} msg];

while {![eof $fp]} {

gets $fp line;

incr numPlies

}

##get num of proerties

set numprops [hm_entitymaxid props]

incr numprops

##create a propertycollector

*collectorcreateonly properties "pcomp-$numprops" "" 5

*createmark prop 1 -1

set colId [hm_getmark prop 1]

set ::env(ALTAIR_HOME) "C:/Altair/hw10.0"

##load PCOMP dictionary

set dict "$::env(ALTAIR_HOME)/templates/feoutput/nastran/general"

*createmark prop 1 -1

*dictionaryload properties 1 "$dict" "PCOMP"

##set it to created property collector

*initializeattributes properties "pcomp-$numprops"

##create mark

*createmark properties $colId "pcomp-$numprops"

##set num plies

*attributeupdateint properties $colId 3027 1 0 0 $numPlies

##loop through the file again to set mat, thickness and ply angle

set fp 0;

set ret [catch {set fp [open "$fname" r+]} msg];

set matId 0

set matName ""

set plyThk {}

set plyAng {}

set soutopt {}

while {![eof $fp]} {

gets $fp line;

set tmplist [split $line ,];

lappend matId [lindex $tmplist 1]

##set material, will work only if material already exists !! hence kept in catch

catch {set matName [hm_getentityvalue mats $matId name 1 -byid]}

catch {*materialupdate properties $colId $matName}

lappend plyThk [lindex $tmplist 2]

lappend plyAng [lindex $tmplist 3]

lappend soutopt [lindex $tmplist 4]

}

##set ply thickness

eval *createdoublearray $numPlies $plyThk

*attributeupdatedoublearray properties $colId 3024 1 2 0 1 $numPlies

##set ply angle

eval *createdoublearray $numPlies $plyAng

*attributeupdatedoublearray properties $colId 3025 1 2 0 1 $numPlies

##set SOUT

eval *createstringarray $numPlies $soutopt

*attributeupdatestringarray properties $colId 3026 1 2 0 1 $numPlies

}

setupPCOMP

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

-- cae.developer@gmail.com

Share this post


Link to post
Share on other sites

I am sorry to trouble you again but now I get the following error message:

0

0

while executing

"*dictionaryload properties 1 "$dict" "PCOMP""

(procedure "setupPCOMP" line 35)

invoked from within

"setupPCOMP"

(file "C:/Documents and Settings/user/Desktop/pcomp_excel_v2.tcl" line 88)

invoked from within

"source {C:/Documents and Settings/user/Desktop/pcomp_excel_v2.tcl}"

("uplevel" body line 1)

invoked from within

"uplevel #0 "source {$file}""

(procedure "::HM_Framework::P_FileLoad" line 49)

invoked from within

"::HM_Framework::P_FileLoad 24"

(menu invoke)

I simply copied your code to notepad++ and saved it as pcomp_excel_v2.tcl on my desktop. Then I created a simple .csv file like:

1,1,0.125,45,YES

1,1,0.125,-45,YES

1,1,0.125,-45,YES

1,1,0.125,45,YES

In Hypermesh I created a MAT8 material with material ID 1 and loaded the .tcl created before. After loading the .csv a pcomp property is created but with the error message seen above.

Again, thank you in advance for your kind assistance.

Share this post


Link to post
Share on other sites

Confusion reins!

Your code works like a charm! Thank you, THANK YOU! Sorry for troubling you but I've made a huge mistake: HWs is not installed in c:/Altair/hw10.0 on our system but on: e:/Altair... (](*,) ), so after changing this in your code -guess what...- it WORKED!

You have my respects and thanks!

(Now I'll try to copy and modify your code for the PCOMPG entry. I'll let you know)

mvass

PS: Yes, I am using the NASTRAN profile

Share this post


Link to post
Share on other sites
Guest

instead of using system variables or hard-coding the paths, use the following code to set the nastran template.

	set templatedir [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR];	set dict [file join $templatedir "feoutput" "nastran" "general"];

Hypermesh knows where it is installed, the code above will take care of that.

have fun!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...