Author Topic: WblockCloneobjects Problem with Styles  (Read 2486 times)

0 Members and 1 Guest are viewing this topic.

makoychan

  • Guest
WblockCloneobjects Problem with Styles
« on: January 08, 2015, 11:07:10 AM »
Is is possible to WblockCloneobjects styles from a different database?

  using (Database db = new Database(false, true))
            {
                try
                {
                    ListBoxItem lItem = (ListBoxItem)lstStyles.SelectedItem;
                    db.ReadDwgFile(lItem.Tag.ToString().Replace("xml", "dwg"), FileShare.ReadWrite, false, string.Empty);
                }
                catch (System.Exception ex)
                {
                    throw ex;
                }

                ObjectIdCollection oidCollection = new ObjectIdCollection();

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    foreach (long handle in lHandles)
                    {
                        Handle hn = new Handle(handle);


                        ObjectId oid = db.GetObjectId(false, hn, 0);

                        DBObject dod = (DBObject)tr.GetObject(oid, OpenMode.ForRead);
                       

                        oidCollection.Add(oid);
                    }

                    tr.Commit();
                }

                if (oidCollection.Count > 0)
                {

                    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

                    using (Database destDb = doc.Database)
                    {
                        IdMapping mapping = new IdMapping();

                        db.WblockCloneObjects(oidCollection, destDb.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);

                    }

                }

I am trying to deepclone objects from another dwg file, those objects are styles. But the problem is that those (i think)  entity have different owner i guess it is not own by the blocktable.
Is there any way to deepclone styles from 1 dwg to another dwg.

Thanks

makoy

Jeff H

  • Needs a day job
  • Posts: 6151
Re: WblockCloneobjects Problem with Styles
« Reply #1 on: January 08, 2015, 03:04:48 PM »
I do it all the time if it's a layer its owner is the layer table, or a MLeaderStyle then owner is MleaderStyleDictionary, etc....,

Jeff H

  • Needs a day job
  • Posts: 6151
Re: WblockCloneobjects Problem with Styles
« Reply #2 on: January 08, 2015, 03:08:03 PM »
U do not need to wrap the active document's database in a using block Autocad will dispose of database

makoychan

  • Guest
Re: WblockCloneobjects Problem with Styles
« Reply #3 on: January 09, 2015, 12:17:41 PM »
You mean the   using (Database db = new Database(false, true))?  yes, i did try to remove that and it worked, but if i call the db.diposed then it will hang again.

Won't it create  a memory leak? if your not going to dispose it?


MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: WblockCloneobjects Problem with Styles
« Reply #4 on: January 09, 2015, 01:00:59 PM »
You mean the   using (Database db = new Database(false, true))?  yes, i did try to remove that and it worked, but if i call the db.diposed then it will hang again.

Won't it create  a memory leak? if your not going to dispose it?

No.  The GC is taking care of that.
Revit 2019, AMEP 2019 64bit Win 10

makoychan

  • Guest
Re: WblockCloneobjects Problem with Styles
« Reply #5 on: January 09, 2015, 02:07:23 PM »
Thanks for the info MexicanCustard, another thing not sure if you've encountered this.

after the Wcloneobject command execute, the mapping variable has na error insde it  "OriginalDatabase: '(mapping).OriginalDatabase' threw an exception of type 'Autodesk.AutoCAD.Runtime.Exception'" though the cloning went successful, but the mapping seems to be having some error inside it.

have you encoutered this or have any idea on it?

Thanks in advance.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: WblockCloneobjects Problem with Styles
« Reply #6 on: January 12, 2015, 08:37:29 AM »
"OriginalDatabase: '(mapping).OriginalDatabase'

Not sure what you mean with the statement above.  You can think of the mapping as a Dictionary<ObjectId, ObjectId> with the Key being the original ObejctId and the value being the cloned ObjectId.
Revit 2019, AMEP 2019 64bit Win 10