Ir ao conteúdo

Script exportar em outro formato


rafael.luc

Posts recomendados

Postado

Olá

Eu gostaria de fazer um script para exportar um formato que no caso é .dxf

Tenho este script que transforma um dxf em .shc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define M_PI 3.141592654

/* ========================================================= */

void main(int argument_count, char *argument[], char *environment[])
{
char s[100],p;
int
i,
state,
lines,
arcs,
circles,
linewidth=1;
float x,y,x1,y1,x2,y2,x3,y3,r,theta1,theta3,xorg,yorg;
FILE *ifile,*ofile;

const char* dufus=
"Program that crunches a DXF file with circles, arcs and lines\n"
"into an Eagle script file. Items are put on the dimension layer.\n"
"Usage:\n\n"
" A> DXF2SCR FILE.DXF FILE.SCR Xorg Yorg\n\n"
"Where FILE.DXF is the name of the DXF file, and FILE.SCR is the\n"
" output file. (Xorg,Yorg) is the origin of the output file.\n"
" Xorg and Yorg are in decimal inches.\n";

if (argument_count != 5)
{
printf(dufus);
exit(1);
}

if ((ifile=fopen(argument[1],"ra")) == NULL)
{
printf(dufus);
exit(1);
}

if ((ofile=fopen(argument[2],"wa")) == NULL)
{
printf(dufus);
exit(1);
}

xorg=atof(argument[3])*1000;
yorg=atof(argument[4])*1000;

fprintf(ofile,"# DXF2SCR generated script file.\n");
fprintf(ofile,"Grid mil 1 off;\n");
fprintf(ofile,"Set Wire_Bend 2;\n");
fprintf(ofile,"Layer Dimension;\n");
fprintf(ofile,"Change Font Vector;\n");

state=0;
lines=arcs=circles=0;
while (!feof(ifile))
{
*s=0;
if (fgets(s,sizeof(s)-1,ifile) == NULL)
break;

switch (state)
{
case 0: // scanning for SECTION
if (strncmp(s,"SECTION",7) == 0)
state=1;
break;
case 1: // scanning for ENTITIES
if (strncmp(s,"ENDSEC",6) == 0)
state=0;
if (strncmp(s,"ENTITIES",8) == 0)
state=2;
break;
case 2: // scanning for LINE, ARC or CIRCLE
if (strncmp(s,"ENDSEC",6) == 0)
state=0;
if (strncmp(s,"LINE",4) == 0)
{
state=3;
lines++;
}
if (strncmp(s,"ARC",3) == 0)
{
state=4;
arcs++;
}
if (strncmp(s,"CIRCLE",6) == 0)
{
state=5;
circles++;
}
break;
case 3: // absorbing LINE
// LINE 10, 20, 30 (start point), 11, 21, 31 (end point).
if (strncmp(s," 10",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
x=1000*atof(s);
}
if (strncmp(s," 20",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
y=1000*atof(s);
}
if (strncmp(s," 11",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
x1=1000*atof(s);
}
if (strncmp(s," 21",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
y1=1000*atof(s);
fprintf(ofile,"Wire %d (%0.0f %0.0f) (%0.0f %0.0f);\n",
linewidth,x+xorg,y+yorg,x1+xorg,y1+yorg);
state=2;
}
break;
case 4: // absorbing ARC
// ARC 10, 20, 30 (center), 40 (radius), 50 (start angle), 51 (end
if (strncmp(s," 10",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
x=1000*atof(s);
}
if (strncmp(s," 20",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
y=1000*atof(s);
}
if (strncmp(s," 40",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
r=1000*atof(s);
}
if (strncmp(s," 50",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
theta1=atof(s);
theta1*=(M_PI/180);
}
if (strncmp(s," 51",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
theta3=atof(s);
theta3*=(M_PI/180);

// compute Eagle arc parameters from DXF arc params
x1=r*cos(theta1)+x;
y1=r*sin(theta1)+y;
x2=x1-2*r*cos(theta1);
y2=y1-2*r*sin(theta1);
x3=r*cos(theta3)+x;
y3=r*sin(theta3)+y;

fprintf(ofile,"Arc CCW %d (%0.0f %0.0f) (%0.0f %0.0f) (%0.0f %0.0f);\n",
linewidth,x1+xorg,y1+yorg,x2+xorg,y2+yorg,x3+xorg,y3+yorg);
state=2;
}
break;
case 5: // absorbing CIRCLE
// CIRCLE 10, 20, 30 (center), 40 (radius).
if (strncmp(s," 10",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
x=1000*atof(s);
}
if (strncmp(s," 20",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
y=1000*atof(s);
}
if (strncmp(s," 40",3) == 0)
{
fgets(s,sizeof(s)-1,ifile);
y1=1000*atof(s);
fprintf(ofile,"Circle %d (%0.0f %0.0f) (%0.0f %0.0f);\n",
linewidth,x+xorg,y+yorg,x+xorg,y+y1+yorg);
state=2;
}
break;
}
}

fprintf(ofile,"Window Fit;\n");
fprintf(ofile,"# lines=%d, arcs=%d, circles=%d\n",lines,arcs,circles);
fclose(ifile);
fclose(ofile);
exit(0);
}

O que gostaria é transformar um .DSN em DXF

um exemplo de .DSN

<?xml version="1.0" encoding="UTF-8"?>

<!--This file was written by TinyCAD Version 2.80.02 Build #462 Production Release
If you wish to view this file go to http://tinycad.sourceforge.net to
download a copy.-->
<TinyCADSheets>
<TinyCAD>
<NAME>Sheet 1</NAME>
<DETAILS>
<Size width='1485' height='1050'/>
<GUIDES horiz='7' vert='5'/>
<TITLE></TITLE>
<AUTHOR></AUTHOR>
<REVISION>1.0</REVISION>
<DOCNUMBER></DOCNUMBER>
<ORGANISATION></ORGANISATION>
<SHEETS>1 of 1</SHEETS>
<SHOWS>1</SHOWS>
<DATE></DATE>
<GRID spacing='100.00000' snap='1'/>
</DETAILS>
<FONT id='1'>
<HEIGHT>-10</HEIGHT>
<WIDTH>0</WIDTH>
<WEIGHT>400</WEIGHT>
<ITALIC>0</ITALIC>
<UNDERLINE>0</UNDERLINE>
<STRIKEOUT>0</STRIKEOUT>
<CHARSET>0</CHARSET>
<FACENAME>Arial</FACENAME>
</FONT>
<FONT id='3'>
<HEIGHT>-11</HEIGHT>
<WIDTH>5</WIDTH>
<WEIGHT>400</WEIGHT>
<ITALIC>0</ITALIC>
<UNDERLINE>0</UNDERLINE>
<STRIKEOUT>0</STRIKEOUT>
<CHARSET>0</CHARSET>
<FACENAME>Arial</FACENAME>
</FONT>
<STYLE id='2'>
<STYLE>0</STYLE>
<COLOR>000000</COLOR>
<THICKNESS>1</THICKNESS>
</STYLE>
<FILL id='0'>
<INDEX>-1</INDEX>
<COLOR>000000</COLOR>
</FILL>
<SYMBOLDEF id='1'>
<NAME type='0'>LM317</NAME>
<REF type='1'>U?</REF>
<DESCRIPTION>Variable Voltage Regulator 1.5A</DESCRIPTION>
<PPP>1</PPP>
<FIELD>
<NAME>Package</NAME>
<DEFAULT>TO-220</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Usage</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Datasheet</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Picture</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>V_Out_Nom</NAME>
<DEFAULT>1.25V-37V</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>V_Out_Tol</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Current</NAME>
<DEFAULT>1.5</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>P_Max</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Manufacturer</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Manufacturer Part</NAME>
<DEFAULT>Fairchild Semiconductor</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Digi-Key Part</NAME>
<DEFAULT>LM317T</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Newark Part</NAME>
<DEFAULT>LM317TFS-ND </DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Mouser Part</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<FIELD>
<NAME>Cost</NAME>
<DEFAULT>..</DEFAULT>
<FT>000001</FT>
<VALUE></VALUE>
<POS>1.#QNAN,1.#QNAN</POS>
</FIELD>
<REF_POINT power='0' part='0' pos='40.00000,35.00000'/>
<TinyCAD>
<PIN pos='20.00000,23.00000' which='0' elec='0' direction='3' part='0' number='1' show='1' length='30' number_pos='0' centre_name='0'></PIN>
<PIN pos='30.00000,34.00000' which='0' elec='0' direction='0' part='0' number='2' show='1' length='30' number_pos='0' centre_name='0'></PIN>
<PIN pos='40.00000,23.00000' which='0' elec='1' direction='2' part='0' number='3' show='1' length='30' number_pos='0' centre_name='0'></PIN>
<TEXT pos='35.00000,23.00000' direction='3' font='3' color='000000'>Out</TEXT>
<TEXT pos='22.00000,23.00000' direction='3' font='3' color='000000'>In</TEXT>
<TEXT pos='32.80000,33.20000' direction='0' font='3' color='000000'>Adj</TEXT>
<POLYGON pos='25.00000,23.00000' style='2' fill='0'>
<POINT pos='1.00000,0.00000' arc='0'/>
<POINT pos='0.00000,0.00000' arc='0'/>
</POLYGON>
<POLYGON pos='34.00000,23.00000' style='2' fill='0'>
<POINT pos='0.00000,0.00000' arc='0'/>
<POINT pos='1.00000,0.00000' arc='0'/>
</POLYGON>
<POLYGON pos='30.00000,28.00000' style='2' fill='0'>
<POINT pos='0.00000,0.00000' arc='0'/>
<POINT pos='0.00000,1.00000' arc='0'/>
</POLYGON>
<RECTANGLE a='34.00000,22.00000' b='26.00000,28.00000' style='2' fill='0'/>
</TinyCAD>
</SYMBOLDEF>
<OPTIONS>
<GRID>0</GRID>
<UNITS>0</UNITS>
<COLOR_WIRE>FF0000</COLOR_WIRE>
<COLOR_BUS>0000FF</COLOR_BUS>
<COLOR_JUNCTION>000000</COLOR_JUNCTION>
<COLOR_NOCONNECT>000000</COLOR_NOCONNECT>
<COLOR_LABEL>208000</COLOR_LABEL>
<COLOR_POWER>000000</COLOR_POWER>
<COLOR_PIN>4040C0</COLOR_PIN>
<COLOR_HIDDEN_PIN>208020</COLOR_HIDDEN_PIN>
<COLOR_BACKGROUND>FFFFFF</COLOR_BACKGROUND>
</OPTIONS>
<SYMBOL id='1' pos='52.00000,50.00000' part='0' rotate='0' can_scale='0' show_power='0' scale_x='1.00000' scale_y='1.00000'>
<FIELD type='1' description='Ref' value='U?' show='1' pos='1.00000,-11.60000'/>
<FIELD type='0' description='Name' value='LM317' show='1' pos='1.00000,-14.00000'/>
<FIELD type='1' description='Package' value='TO-220' show='0' pos='1.00000,-9.20000'/>
<FIELD type='1' description='Usage' value='..' show='0' pos='1.00000,-6.80000'/>
<FIELD type='1' description='Datasheet' value='..' show='0' pos='1.00000,-4.40000'/>
<FIELD type='1' description='Picture' value='..' show='0' pos='1.00000,-2.00000'/>
<FIELD type='1' description='V_Out_Nom' value='1.25V-37V' show='0' pos='1.00000,0.40000'/>
<FIELD type='1' description='V_Out_Tol' value='..' show='0' pos='1.00000,2.80000'/>
<FIELD type='1' description='Current' value='1.5' show='0' pos='1.00000,5.20000'/>
<FIELD type='1' description='P_Max' value='..' show='0' pos='1.00000,7.60000'/>
<FIELD type='1' description='Manufacturer' value='..' show='0' pos='1.00000,10.00000'/>
<FIELD type='1' description='Manufacturer Part' value='Fairchild Semiconductor' show='0' pos='1.00000,12.40000'/>
<FIELD type='1' description='Digi-Key Part' value='LM317T' show='0' pos='1.00000,14.80000'/>
<FIELD type='1' description='Newark Part' value='LM317TFS-ND ' show='0' pos='1.00000,17.20000'/>
<FIELD type='1' description='Mouser Part' value='..' show='0' pos='1.00000,19.60000'/>
<FIELD type='1' description='Cost' value='..' show='0' pos='1.00000,22.00000'/>
</SYMBOL>
<WIRE a='6.00000,18.00000' b='84.00000,18.00000'/>
</TinyCAD>
</TinyCADSheets>

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...