Author Topic: Active doc 32bit vs 64  (Read 3647 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Active doc 32bit vs 64
« on: March 27, 2013, 04:17:49 PM »
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


Code: [Select]
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
       
    }
}

BlackBox

  • King Gator
  • Posts: 3770
Re: Active doc 32bit vs 64
« Reply #1 on: March 27, 2013, 04:39:56 PM »
Are you compiling to both 32 / 64, or to one assembly via 'Any CPU'?
"How we think determines what we do, and what we do determines what we get."

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Active doc 32bit vs 64
« Reply #2 on: March 27, 2013, 09:00:34 PM »
2 separate

BlackBox

  • King Gator
  • Posts: 3770
Re: Active doc 32bit vs 64
« Reply #3 on: March 28, 2013, 01:38:37 AM »
2 separate

When building solutions for .NET API, take advantage of one of the few benefits over ObjectARX, by compiling with Any CPU specified, when the alternative dual 32 / 64 assemblies would be for the same target version.
"How we think determines what we do, and what we do determines what we get."

TheMaster

  • Guest
Re: Active doc 32bit vs 64
« Reply #4 on: March 28, 2013, 01:45:47 AM »
2 separate

The ObjectARX SDK with older releases of AutoCAD shipped with separate 32 and 64 bit versions of the managed assemblies, and there were types in them that had differing signatures. And, if you are doing any P/Inovking, the 32 and 64 bit entry point symbols may not be the same. 

I resolve platform-dependent code and also do an end-run around C# P/Invoke by building a single, platform-dependent C++/CLI mixed-mode assembly that factors out any platform-dependencies from the purely managed, platform-neutral code that uses it, so I only have to distribute 32 and 64 bit versions of the mixed-mode assembly, and everything else is AnyCPU. I also can avoid the insidious problem of dealing with platform-dependent entry point symbols in P/Invoke, because C++/CLI does everything for you.

So, is there a legitimate reason for separate, platform-dependent builds?

fixo

  • Guest
Re: Active doc 32bit vs 64
« Reply #5 on: March 28, 2013, 06:13:41 AM »
2 separate
May be I'm out off thoughts, perhaps use this way instead,
copy any table from source drawing, or whatever you need:
Code: [Select]
        [CommandMethod("Bryco", CommandFlags.Session)]
        public void tryCopyTable()
        {
            //source drawing name, change to suit
            string fname = @"c:\test\workingdrawing.dwg";

            ObjectId id = ObjectId.Null;

            ObjectIdCollection ids = new ObjectIdCollection();

            IdMapping map = new IdMapping();

            bool ok = false;

            try
            {
                DocumentCollection dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

                Document doc = dm.MdiActiveDocument;

                Editor ed = doc.Editor;

                Database db = doc.Database;

                using (doc.LockDocument())
                {
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        Document doc2 = dm.Open(fname, false);

                        while (!dm.IsApplicationContext)
                        {
                            // get a time to next drawing to wake up
                            System.Threading.Thread.Sleep(1);
                        }

                        Database db2 = doc2.Database;

                        Editor ed2 = doc2.Editor;

                        ed2.WriteMessage("\nYou're may use editor in the drawing: \"{0}\"\n", fname);

                        using (Transaction tr2 = doc2.TransactionManager.StartTransaction())
                        {
                            id = ed2.GetEntity("\nSelect table to copy: ").ObjectId;

                            DBObject obj = (DBObject)tr2.GetObject(id, OpenMode.ForRead, false, true);

                            Table tbl = obj as Table;

                            if (tbl == null) return;

                            map = new IdMapping();

                            ids = new ObjectIdCollection();

                            ids.Add(id);

                            tr2.Commit();
                        }
                        dm.MdiActiveDocument = doc;

                        HostApplicationServices.WorkingDatabase = doc.Database;

                        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;

                        db2.WblockCloneObjects(ids, btr.ObjectId, map, DuplicateRecordCloning.Replace, false);

                        id = ed.SelectLast().Value.GetObjectIds()[0];

                        DBObject clone = (DBObject)tr.GetObject(id, OpenMode.ForRead, false, true);

                        Table copytbl = clone as Table;

                        if (!copytbl.IsWriteEnabled) copytbl.UpgradeOpen();

                        Point3d pt = ed.GetPoint("\nPick new insertion point: \n").Value;

                        copytbl.TransformBy(Matrix3d.Displacement(pt - copytbl.Position));

                        tr.Commit();

                        doc2.CloseAndDiscard();

                        ok = true;
                    }

                }

            }
            catch (System.Exception ex)
            {
                ok = false;
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                if (ok)
                {
                    MessageBox.Show("Save drawing manually or change code to save it");
                }
            }
        }

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Active doc 32bit vs 64
« Reply #6 on: March 28, 2013, 10:02:58 AM »
blackbox, I think I mispoke, both are compiled w/ Any CPU, but normally (Since I use some com) I need to have to sets of References to Interop and Interop.common.
This little code has no com so yes 1 assembly.
I have no idea why "acadApp.DocumentManager.MdiActiveDocument = cncDoc;" works fine on 32bit but fails on 64bit.

