I have some simple code that
1) Select some objects to wblock
2) Wblock to new drawing and open it
3) Do something w/ the wblocked objects.
This works fine in 32 bit but in 64 bit the new drawing refuses to become active
AND THE ERROR at psr = cEd.GetSelection(); is enotapplicable.
Appreciate any help
using System.Windows.Forms;
using acadApp=Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
[assembly: CommandClass(typeof(ClassLibrary1.Class1))]
namespace ClassLibrary1
{
public class Class1
{
[CommandMethod("cnc",CommandFlags.Session)]
public static void TestCnc()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptSelectionResult psr= ed.GetSelection();
if (psr.Status != PromptStatus.OK) return;
SelectionSet ss = psr.Value;
FolderBrowserDialog fd=new FolderBrowserDialog();
if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
string f= fd.SelectedPath;
if(string.IsNullOrEmpty(f)) return;
ObjectIdCollection ids = new ObjectIdCollection();
foreach(ObjectId id in ss.GetObjectIds())
ids.Add(id);
string sDwg = doc.Name.Replace(".dwg","C.dwg");
string cncDwg = f + @"/" + sDwg;
using (doc.LockDocument())
{
using (Database dbase = new Database(true, false))
{
dbase.WblockCloneObjects(ids, dbase.CurrentSpaceId, new IdMapping(), DuplicateRecordCloning.Replace, false);
dbase.SaveAs(cncDwg, DwgVersion.Current);
}
}
Document cncDoc = acadApp.DocumentManager.Open(cncDwg, false);
acadApp.DocumentManager.MdiActiveDocument = cncDoc;
Database db = cncDoc.Database;
Editor cEd = cncDoc.Editor;
using (cncDoc.LockDocument())
{
psr = cEd.GetSelection();
if (psr.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (SelectedObject so in psr.Value)
{
Entity ent = tr.GetObject(so.ObjectId, OpenMode.ForWrite) as Entity;
ent.ColorIndex = 1;
}
tr.Commit();
}
}
} // end TestCnc
}
}