You need to switch the active drawing in Acad before asking user to do second pick. Or you do know this but do not know how to switch drawing in acad.
Anyway, here is some code doing that:
{code}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System.IO;
namespace PickInTwoDocs
{
public class MyData
{
public string Drawing1 { get; set; }
public string Drawing2 { get; set; }
public ObjectId PickedInDrawing1 { get; set; }
public ObjectId PickedInDrawing2 { get; set; }
}
public class MyCommand
{
private static MyData _data = null;
[CommandMethod("PickInDocs", CommandFlags.Session)]
public static void RunThisMethod()
{
DocumentCollection docs = Application.DocumentManager;
Document dwg = docs.MdiActiveDocument;
if (docs.Count<2)
{
dwg.Editor.WriteMessage(
"\nThere is only one drawing open. " +
"\nThe program cannot continue!");
return;
}
_data=new MyData();
//Get data from first drawing
_data.Drawing1 = dwg.Name;
_data.PickedInDrawing1 = PickObjectInDwg(dwg);
// Go to next drawing, as long as it
// is not the same drawing
//You should decide which drawing is the
//other drawing in your code
foreach (Document d in docs)
{
if (d.Name.ToUpper() != dwg.Name.ToUpper())
{
// Set this drawing as active drawing, so
// user can do the pick
docs.MdiActiveDocument = d;
dwg=docs.MdiActiveDocument;
break;
}
}
// Get data from the second drawing
_data.Drawing2 = dwg.Name;
_data.PickedInDrawing2 = PickObjectInDwg(dwg);
// Show the result
// You can now use the 2 ObjectIds to do some thing
dwg.Editor.WriteMessage("\n\nPicking result:");
dwg.Editor.WriteMessage("\nPicked object in \"" +
_data.Drawing1 + "\": " +
_data.PickedInDrawing1.ToString());
dwg.Editor.WriteMessage("\nPicked object in \"" +
_data.Drawing2 + "\": " +
_data.PickedInDrawing2.ToString());
dwg.Editor.WriteMessage("\n");
}
private static ObjectId PickObjectInDwg(Document dwg)
{
ObjectId picked = ObjectId.Null;
Editor ed = dwg.Editor;
PromptEntityOptions opt =
new PromptEntityOptions("\nPick an enetity:");
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
picked = res.ObjectId;
}
return picked;
}
}
}
{code}
Of course, the 2 ObjecIds you have in hand is only useful when working with their corresponding databases of the two different drawings.
HTH.