# DXF2ANN.AWK 1.6 # # Created by : Francois Valcourt 97-09-11 # # Modified by : Marc St-Germain 98-09-16 # (Major restructuration of the script) # # Modified by : Marc St-Germain 99-05-05 # (Modification of the script to test that each treated # blocks begin by 0) # # Modified by : Marc St-Germain 99-05-10 # (Modification of the script. A line ( getline) was deleted # in the TEXT block.) # # (c) INRO Consultant Inc. Montreal, 1997 # # Syntax : # # When using hardware coordinates: # # DOS: # gawk -f dxf2ann.awk -v user=no file.dxf >filename # UNIX: # gawk -f dxf2ann.awk -v user=no file.dxf >filename # # When using user coordinates: # # DOS: # gawk -f dxf2ann.awk file.dxf >filename # UNIX: # gawk -f dxf2ann.awk file.dxf >filename # # # This script converts a DXF file into an EMME/2 or STAN annotation file. # It strictly converts Lines, Points, Solids, Text, Circles, Arcs, # Line patterns, and Colors. # # All other types of blocks are not converted. # # BEGIN { # # Definition of global variables # FS=" " color=1 last_color=1 line_pattern=1 temp_string="u1 " # Value of piarc= 3.14159265359/180 piarc=0.01745329252 # Definition of the Convert_Line_Pattern Table. For the # conversion of AUTOCAD Line Pattern (with files created in AUTOCAD into # EMME/2 or STAN line patterns. empat["CONTINUOUS"]=0 empat["DOT"]=1 empat["DOT2"]=1 empat["DOTX2"]=1 empat["ACAD_ISO07W100"]=1 empat["BORDER"]=2 empat["BORDER2"]=2 empat["BORDERX2"]=2 empat["DASHDOT"]=2 empat["DASHDOT2"]=2 empat["DASHDOTX2"]=2 empat["DIVIDE"]=2 empat["DIVIDE2"]=2 empat["DIVIDEX2"]=2 empat["ACAD_ISO04W100"]=2 empat["ACAD_ISO05W100"]=2 empat["ACAD_ISO06W100"]=2 empat["ACAD_ISO10W100"]=2 empat["ACAD_ISO11W100"]=2 empat["ACAD_ISO12W100"]=2 empat["ACAD_ISO13W100"]=2 empat["ACAD_ISO14W100"]=2 empat["ACAD_ISO15W100"]=2 empat["DASHED2"]=3 empat["HIDDEN"]=3 empat["HIDDEN2"]=3 empat["CENTER"]=4 empat["CENTER2"]=4 empat["CENTERX2"]=4 empat["DASHED"]=4 empat["DASHEDX2"]=4 empat["HIDDENX2"]=4 empat["PHANTOM"]=4 empat["PHANTOM2"]=4 empat["PHANTOMX2"]=4 empat["ACAD_ISO02W100"]=4 empat["ACAD_ISO03W100"]=4 empat["ACAD_ISO08W100"]=4 empat["ACAD_ISO09W100"]=4 # Definition of DXF files line pattern from emme2 ( using gpl )_ empat["1"]=0 empat["2"]=1 empat["3"]=2 empat["4"]=3 empat["5"]=4 # Definition of the Convert_Color Table. For the conver- # sion of AUTOCAD Line Pattern into EMME/2 or STAN # line patterns. emcol["1"]=1 emcol["RED"]=1 emcol["2"]=6 emcol["YELLOW"]=6 emcol["4"]=4 emcol["CYAN"]=4 emcol["5"]=3 emcol["BLUE"]=3 emcol["7"]=0 emcol["WHITE"]=0 emcol["0"]=0 emcol["3"]=2 emcol["GREEN"]=2 emcol["6"]=5 emcol["MAGENTA"]=5 # # Set the annotation in User or Hardware Coordinates # if (substr(user,1,1)=="n") temp_string="u0 " printf("%s", temp_string) # # Create annotation header # printf("/Annotation File Created by DXF2ANN.AWK Version 2.0\n") } # # Ignore any BLOCK entity and its contents # $1=="BLOCK", $1=="ENDBLK" {next} # Convert LINE objects # $1=="LINE" && previous =="0" { fin=0 color=1 line_pattern=1 flag=0 flag2=0 color_flag=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="6") { flag2=1 Convert_Line_Pattern() } else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") x_start=$1 else if (code=="20") y_start=$1 else if (code=="11") x_end=$1 else if (code=="21") y_end=$1 } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) printf("m %f %f /Handle %s\nd %f %f\n", x_start, y_start, label, x_end, y_end) next } # # Convert POINT objects # $1=="POINT" && previous=="0" { fin=0 color=1 flag=0 flag2=0 color_flag=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") { x_start=$1 x_end=$1 } else if (code=="20") { y_start=$1 y_end=$1 } } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) printf("m %f %f /Handle %s\nd %f %f\n", x_start, y_start, label, x_end, y_end) next } # # Convert SOLID objects # $1=="SOLID" && previous=="0" { fin=0 color=1 line_pattern=1 flag=0 flag2=0 color_flag=0 x1=0 y1=0 x2=0 y2=0 x3=0 y3=0 x4=0 y4=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="6") { flag2=1 Convert_Line_Pattern() } else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") x1=$1 else if (code=="20") y1=$1 else if (code=="11") x2=$1 else if (code=="21") y2=$1 else if (code=="12") x3=$1 else if (code=="22") y3=$1 else if (code=="13") x4=$1 else if (code=="23") y4=$1 } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) printf("m %f %f /Handle %s\nd %f %f\nd %f %f\nd %f %f\nd %f %f\n", x1, y1, label, x2, y2, x3, y3, x4, y4, x1, y1) next } # # Convert TEXT objects # $1=="TEXT" && previous=="0" { fin=0 color=1 flag=0 flag2=0 color_flag=0 text_height=0 text="" text_angle=0 text_slant=0 text_angle_flag=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") x_start=$1 else if (code=="20") y_start=$1 else if (code=="40") text_height=$1 else if (code=="1") text=$0 else if (code=="51") { text_slant=$1 text_slant=text_slant*piarc } else if (code=="50") { x=0 y=0 text_angle=$1 text_angle_flag=1 x=cos(text_angle*piarc) y=sin(text_angle*piarc) } } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) if (text_angle_flag==1) printf("a %f %f\n", x, y) printf("s %f %f\n", text_height, text_slant) printf("t %f %f %s\n", x_start, y_start, text) next } # # Convert CIRCLE objects # $1=="CIRCLE" && previous=="0" { color=1 fin=0 flag=0 color_flag=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") x_start=$1 else if (code=="20") y_start=$1 else if (code=="40") radius=$1 } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) printf("m %f %f /Handle %s\no %f %f\n", x_start, y_start, label, x_start+radius, y_start) next } # # Convert ARC objects # $1=="ARC" && previous=="0" { color=1 fin=0 flag=0 color_flag=0 while (fin==0) { getline if ($1=="0") fin=1 else { code=$1 getline if (code=="5") label=$1 else if (code=="8") { flag=1 color=$1 color_flag=1 } else if (code=="62") { flag=1 color=$1 color_flag=1 } else if (code=="10") x_start=$1 else if (code=="20") y_start=$1 else if (code=="40") radius=$1 else if (code=="50") ang_st=$1 else if (code=="51") ang_end=$1 } } if (color_flag==1) Convert_color(color) last_color=color if (flag==0) printf("c%d\n", color) Arc() next } # The variable "previous" is used to check if the value of the line is 0 (indicating the # beginning of a new block (object). This new block is tested if it will be converted # or not. { previous=$1 } # # Creates an ARC # function Arc() { premier=0 if (ang_st > ang_end) { temp_value=ang_st ang_st=0 for (i=ang_st;i<(ang_end-0.00000001);i+=6) { x=x_start + cos(i*piarc)*radius y=y_start + sin(i*piarc)*radius if (premier==0) { printf("m %f %f /Handle %s\n", x, y, label) premier=1 } else printf("d %f %f\n", x, y) } x=x_start + cos((ang_end-0.00000001)*piarc)*radius y=y_start + sin((ang_end-0.00000001)*piarc)*radius printf("d %f %f\n", x, y) ang_st=temp_value ang_end=360 } premier=0 for (i=ang_st;i<(ang_end-0.00000001);i+=6) { x=x_start + cos(i*piarc)*radius y=y_start + sin(i*piarc)*radius if (premier==0) { printf("m %f %f /Handle %s\n", x, y, label) premier=1 } else printf("d %f %f\n", x, y) } x=x_start + cos((ang_end-0.00000001)*piarc)*radius y=y_start + sin((ang_end-0.00000001)*piarc)*radius printf("d %f %f\n", x, y) } # # Convert AUTOCAD colors into EMME/2 or STAN color patterns # function Convert_color(col) { # If the color does not exist: color=1. # It will be treated like the color "white" color=emcol[col]+1 if (color != previous_color) { printf("c%d\n",color) previous_color = color } } # # Convert AUTOCAD line patterns into EMME/2 or STAN line patterns # function Convert_Line_Pattern() { # If the line pattern does not exist: line_pattern=1. # It will be treated like the line pattern "CONTINUOUS" line_pattern = empat[$1] + 1 if (line_pattern != previous_pattern) { printf("l%d\n", line_pattern) previous_pattern = line_pattern } }