Perhaps this is a debugging problem as both were sent to debug not release.

Tony the C++ is a bit beyond me at the moment.

Fixo maybe "System.Threading.Thread.Sleep(1);" is what I need , I'll try it today

BlackBox

  • King Gator
  • Posts: 3770
Re: Active doc 32bit vs 64
« Reply #7 on: March 28, 2013, 11:20:24 AM »
The ObjectARX SDK with older releases of AutoCAD shipped with separate 32 and 64 bit versions of the managed assemblies...

This holds true for the ObjectARX 2014 SDK as well; just got it from ADN today, and used the new self-extracting installer. Not available publicly (yet).

The rest of your post was (way) over my head, so forgive my simply saying thank you, for giving me more to add to the reading list, Tony.

Cheers
"How we think determines what we do, and what we do determines what we get."

TheMaster

  • Guest
Re: Active doc 32bit vs 64
« Reply #8 on: March 28, 2013, 02:58:58 PM »
The ObjectARX SDK with older releases of AutoCAD shipped with separate 32 and 64 bit versions of the managed assemblies...

This holds true for the ObjectARX 2014 SDK as well; just got it from ADN today, and used the new self-extracting installer. Not available publicly (yet).


There have always been separate builds of the assemblies, because they are mixed-mode (native and managed code). The main point of what you quote above, was that assemblies contained types with methods that had differing signatures (e.g., on 32 bit platforms some arguments were typed as Int32, and on 64 bit platforms the same argument in the same API was typed as Int64).

That was resolved, AFAIK

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Active doc 32bit vs 64
« Reply #9 on: March 29, 2013, 11:49:46 AM »
fixo I ran your code and get the same error
enotapplicable  at
ed2.WriteMessage("\nYou're may use editor in the drawing: \"{0}\"\n", fname);

Maybe my computer is whacked out. (win7 acad13)
Veery frustrating

fixo

  • Guest
Re: Active doc 32bit vs 64
« Reply #10 on: March 29, 2013, 11:57:57 AM »
Sorry, friend, I could just working on A2010

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Active doc 32bit vs 64
« Reply #11 on: March 29, 2013, 12:32:53 PM »
bRYCO, YOUR CODE WORKS FOR ME IN 64 BIT,  crap, dang CAPSLOCK. Anyway, it works when I placed it in an existing project I have which references the managed DLL's in the ObjectARK 2013\inc folder. I thought I heard that these were slightly different than the ones in either the 32 or 64 bit release folders. Perhaps this is what you need to use. Oh, and I have it building for AnyCPU.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Active doc 32bit vs 64
« Reply #12 on: March 29, 2013, 12:50:18 PM »
Thanks for trying it Jeff, I am using the same objectarx folder.
So perhaps it is my cad is bad. I have just done a reinstall and am still having problems.
I'll reinstall again

BlackBox

  • King Gator
  • Posts: 3770
Re: Active doc 32bit vs 64
« Reply #13 on: March 29, 2013, 12:58:52 PM »
"How we think determines what we do, and what we do determines what we get."

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Active doc 32bit vs 64
« Reply #14 on: March 29, 2013, 02:19:17 PM »
bRYCO, YOUR CODE WORKS FOR ME IN 64 BIT,  crap, dang CAPSLOCK.

You could always have AutoCAD change the CapsLock for you:-P
AutoCAD has nothing to do with it. It's the keyboard layout on my laptop and fat fingers that are the problems. :-)