Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I would like to take the following file:
!
! *** UNIGRAPHICS-TO-ANSYS CORRESPONDENCE TABLE FILE ***! *** This version of the connection was validated with UG NX 2.0.0.21
!
! Version : 8.1 - UG NX V2.0
! Build date : 03/25/04
! Generated on: 08/08/05 15:20
! By : bz0tkb
!
! Part : junk
! Units : Inches
! Selected Layers : 1-256
! Geometry Type : Solids Only
!
! Translator Working Tolerance: 5.0000000E-05
! Part system Tolerance (ref): 1.0000000E-05
!
!Object Name ANSYS Type ANSYS ID
EDGE2 LINE 3
EDGE1 LINE 4
SIDE1 AREA 2
BOTTOM AREA 3
SIDE2 AREA 4
TOP AREA 5
SCOTT AREAand put in a different file the following:
LSEL,S,,,3
CM,EDGE2,LINEetc., to the end of the file.
Can somone help?

Okay, the following gives me the first three lines...but I need to go to the end of file...
Like:until EOF do
getline
printf("%s etc..
endcan someone help with the proper control flow syntax to get to the eof please...
#! /bin/nawk -f
#
# flexeng_edit.awk - Save the mount load data
# from a flexeng output listing.
#
BEGIN {# Initialize some handy constants
TRUE = 1
FALSE = 0
fatal_error = FALSE# Check the number of command line parameters
if ( ARGC != 2 )
{
printf("Usage: ansys_comp.awk tbl_file.tbl > ansys_component_file\n")
fatal_error = TRUE
exit(-1)
}}
#
/^ *!Object/ {getline
printf("%s\n",$0)
getline
printf("%s\n",$0)
getline
printf("%s\n",$0)
next
}END {
# Don't do anything if fatal error found
if ( fatal_error == TRUE )
{
exit(-1)
}}
Scott

Scott,
The sample input file is good, but you completely lost me on this:
and put in a different file the following:
LSEL,S,,,3
CM,EDGE2,LINEetc., to the end of the file.
I do not see where that data comes from.

Hi guys, thanks for responding! :)
Okay I have the following working...
#! /bin/nawk -f
#
# flexeng_edit.awk - Save the mount load data
# from a flexeng output listing.
#
BEGIN {# Initialize some handy constants
TRUE = 1
FALSE = 0
fatal_error = FALSE# Check the number of command line parameters
if ( ARGC != 2 )
{
printf("Usage: ansys_comp.awk tbl_file.tbl > ansys_component_file\n")
fatal_error = TRUE
exit(-1)
}}
/^ *!Object/ {
getline
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }getline
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }getline
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }next
}END {
# Don't do anything if fatal error found
if ( fatal_error == TRUE )
{
exit(-1)
}}
But, I need the chunk that is repeated 3 (or 'n') times to be put into a while loop so it just continues to the end of the file that this info is coming from.So something like this...
while ( != EOF ) # while not end of file...
dogetline
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }done
What do you guys think? It seems like it should be easy but I can't get it.
Thanks in advance!! :)
Scott

Okay, here's where the info is coming from:
!
! *** UNIGRAPHICS-TO-ANSYS CORRESPONDENCE TABLE FILE ***! *** This version of the connection was validated with UG NX 2.0.0.21
!
! Version : 8.1 - UG NX V2.0
! Build date : 03/25/04
! Generated on: 08/09/05 10:34
! By : bz0tkb
!
! Part : scott1
! Units : Inches
! Selected Layers : 1-256
! Geometry Type : Solids Only
!
! Translator Working Tolerance: 5.0000000E-05
! Part system Tolerance (ref): 1.0000000E-05
!
!Object Name ANSYS Type ANSYS ID
EDGE1 LINE 4
SMEDGE LINE 8
SIDE1 AREA 1
TOP AREA 4

Right, once you pop into the /!Object/ code block, you have to remain in there to process all following lines. If you exit that code block, the main loop will bypass the remaining lines looking for the next /!Object/.
You can code the loop as follows:
/^ *!Object/ {
while (getline > 0)
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else
if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }}
And here is a different approach. This code produces the identical output as the code above. The BEGIN block bypasses the first part of the file through the !Object line. With those lines out of the way, the main detail block does not need a loop.#! /bin/sh
awk 'BEGIN \
{while (true)
{getline
if (match($0,"!Object"))
break
}
}{if ($2 == "LINE")
{printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1)}
else
if ($2 == "AREA")
{printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1)}}' filein > fileout

I'm afraid my problem needs a bit more tweaking. That's because it needs to accomodate multiple occurances of entities of the same name. If you can possibly help, please take a look at the following description. I humbly ask for your help and would be forever grateful, honestly.
This is what I'm starting with:
!
! *** UNIGRAPHICS-TO-ANSYS CORRESPONDENCE TABLE FILE ***! *** This version of the connection was validated with UG NX 2.0.0.21
!
! Version : 8.1 - UG NX V2.0
! Build date : 03/25/04
! Generated on: 08/18/05 08:34
! By : bz0tkb
!
! Part : block
! Units : Inches
! Selected Layers : 1-256
! Geometry Type : Solids Only
!
! Translator Working Tolerance: 5.0000000E-05
! Part system Tolerance (ref): 1.0000000E-05
!
!Object Name ANSYS Type ANSYS ID
EDGE LINE 2
FACE AREA 4
EDGE LINE 3
EDGE LINE 6
FACE AREA 5
EDGE LINE 10
FACE AREA 3
First I need this sorted to look like this (this part I don't yet have in my awk script):
EDGE LINE 2
EDGE LINE 10
EDGE LINE 3
EDGE LINE 6
FACE AREA 5
FACE AREA 4
FACE AREA 3
Then formated to look like this (I have most of this from Jim's input which I have added below but it's currently not smart enough to determine when to use the 'S' and when to use the 'A'):LSEL,S,,,2
CM,EDGE,LINELSEL,A,,,10
CM,EDGE,LINELSEL,A,,,3
CM,EDGE,LINELSEL,A,,,6
CM,EDGE,LINEASEL,S,,,5
CM,FACE,AREAASEL,A,,,4
CM,FACE,AREAASEL,A,,,3
CM,FACE,AREA
Note that the first instance of a name must have the 'S' and following instances of that same name must have the 'A'.This is what I currently have from Jim which works perfect but only for a single occurance of some entity name:
while ( getline > 0 )
if ( $2 == "LINE" )
{ printf("LSEL,S,,,%s\n",$3)
printf("CM,%s,LINE\n",$1) }
else if ( $2 == "AREA" )
{ printf("ASEL,S,,,%s\n",$3)
printf("CM,%s,AREA\n",$1) }

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |