FME安装问题以及FME处理dwg代码示例
- FME 安装
说明:这里采用的是FME2022的desktop的来处理和读取cad dwg文件 (曾今安装过去fme的,就需要全局删除所有fme的文件夹)
https://www.zhihu.com/question/278356734
https://www.xiazai99.com/down/soft266163.html
https://www.cnblogs.com/alunzuishuai/p/16344909.html
获取crack 安装包
链接:https://pan.baidu.com/s/1CsJhsWzLjo6e7HBsVN0WWQ?pwd=yut5
提取码:yut5
1.1 安装 fme-flexnet-win-x64.msi 文件
安装完后,C:\Program Files\FlexServer
至此,需要检查hostid.txt文件不能有重复的网卡
1.1 生产safe.lic文件
解压crack文件夹
按上图,修改dummy.txt文件,修改hostid.txt 和网卡之后,执行命令行。生产新的safe.lic文件
- 替换系统默认“C:\Program Files\FlexServer” safe.exe
- 执行BatchFiles中的restartService.bat文件
若发现多个网卡,需要修改成一个。从hostid.txt文件获取
启动成功之后,方可安装“fme-desktop-2022.0-b22245-win-x64-beta.exe”
-
FME 常见错误
1、无法active,safe.lic文件生成的不对。按上面crack的流程执行即可 -
IDEA 配置FME开发环境
打开idea, new project
3. FME处理dwg,并读取cad里面的行政区划保护线
核心代码:
public static void main(String[] args) throws FMEException {
try {
_fmeSession = FMEObjects.createSession();
IFMEStringArray stringArray = _fmeSession.createStringArray();
stringArray.append(“FME_USE_RICH_GEOMETRY”);
stringArray.append(“yes”);
_fmeSession.init(stringArray);
FmeCreateReader("D:/fmeTest/src/com/guodi/01ljymq.dwg");
IFMEFeature _fmeFeatureRead = _fmeSession.createFeature();
while (_fmeReader.read(_fmeFeatureRead)) {
String strLyr = GetFmeFeatureAttribute(_fmeFeatureRead, "autocad_layer").toUpperCase();
System.out.println(strLyr);
if (strLyr.equalsIgnoreCase("--文物保护线")) {
IFMEGeometry geo = _fmeFeatureRead.getGeometry();
// create visitor
FmeCADDataVisitor visitor = new FmeCADDataVisitor();
visitor.setFmeSession(_fmeSession);
visitor.setFmeGeometry(geo);
if (null != geo) {
geo.acceptGeometryVisitor(visitor);
if (geo instanceof IFMEPolygon || geo instanceof IFMELine || geo instanceof IFMEArc || geo instanceof IFMEEllipse ||
geo instanceof IFMEPath) {
String strHandle = GetFmeFeatureAttribute(_fmeFeatureRead, "autocad_entity_handle");
String strEntName = GetFmeFeatureAttribute(_fmeFeatureRead, "autocad_entity");
String strColor = GetFmeFeatureAttribute(_fmeFeatureRead, "autocad_color");
// collect dwg data items
DwgDataItem dwgItem = new DwgDataItem();
dwgItem.strColor = strColor;
dwgItem.strEntName = strEntName;
dwgItem.strHandle = strHandle;
dwgItem.geometry = visitor.geometry;
results.add(dwgItem);
}
}
}
// handle next features right now
_fmeFeatureRead = _fmeSession.createFeature();
}
} catch (FMEException ex) {
System.out.println("FME初始化错误:" + ex.getMessage().toString());
return;
}
_fmeReader.close();
_fmeReader.dispose();
_fmeReader = null;
}
最后结果如下: