如何 select 实体列表并在视野中获取它们的属性?

How to select a list of entities and get their properties in eyeshot?

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

但是如何获得此实体列表的属性(例如,如果实体是圆柱体及其 需要起点和终点)

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

您可以简单地在控件的 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];
            }
        }        
    }
}

您正在寻找选角。当将 objects 放入和拉出 objects 视口时,它们总是被投射为实体,因为这是所有实体的 parent class。如果您想要圆柱体属性,您需要将其转换为您添加到视口中的任何 child class。不幸的是,没有实体的圆柱 child class,所以我假设你制作了 Mesh.CreateCylinder()。这是一个 Mesh class,您传递给函数的变量(起点和终点)在函数的局部范围内,不再可供 Mesh class.[=12 访问=]

一种绕过此方法的方法是将此信息添加到实体的 EntityData 属性 中。这个 属性 可以容纳你制作的任何 object。

        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

此外,如果它是继承实体的 class 的可用 属性,您可以像这样检索 属性。

        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
            }
        }