資源簡介
本程序可以很好地讀取DXF文件,可以輸出直線(c_Line)多段線(c_Poly)圓(c_Cir)圓弧(c_Arc)頂點(diǎn)(c_Poi),很實(shí)用
代碼片段和文件信息
function?[c_Linec_Polyc_Circ_Arcc_Poi]?=?f_LectDxf(nomArch)
%%?Read?entities?information?of?dxf?file
????%author?=?SebaTM?
????%Jul?27?2009
????%based?in?dxf2coord?1.1?matrix?of?lukas?wischounig?but?is?not?dependent?of?the?Code?
????%Group?relative?position.?That?is?better?way?to?read?dxf?format.?Don‘t?fail?if?the?
????%polyline?has?arcs?(budges)?but?yet?don‘t?read?them.?Don‘t?read?arcs?as?circles.?Read?
????%properties?(see?case?‘LINE‘?by?examples?of?modifications).?Group?Codes?and?Associated?
????%Values?is?read?in?accurately?way?(accept?associated?values?with?space).
????%
????%Use?cell2mat(cell(:1))?to?acquire?geometry?data?in?matrix?
????%by?example?cell2mat(c_Cir(:1))
?
%%?Read?file
????fId?=?fopen(nomArch);????
????c_ValAsoc?=?textscan(fId‘%d%s‘‘Delimiter‘‘\n‘);
????fclose(fId);
????%?Code?Group?Matrix
????m_GrCode?=?c_ValAsoc{1};
????%?Associated?value?String?Cell
????c_ValAsoc?=?c_ValAsoc{2};
????%[m_GrCodec_ValAsoc]?=?c_ValAsoc{:};
????
%%?Entities
????m_PosCero?=?find(m_GrCode==0);
????%Is?searched?by?(0SECTION)(2ENTITIES)
????indInSecEnt?=?strmatch(‘ENTITIES‘c_ValAsoc(m_PosCero(1:end-1)+1)‘exact‘);
????%(0ENDSEC)
????m_indFinSecEnt?=?strmatch(‘ENDSEC‘c_ValAsoc(m_PosCero(indInSecEnt:end))‘exact‘);
????%?Entities?Position
????m_PosCero?=?m_PosCero(indInSecEnt:indInSecEnt-1+m_indFinSecEnt(1));
????%?Variable?initiation
????%accelerate?
%?????c_Line?=?cell(sum(strcmp(‘LINE‘c_ValAsoc(m_PosCero)))2);
%?????c_Poly?=?cell(sum(strcmp(‘LWPOLYLINE‘c_ValAsoc(m_PosCero)))2);
%?????c_Cir?=?cell(sum(strcmp(‘CIRCLE‘c_ValAsoc(m_PosCero)))2);
%?????c_Arc?=?cell(sum(strcmp(‘ARC‘c_ValAsoc(m_PosCero)))2);
%?????c_Poi?=?cell(sum(strcmp(‘POINT‘c_ValAsoc(m_PosCero)))2);
????c_Line?=?cell(12);
????c_Poly?=?cell(12);
????c_Cir?=?cell(12);
????c_Arc?=?cell(12);
????c_Poi?=?cell(12);
????%
????iLine?=?1;
????iPoly?=?1;
????iCir?=?1;??
????iArc?=?1;
????iPoi?=?1;
????%?Loop?on?the?Entities
????for?iEnt?=?1:length(m_PosCero)-2
????????m_GrCodeEnt?=?m_GrCode(m_PosCero(iEnt+1):m_PosCero(iEnt+2)-1);
????????c_ValAsocEnt?=?c_ValAsoc(m_PosCero(iEnt+1):m_PosCero(iEnt+2)-1);
????????nomEnt?=?c_ValAsocEnt{1};??%c_ValAsocEnt{m_PosCero(iEnt+1)}
????????%In?the?entitie‘s?name?is?assumed?uppercase
????????switch?nomEnt????????????
????????????case?‘LINE‘
????????????????%?(XiYiZiXjYjZj)?start?and?end?points
????????????????c_Line{iLine1}?=?[str2double(f_ValGrCode(10m_GrCodeEntc_ValAsocEnt))...
????????????????????str2double(f_ValGrCode(20m_GrCodeEntc_ValAsocEnt))...
????????????????????str2double(f_ValGrCode(30m_GrCodeEntc_ValAsocEnt))...
????????????????????str2double(f_ValGrCode(11m_GrCodeEntc_ValAsocEnt))...
????????????????????str2double(f_ValGrCode(21m_GrCodeEntc_ValAsocEnt))...
????????????????????str2double(f_ValGrCode(31m_GrCodeEntc_ValAsocEnt))];
????????????????%?layer
????????????????c_Line(iLine2)?=?f_ValGrCode(8m_GrCodeEntc_ValAsocEnt);
評(píng)論
共有 條評(píng)論