java 读取dwg_Java 读取 dwg 转换 dxf

2019独角兽企业重金招聘Python工程师标准>>>

kabeja-0.4.jar

1.java 读取 dxf 字符

@Test

public void JunitGetContent(){

String dxfPath="D:\1-test-exe\out\cwp.dxf"; // 默认 /x2004 的参数

String docContent = getDocContent(dxfPath);

System.out.println(docContent);

String dxfPath2="D:\1-test-exe\out\X2010.dxf"; // 解析 /x2010 参数转换的文件

String docContent2 = getDocContent(dxfPath2);

System.out.println(docContent2);

}

public String getDocContent(String sourceFile){

StringBuffer strResult = new StringBuffer();

Parser parser = ParserBuilder.createDefaultParser();

try {

FileInputStream in = new FileInputStream(new File(sourceFile));

// "/x"参数用 parser.parse(in, "");

// "/x2010" 用parser.parse(in, "UTF-8");

parser.parse(in, "UTF-8"); //编码集合

DXFDocument doc = parser.getDocument();

Iterator> it = doc.getDXFLayerIterator();

while (it.hasNext()) {

DXFLayer layer = (DXFLayer) it.next();

List> text = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_TEXT);

if (text != null) {

for (int i = 0; i < text.size(); i++) {

String a = ((DXFText) (text.get(i))).getText();

if (a != null && !"".equals(a.trim())){

a = a.replaceAll(" ", "");

strResult.append(a);

}

}

}

List> mtext = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_MTEXT);

if (mtext != null) {

for (int i = 0; i < mtext.size(); i++) {

String a = ((DXFMText) (mtext.get(i))).getText();

if (a != null && !"".equals(a.trim())){

a = a.replaceAll(" ", "");

strResult.append(a);

}

}

}

}

} catch (ParseException e) {

logger.error(e.getMessage());

} catch (FileNotFoundException e) {

logger.error(e.getMessage());

}

return strResult.toString();

}

2019独角兽企业重金招聘Python工程师标准>>> kabeja-0.4.jar 1.java 读取 dxf 字符 @Test public void JunitGetContent(){ String dxfPath="D:\1-test-exe\out\cwp.dxf"; // 默认 /x2004 的参数 String docContent = getDocContent(dxfPath); System.out.println(docContent); String dxfPath2="D:\1-test-exe\out\X2010.dxf"; // 解析 /x2010 参数转换的文件 String docContent2 = getDocContent(dxfPath2); System.out.println(docContent2); } public String getDocContent(String sourceFile){ StringBuffer strResult = new StringBuffer(); Parser parser = ParserBuilder.createDefaultParser(); try { FileInputStream in = new FileInputStream(new File(sourceFile)); // "/x"参数用 parser.parse(in, ""); // "/x2010" 用parser.parse(in, "UTF-8"); parser.parse(in, "UTF-8"); //编码集合 DXFDocument doc = parser.getDocument(); Iterator> it = doc.getDXFLayerIterator(); while (it.hasNext()) { DXFLayer layer = (DXFLayer) it.next(); List> text = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_TEXT); if (text != null) { for (int i = 0; i < text.size(); i++) { String a = ((DXFText) (text.get(i))).getText(); if (a != null && !"".equals(a.trim())){ a = a.replaceAll(" ", ""); strResult.append(a); } } } List> mtext = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_MTEXT); if (mtext != null) { for (int i = 0; i < mtext.size(); i++) { String a = ((DXFMText) (mtext.get(i))).getText(); if (a != null && !"".equals(a.trim())){ a = a.replaceAll(" ", ""); strResult.append(a); } } } } } catch (ParseException e) { logger.error(e.getMessage()); } catch (FileNotFoundException e) { logger.error(e.getMessage()); } return strResult.toString(); }
经验分享 程序员 微信小程序 职场和发展