sclkkk 发表于 2011-6-14 10:32:00

请问如何画一个多边形,并获取该多边形里的图元?

请问如何画一个多边形,并获取该多边形里的图元?

sclkkk 发表于 2011-6-14 14:36:00

哪位高手贴段代码参考下啊!

guohq 发表于 2011-6-15 00:34:00


    Public Enum PolygonSelectType
      '''
      ''' 圈交(实选)
      '''
      '''
      CrossingPolygon = 1
      '''
      ''' 圈围(范选)
      '''
      '''
      WindowPolygon = 2
    End Enum

    Public Function SelectEntsByPolygon(ByVal objEditor As Editor, ByVal Pts As Point3dCollection, Optional ByVal sFilter As SelectionFilter = Nothing, Optional ByVal SelectType As PolygonSelectType = PolygonSelectType.CrossingPolygon) As ObjectId()
      Dim resSel As PromptSelectionResult = Nothing
      Select Case SelectType
            Case 1
                If sFilter Is Nothing Then
                  resSel = objEditor.SelectCrossingPolygon(Pts)
                Else
                  resSel = objEditor.SelectCrossingPolygon(Pts, sFilter)
                End If
            Case 2
                If sFilter Is Nothing Then
                  resSel = objEditor.SelectWindowPolygon(Pts)
                Else
                  resSel = objEditor.SelectWindowPolygon(Pts, sFilter)
                End If
            Case Else
                '暂时没有其它情况
      End Select
      If resSel.Value Is Nothing Then
            Return New clsAADS.ObjectId() {}
      Else
            Return (resSel.Value.GetObjectIds())
      End If
    End Function
多边形的顶点坐标转到point3dcollection就不用说了吧

sclkkk 发表于 2011-6-15 08:45:00

回复
谢谢,请问你有C#的代码么?我现在只要获取到多边形里所有图元的ObjectId后,删除该多边形或刷新图层该怎么做.本人新手希望代码能全点,谢谢

guohq 发表于 2011-6-15 11:50:00

自己找个网站翻译一下好了,C# 我也不会写,不过语法基本还是比较接近的。
http://www.developerfusion.com/tools/convert/vb-to-csharp/

sclkkk 发表于 2011-6-15 13:37:00

回复
谢谢了!你能把整个代码给我看看么?我对方法里传的值看不明白

sclkkk 发表于 2011-6-17 08:47:00

哪为高手帮帮忙啊!给个具体点的实例参考下啊

zjh0603 发表于 2011-6-17 10:29:00


          public static bool selctText(ObjectId idp, Point3dCollection point3D)
      {
         Document doc = Autodesk.AutoCAD.Applicati**ervices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database ;
            bool fa = false;
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {         
                object obj = tr.GetObject(idp, OpenMode.ForWrite);
                Entity ent = (Entity)tr.GetObject(idp, OpenMode.ForWrite);
                TypedValue[] TypValAr1 = new TypedValue;
                TypValAr1.SetValue(new TypedValue((int)DxfCode.Start, "*TEXT"), 0);               
                SelectionFilter acSelFtr1 = new SelectionFilter(TypValAr1);
                PromptSelectionResult acSStext;
                acSStext = doc.Editor.SelectCrossingPolygon(point3D, acSelFtr1);
                if (acSStext.Status == PromptStatus.OK)
                {
                  
                  foreach (ObjectId id in acSStext.Value.GetObjectIds())
                  {
                        Entity entT = (Entity)tr.GetObject(id, OpenMode.ForRead);
                        string Str="";
                        if (entT is DBText)
                        {
                            DBText DBt = (DBText)tr.GetObject(id, OpenMode.ForRead);
                            Str = DBt.TextString;
                        }
                  }
                }
                tr .Commit ();
            }
}

chpmould 发表于 2011-6-17 17:51:00

不错的例子...

sclkkk 发表于 2011-6-20 09:13:00

回复
请问 ObjectId idp, Point3dCollection point3D 是什么值?我是用多段线画的多边形
页: [1]
查看完整版本: 请问如何画一个多边形,并获取该多边形里的图元?