简体   繁体   English

c#Autocad Map 3D 2012获取用户绘制的对象

[英]c# Autocad Map 3D 2012 get user drawn object

Is it possible to send a string to execute to Map and find out what objects has the user drawn in an easier way? 是否可以发送一个字符串来执行Map并找出用户以更简单的方式绘制的对象? I feel that like what I am doing is too much... 我觉得我正在做的事情太多了......

This is the command: 这是命令:

    acad.DocumentManager.MdiActiveDocument.SendStringToExecute
("_MPOLYGON ", false, false, true);

As of now, what I do is I subscribe to the object appended event, and to the command ended event, then I call the sendStringToExecute and from there I check all the new objects coming in the DB and keep a reference to the ones I find the user has drawn. 截至目前,我所做的是订阅对象附加事件和命令结束事件,然后我调用sendStringToExecute并从那里检查数据库中的所有新对象并保留对我找到的对象的引用用户已绘制。

So first: 首先:

    HostApplicationServices.WorkingDatabase.ObjectAppended += 
new ObjectEventHandler(activeDB_ObjectAppended);

and

    acad.DocumentManager.MdiActiveDocument.CommandEnded += 
new CommandEventHandler(MdiActiveDocument_CommandEnded);

While the command is executing: 执行命令时:

void activeDB_ObjectAppended(object sender, ObjectEventArgs e)
        {
            polyDessinIds.Add(e.DBObject.Id);
        }

Autocad adds objects to the database WHILE the _MPOLYGON command is being executed, so I keep a reference to all them. Autocad在执行_MPOLYGON命令时将对象添加到数据库,因此我保留对它们的引用。 Autocad adds points and lines to the database while the user is drawing. 在用户绘图时,Autocad会向数据库添加点和线。 For example, the first and second click that for a line seem to be put in the database. 例如,对于一行的第一次和第二次单击似乎放在数据库中。 Also when a polygon is added to the working db it does not mean it is the last one. 此外,当多边形添加到工作数据库时,并不意味着它是最后一个。 The last added object is not guaranteed to be the real object either. 最后添加的对象也不能保证是真实对象。

Then when the command is ended, I look for the correct objectId, even if there are many polygons that were drawn, there is only 1 valid objectId that references the one or the many polygons drawn. 然后当命令结束时,我寻找正确的objectId,即使有很多多边形被绘制,只有一个有效的objectId引用一个或多个绘制的多边形。

 foreach (ObjectId obj in polyDessinIds)
 {
            if (obj.IsErased == false && obj.ObjectClass.Name == "AcDbMPolygon")
            {
             mPolygons = obj;
             //there should be only one valid at this point
             break;
            }
 }

I am wondering if there is a better and more reliable way to do this? 我想知道是否有更好更可靠的方法来做到这一点? Maybe something like when you prompt for selecting objects, this returns a selection set with all the objects. 也许就像你提示选择对象时一样,这会返回一个包含所有对象的选择集。 Is there a way to "promptForPolygon" or something similar that will just return me the new objects once the user has drawn them? 有没有办法“promptForPolygon”或类似的东西,一旦用户绘制它们只会返回我的新对象?

I don't think you need all of that code, try to play with: 我认为您不需要所有代码,请尝试使用:

ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SelectLast()

Which should give you the last entity drawn or used. 哪个应该为您提供最后绘制或使用的实体。

Some more explanation here: 这里有更多解释:

http://72.77.202.9/index.php?topic=20267.0

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM