给后来者一点参考吧,咨询了多次技术客服,最终转到研发,终于解决了。
public static int createLine3DSymbol(double width, double height) {
double max = width > height ? width : height;
int length = SwingUtils.countDigits(max);
double bf = length > 2 ? Math.pow(10, length - 2) : 1;
int w = (int) (width / bf);
int h = (int) (height / bf);
w = w == 0 ? 1 : w;
h = h == 0 ? 1 : h;
String name = "方管截面:" + w + ":" + h, groupname = "自定义符号[John]";
SymbolMarkerLibrary libMarker = SysBaseVarInfo.G_SysDataWorkSpace.getResources().getMarkerLibrary();
SymbolLineLibrary libLine = SysBaseVarInfo.G_SysDataWorkSpace.getResources().getLineLibrary();
Symbol sLine = libLine.findSymbol(name);
if (sLine != null) return sLine.getID();
Symbol sMarker = libMarker.findSymbol(name);
if (sMarker == null) {
int groupIndex = libMarker.getRootGroup().getChildGroups().indexOf(groupname);
SymbolGroup groupMarker = groupIndex == -1 ? libMarker.getRootGroup().getChildGroups().create(groupname) : libMarker.getRootGroup().getChildGroups().get(groupIndex);
SymbolMarker marker = new SymbolMarker();
Geometry g = new GeoRectangle(new Point2D(w / 2, h / 2), w, h, 0);
marker.fromGeometry(g, new Rectangle2D(0, 0, w, h));
marker.setName(name);
marker.setSize(w > h ? w : h);
int symbolidMarker = libMarker.add(marker, groupMarker);
sMarker = libMarker.findSymbol(symbolidMarker);
}
if (sMarker == null) return -1;//表示创建截面点符号失败
SymbolLine line = new SymbolLine();
SymbolLineBase lineBase = new SymbolLineBase();
lineBase.setType(SymbolLineBaseType.CUSTOMIZATION3D);
lineBase.setCode(sMarker.getID());
line.add(lineBase);
line.setName(name);
int groupindex = libLine.getRootGroup().getChildGroups().indexOf(groupname);
SymbolGroup group = groupindex == -1 ? libLine.getRootGroup().getChildGroups().create(groupname) : libLine.getRootGroup().getChildGroups().get(groupindex);
return libLine.add(line, group);
}