【问题标题】:How to select a list of entities and get their properties in eyeshot?如何选择实体列表并获得它们的属性?
【发布时间】:2020-09-16 12:21:14
【问题描述】:

我想通过鼠标单击选择实体列表,然后要求它们的属性。我知道可以使用(请查看代码)选择实体

但是如何获得这个实体列表的属性(例如,如果实体是圆柱体并且它的 起点和终点是必需的)

controlDrawing.ViewportLayoutTower.ActionMode = devDept.Eyeshot.actionType.SelectByPick

【问题讨论】:

  • 没有在谈论 vb.net 中的 Eyeshot 库
  • 知道了 - 我认为这是一个比喻,因为它没有大写,即 Eyeshot

标签: vb.net eyeshot


【解决方案1】:

您可以简单地在控件的MouseDown事件中找到鼠标下的所有实体并从中获取您想要的。

private void myViewport_MouseDown(object sender, MouseEventArgs e)
{
    // if left click
    if (e.Button == MouseButtons.Left)
    {
        // get all entities under the mouse cursor
        var entityIndexes = myViewport.GetAllEntitiesUnderMouseCursor(e.Location);
        
        // if there is any entities
        if entityIndexes.Any())
        {
            foreach(var index in entityIndexes)
            {
                 // get the entity and do something
                 var entity = myViewport.Entities[index];
            }
        }        
    }
}

【讨论】:

    【解决方案2】:

    您正在寻找演员表。当将对象放入视口和将对象拉出视口时,它们总是被转换为实体,因为这是所有实体的父类。如果您想要圆柱体属性,您需要将其转换为您添加到视口的任何子类。不幸的是,Entity 没有 Cylinder 子类,所以我假设您制作了 Mesh.CreateCylinder()。这是一个 Mesh 类,您传递给函数的变量(起点和终点)在函数的本地范围内,不再可供 Mesh 类访问。

    绕过此问题的一种方法是将此信息添加到实体的 EntityData 属性中。此属性可以保存您制作的任何对象。

            public class myCylinderEntData
            {
                public double radius = 2d;
                public double height = 5d;
                public int slices = 10;
            }
    
            double dRadius = 2d;
            double dHeight = 5d;
            int iSlices = 10;
            myCylinderEntData cyl1EntData = new myCylinderEntData() { radius = dRadius, height = dHeight, slices = iSlices };
            Mesh cylinder1 =  Mesh.CreateCylinder(dRadius, dHeight, iSlices);
            cylinder1.EntityData = cyl1EntData;
            vp1.Entities.Add(cylinder1); // Add to viewport
    
            Entity retrivedEnt = vp1.Entities[0];
            myCylinderEntData myRetrievedEntData = (myCylinderEntData)retrivedEnt.EntityData; // get Data back after clicked
    
    
            int[] clickedEntsIndex = vp1.GetAllEntitiesUnderMouseCursor(Cursor.Position);// e.Location) ;  // retrieve from viewport
    

    此外,如果它是继承 Entity 的类的可用属性,您可以像这样检索该属性。

            int[] clickedEntsIndex = vp1.GetAllEntitiesUnderMouseCursor(Cursor.Position);// e.Location) ;  // retrieve from viewport
            foreach(int index in clickedEntsIndex)
            {
                 if(vp1.Entities[index] is Mesh) // Check object type for whichever child class you want to convert to
                {
                    Mesh myClickedMesh = (Mesh)vp1.Entities[index];
                    // Here you access to all of your Meshes public Variables
                }
                else if (vp1.Entities[index] is Solid)
                {
                    Solid myClickedSolid = (Solid)vp1.Entities[index];
                    // Here you access to all of your Solid public Variables
                }
            }
    

    【讨论】:

    • 为了学习编程,你不应该使用new Mesh().GetType(),你应该使用typeof(Mesh)。无论如何,整行不应该是if(vp1.Entities[index].GetType() == new Mesh().GetType()),而是if(vp1.Entities[index] is Mesh)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多