| export class TestGetEntityData { |
| private sDwgFileName: string; |
| private getDataFilePath(): string { |
| return mxConvert.getConvertPath() + this.sDwgFileName + ".json"; |
| } |
| |
| // 得到图层"飘檐"上的文本 |
| private getText1() { |
| // 把得到数据,写到sDataFile. |
| let sDataFile = this.getDataFilePath(); |
| |
| let ss: Mx.MrxDbgSelSet = new Mx.MrxDbgSelSetClass(); |
| |
| // 创建一个选择过滤条件. |
| let filter: Mx.MrxDbgRbList = new Mx.MrxDbgRbListClass(); |
| |
| // 只选择文字对象. |
| filter.addString("TEXT", 5020) |
| |
| // 图层过滤. |
| filter.addString("飘檐", 8); |
| |
| // 得到图上所有文字对象. |
| ss.allSelect(filter); |
| |
| |
| let dataObject: any = {}; |
| |
| let iCount = ss.count; |
| |
| for (let i = 0; i < iCount; i++) { |
| // 选择集不为空. |
| let txt: Mx.McDbText = Mx.MxType.MxCast<Mx.McDbText>(ss.item(i), Mx.MxType.TypeString.kMcDbText); |
| |
| // 得到文字对象,文字内容. |
| if (txt) { |
| |
| if (!dataObject[txt.layer]) { |
| dataObject[txt.layer] = []; |
| } |
| // 把文字对象数据返回. |
| let txtData: any = {}; |
| txtData.txt = txt.textString; |
| txtData.posx = txt.position.x; |
| txtData.posy = txt.position.y; |
| dataObject[txt.layer].push(txtData); |
| } |
| } |
| |
| // 保存数据文件. |
| MxFun.writeFile(sDataFile, JSON.stringify(dataObject)); |
| } |
| |
| |
| public Do(filename: string) { |
| this.sDwgFileName = filename; |
| this.getText1(); |
| } |
| } |