2014-12-01 4 views
0

주어진 경로 도면 파일을 연 다음 도면의 모든 선을 선택한 다음 선의 목록 번호를 선택해야합니다. 내가 MdiActiveDocument 메서드를 열고 설정하는 동안 반환되기 때문에 나는 이러한 일을 할 수 없습니다. 아래 라인은 실행되지 않습니다.C#을 사용하여 AutoCAD에서 지정된 도면에서 Select 객체를 수행 할 수 없습니다?

private static int GetNumberofLines(string drawingName) 
    { 
     int lineCount = 0; 
     DocumentCollection docMgr = AutoCAD.ApplicationServices.Application.DocumentManager; 
     Document doc = docMgr.Open(drawingName, false); 

     docMgr.MdiActiveDocument = doc;  // in this line method is skipped 

     TypedValue[] filterlist = new TypedValue[1]; //cursor didn't come this line.. 

     filterlist[0] = new TypedValue((int)DxfCode.Start, "Line"); 

     SelectionFilter filter = new SelectionFilter(filterlist); 

     PromptSelectionOptions opts = new PromptSelectionOptions(); 

     opts.MessageForAdding = "Select entities to get line counts: "; 

     PromptSelectionResult prmptSelRslt = doc.Editor.SelectAll(filter); 

     if (prmptSelRslt.Status != PromptStatus.OK) 
     { 
      return 0; 
     } 
     else 
     { 
      lineCount = prmptSelRslt.Value.Count; 
     } 

     return lineCount; 

    } 

누구든지 내게 줄 번호를 나열하는 방법을 말해 줄 수 있습니까?

감사의 말 ....

답변

0

DocumentCollectionExtension을 사용해야합니다. (VB에서)

Dim strFileName As String = "C:\campus.dwg" 

Dim acDocMgr As DocumentCollection = Application.DocumentManager 

If (File.Exists(strFileName)) Then 
    DocumentCollectionExtension.Open(acDocMgr, strFileName, False) 
Else 
    acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & strFileName & _ 
                " does not exist.") 
End If 
+0

감사 ... 알랭 .. – Sivaperuman

1

필요한 정보를 얻는 훨씬 쉬운 방법이 있습니다. 이 주제에 대해 blog post이라고 썼습니다. 좀 봐봐.

[CommandMethod("getLines")] 
    public void OpenDrawing() 
    { 
     OpenDrawingGetLines(@"C:\saved\linetest.dwg"); 
    } 

    public void OpenDrawingGetLines(string path) 
    { 
     var editor = Application.DocumentManager.MdiActiveDocument.Editor; 
     if (!File.Exists(path)) 
     { 
      editor.WriteMessage(string.Format(@"{0} doesn't exist.", path)); 
      return; 
     } 

     // wrap in using statement to open and close. 
     var doc = Application.DocumentManager.Open(path, false); 

     string docName = string.Empty; 
     IEnumerable<ObjectId> lineIds; 

     // lock the doc 
     using (doc.LockDocument()) 

     // start transaction 
     using (var trans = doc.TransactionManager.StartOpenCloseTransaction()) 
     { 
      // get the modelspace 
      var modelspace = (BlockTableRecord) 
       trans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(doc.Database), OpenMode.ForRead); 

      // get the lines ObjectIds 
      lineIds = from id in modelspace.Cast<ObjectId>() 
         where id.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Line))) 
         select id; 

      docName = doc.Name; 
      trans.Commit(); 
     } 

     var message = string.Format("{0} Lines in {1}", lineIds.Count(), docName); 
     editor.WriteMessage(message); 
     Application.ShowAlertDialog(message); 
    } 
+0

thanks..Trae Moore .. – Sivaperuman