设备自定义标注

2022-11-09  本文已影响0人  饭桶2018

Plant3D 设备标注默认只有位号


image.png

我们希望在标注的时候显示设备的位号+支座标高

我们可以通过下面的方法配置。

右键项目进入项目配置


image.png

我们选择设备,这样所有设备都可以使用这个标注

image.png

当我们点击Edit Block 后会跳出编辑当前样式的界面
我们复制原有样式,把Tag属性改成 COG Z属性。

注意,属性中的空格需要用Unicode表示。 见文档

image.png

好了之后点击Close Block Editor 并保存


image.png

好了之后点 Apply OK


image.png

好了之后我们就可以使用这个属性了

image.png

然后在布置图界面 更新标记即可。


image.png

为了方便用户设置这个标高,我们可以写个小插件,方便用户选中设备、选中支架底标高,更新这个属性


image.png
image.png
image.png

以下是小插件源码

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.ProcessPower.PlantInstance;
using Autodesk.ProcessPower.PnP3dObjects;

// 此处省略 namespace class method .....

var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;


using (Transaction tr = db.TransactionManager.StartTransaction())
{
    var bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
    var btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;

    var equipmentSelection = ed.GetSelection(new PromptSelectionOptions { MessageForAdding = "\n请选择一个设备:", SingleOnly = true, SinglePickInSpace = true });
    if (equipmentSelection.Status != PromptStatus.OK) { return; }
    if (equipmentSelection.Value.Count != 1) { return; }
    var equipmentObjectId = equipmentSelection.Value[0].ObjectId;
    var equipment = tr.GetObject(equipmentObjectId, OpenMode.ForRead) as Equipment;
    if (equipment == null)
    {
        ed.WriteMessage("您选择的不是设备!\n");
        return;
    }

    var pointSelection = ed.GetPoint("请选择设备底标高");
    if (pointSelection.Status != PromptStatus.OK)
    {
        return;
    }

    var point = pointSelection.Value;
    var dlm = PlantApplication.CurrentProject.ProjectParts["Piping"].DataLinksManager;
    var row = dlm.GetPnPDatabase().GetRow(dlm.FindAcPpRowId(equipmentObjectId));
    row.SetPropertyValue("COG Z", point.Z);
}

上一篇 下一篇

猜你喜欢

热点阅读