DgnUtilities.GetInstancesFromDgn("NOZZLE");返回的对象,仅找到位置坐标,关联的“NOZZLE_HAS_PORT”对象也仅有位置坐标,不知道有没有办法可以得到管接头方向数据?
首先检查一下,您是否用Workspace打开的DGN文件,且您的NOZZLE Schema定义中有其它属性。
可以使用 ecx items dump这个Keyin,然后检查一下生成的xml文件中的NOZZLE和PORT是否有所有的EC属性。
没有的话应该是要么没有使用正确的工作空间,要么是其他问题导致Schema没有加载上。
然后可以按照这个思路写段代码调试一下,看能否取出其它属性:
SDKExamples\ZeroLengthPipesExample
private void BtnReport_Click(object sender, EventArgs e) { ECInstanceList pipeInstances = DgnUtilities.GetInstancesFromDgn("PIPE", false);
if(pipeInstances != null && pipeInstances.Count > 0) { foreach(IECInstance instance in pipeInstances) { double length = instance["LENGTH"].DoubleValue; if(length < 0.00001) { string name = GetValue(instance, "NAME"); string pipeline = GetValue(instance, "LINENUMBER"); string spec = GetValue(instance, "SPECIFICATION"); string nominalSize = GetValue(instance, "NOMINAL_DIAMETER"); string Length = GetValue(instance, "LENGTH");
ListViewItem item = new ListViewItem(name); item.SubItems.Add(pipeline); item.SubItems.Add(nominalSize); item.SubItems.Add(spec); item.SubItems.Add(Length); LstPipes.Items.Add(item); } } } else MessageBox.Show("No pipes found with length zero.", "OpenPlant Modeler SDK Examples", MessageBoxButtons.OK, MessageBoxIcon.Information); }
方向:
PORT有DIRECTION_X Y Z属性
感谢解答,Schema应该没错,看数据,我之前认为Direction_X这些不是方向数据,因为数值对不上,见下图。
右视图:
显示方向向量为(-1,0,0)
俯视图:
方向数据不对,这个x方向应该为0,另外两个方向不为0才对啊?
是否需要通过这个数据+元素的矩阵二次计算?
那直接用它的矩阵吧
Answer Verified By: Chao Cheng
OK,我再试试,另外突然发现个小问题,就不另开一帖了。
DgnUtilities.GetInstanceByGuid()应该怎么使用?下面的GUID是附件图纸里设备的GUID。
DgnUtilities.GetInstanceByGuid("66449e9d-f3e4-45c2-a8ad-5e68f20c57a9");//返回null DgnUtilities.GetInstancesFromDGNByProperty("GUID", "66449e9d-f3e4-45c2-a8ad-5e68f20c57a9");//正常返回,集合数量为1
这个API有点问题,预计Update 9修复,我做的一个临时替代办法:
//Create Pipe.
PipeComponentData pipe1Data = new PipeComponentData(specification, nominalDiameter);
pipe1Data.SetProperty("LENGTH", length.ToString());
PipeComponent pipe1 = new PipeComponent(origin, pipe1Data, 0, DrawingView.ViewTop, true);
pipe1.Create();
ComponentPropertiesGetter pGetter = new ComponentPropertiesGetter(pipe1);
// Yes, it is the GUID of the newly created PIPE, I have verified it with the result of "ecx items dump"
string guid = pGetter.GetPropertyValue("GUID");
Debug.WriteLine(guid);
ECInstanceList plantInstanceList = DgnUtilities.GetInstancesFromDgn("PLANT_BASE_OBJECT", true);
foreach (IECInstance plantInstance in plantInstanceList)
{
if (plantInstance["GUID"].StringValue == guid)
IDgnECInstance dgnInstance = plantInstance as IDgnECInstance;
Element element = dgnInstance.Element;
Debug.WriteLine(element.ElementId);
Debug.WriteLine("We found it!"); // Indeed, we found it.
// You can operate on the element immediately;
// or just cache its “Plant Object Instance GUID” somewhere and operate on them later in a batch.
}