Author Topic: Document collection items.  (Read 6095 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Document collection items.
« on: September 07, 2010, 10:44:00 AM »
If I want the active document and it's database:

DocumentCollection docCol = AcadApp.DocumentManager;
Document doc = docCol.MdiActiveDocument;
Database db = doc.Database;


Q: How I can get the database from a different document in the docCol that is not the active document?

I've searched quite a bit without success.








T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #1 on: September 07, 2010, 11:20:38 AM »
The same way.  The only thing that matters is how you find out which document you want the database from.  You could step through the collection with a foreach, and then when you find the one you want, you just grab the database.  You might be able to grab it from the item number, but I'm not sure if that way works.

foreach ( Document doc in docCol ) {
    if ( doc.Name == searchName )
        Database db = doc.Database;
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #2 on: September 07, 2010, 11:23:18 AM »
The same way.  The only thing that matters is how you find out which document you want the database from.  You could step through the collection with a foreach, and then when you find the one you want, you just grab the database.  You might be able to grab it from the item number, but I'm not sure if that way works.

foreach ( Document doc in docCol ) {
    if ( doc.Name == searchName )
        Database db = doc.Database;
}

I thought about doing it that way in the mean time.
Didn't know if it was the only or best way but I'll give it a shot!

Thanks Tim.



T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #3 on: September 07, 2010, 11:34:16 AM »
You're welcome Bill.

You might be able to do something like

docCol[1].Database

But I'm not sure, as I've only done it the way I've shown already.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #4 on: September 07, 2010, 02:31:23 PM »
Iterating works fine as I have know what filename I'm using.

Did you ever figure out how to update the destination drawing so the wblockcloned entities show up immediately?


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #5 on: September 07, 2010, 02:52:43 PM »

Did you ever figure out how to update the destination drawing so the wblockcloned entities show up immediately?


If you're talking about this one

http://www.theswamp.org/index.php?topic=33321.0;all  - Copy block definitions - Beta testing

Then no.  I haven't worked on that one in awhile.  If not that one, then I don't think I remember the code, and that means most likely not.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #6 on: September 07, 2010, 03:18:38 PM »
Might've been, about the same date.
I saw it here:

 http://forums.autodesk.com/t5/NET/Updating-blocks-in-open-non-current-drawing/m-p/2678788#M19093

I still have a long way to go on this project.
I'm trying to copy a group from one drawing to another.
Like copyclip as block, except a group instead.

Am I re inventing the wheel?


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #7 on: September 07, 2010, 03:43:18 PM »
I think those two are about the same code, so I would say no I haven't found a solution.  Sorry Bill.  Wish I could help more with that.

I still have a long way to go on this project.
I'm trying to copy a group from one drawing to another.
Like copyclip as block, except a group instead.

Am I re inventing the wheel?



I would say yes.  I guess I would ask, is what's given not able to do what you want?  If not, then proceed.  I would think that you could do what you want.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #8 on: September 07, 2010, 03:54:25 PM »
Alrighty then, full speed ahead.  :-)

Oh, can you tell me what's the best way to identify the new entities after I wblockclone them over to the non active drawing.
I don't think that the IDMap variable works in that drawing.

Code: [Select]
try
{
  Database DestData = GetDestinationDB(path, docCol);

  Document DestDoc = GetDestinationDoc(path, docCol);
                                        
  if (DestDoc != null && DestDoc.Name.Equals(path))
       {
                   using (DestDoc.LockDocument())
                     {
                         using (Transaction twb = DestData.TransactionManager.StartTransaction())
                              {

                                IdMapping IDMap = new IdMapping();

                                IDMap = database.WblockCloneObjects(new ObjectIdCollection(EntIds), DestData.CurrentSpaceId, DuplicateRecordCloning.Replace, false);

                                twb.Commit();

                                editor.WriteMessage("\nTransaction complete.");
                                                    }                                                
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Filename chosen is not open in drawing editor.");
                                        }
                                    }
                              }
                        }
         }
« Last Edit: September 07, 2010, 03:58:52 PM by BillZndl »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #9 on: September 07, 2010, 04:02:50 PM »
The function itself returns null or void, so the mapping you would use is the one you supply.

From the Managed Arx Docs
Quote
public unsafe void WblockCloneObjects(
    ObjectIdCollection identifiers,
    ObjectId id,
    IdMapping mapping,
    Autodesk.AutoCAD.DatabaseServices.DuplicateRecordCloning cloning,
    [MarshalAs(UnmanagedType.U1)] bool deferTranslation
);

mapping is filled with IdPair objects that contain the objectId entities of the original and cloned object pairs. This array can be used for post-processing the objects involved in the deepClone operation.

In your call you are not supplying the idmap correctly.  Your call should look like

database.WblockCloneObjects(new ObjectIdCollection(EntIds), DestData.CurrentSpaceId, IDMap, DuplicateRecordCloning.Replace, false);
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #10 on: September 07, 2010, 04:12:49 PM »

In your call you are not supplying the idmap correctly.  Your call should look like

database.WblockCloneObjects(new ObjectIdCollection(EntIds), DestData.CurrentSpaceId, IDMap, DuplicateRecordCloning.Replace, false);

Not in net 2.0

Kinda weird but that's what I'm stuck with because of the windows versions here.

I'll have to play with this some more and see what will go.

Thanks again!



T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #11 on: September 07, 2010, 04:18:13 PM »
I don't think the Windows .Net version matters that much since it is a Acad call.  I didn't look through my code though to see how I did it, but that is from the '09 help, so maybe in another version of Acad it is a different call.  Weird.


Edit:  I see in '06 it does return an IdMapping.  So then, I think, it is like an associate list in lisp, where the first item is the old ObjectId and the second item is the new Id.  But then again I have never used an IdMapping object.
« Last Edit: September 07, 2010, 04:25:50 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #12 on: September 07, 2010, 04:46:41 PM »
I don't think the Windows .Net version matters that much since it is a Acad call.  I didn't look through my code though to see how I did it, but that is from the '09 help, so maybe in another version of Acad it is a different call.  Weird.

Ya, all I know is that when I went to net3.5 in WinXP it worked for me but when I tried to load net3.5 on the win2000 machines, it was a no go.


BillZndl

  • Guest
Re: Document collection items.
« Reply #13 on: September 09, 2010, 08:50:51 AM »

Did you ever figure out how to update the destination drawing so the wblockcloned entities show up immediately?


FWIW:

I used this to make the WblockClone entities to "appear".
I set the drawing to MDIActive before I processed the oids.

Code: [Select]
foreach (ObjectId id in Module.GrpInfoLst)  //Module is arraylist containing object ids from the IMap pairs.
    {
   Entity en = trans.GetObject(id, OpenMode.ForWrite) as Entity;                        

      if (en != null)
        {
          en.RecordGraphicsModified(true);                                
        }
}
    trans.TransactionManager.QueueForGraphicsFlush();                                        
    trans.Commit();

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #14 on: September 09, 2010, 11:30:34 AM »
I think I tried that, now that you mention it, but I didn't like it switching back and forth, so I didn't go that route.  I think Tony said that it was an oversight, as to make item appear like that in Arx you can change the current document, without switching it to the active document, but it isn't exposed to .Net, so if you want to P/Invoke I think you can get it without switching the active document.

Thanks for posting your solution Bill.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kaefer

  • Guest
Re: Document collection items.
« Reply #15 on: September 09, 2010, 12:00:52 PM »
I think I tried that, now that you mention it, but I didn't like it switching back and forth, so I didn't go that route.  I think Tony said that it was an oversight, as to make item appear like that in Arx you can change the current document, without switching it to the active document, but it isn't exposed to .Net, so if you want to P/Invoke I think you can get it without switching the active document.

Correct me if I'm wrong: nowhere seems to be an exposed signature of AcApDocManager::setCurDocument, so you can't even P/Invoke it.

Apart from that, what does the average End User expect here? Is it OK to manipulate an opened non-current drawing? If it's opened by anyone else, it would be effectively write-protected; why then handle the case that it's opened in the same application session differently?

Cheers, Thorsten

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Document collection items.
« Reply #16 on: September 09, 2010, 12:21:00 PM »
Apart from that, what does the average End User expect here? Is it OK to manipulate an opened non-current drawing? If it's opened by anyone else, it would be effectively write-protected; why then handle the case that it's opened in the same application session differently?

I have a program that I wrote to update revisions for our drawings.  I do it without opening the drawing in the editor, and I allow the user to select as many drawings as they want within a folder.  If they happen to have a drawing open, then with the old code it wouldn't update the drawing, but they selected it to update, so why not update it if they have it open?

My thought is why limit the user?  If they select a couple of drawings that they want to update, and they happen to have one of them open, why not update that one also?  If it's open by another user, then I wouldn't try to do anything to said drawing, but would alert the user that said drawing couldn't have the work preformed on it.

Sometimes users forget which drawings they have open, and sometimes the only option is to select drawings from a file selection dialog box.  If they select it, do what you can to it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Document collection items.
« Reply #17 on: September 09, 2010, 01:06:29 PM »
I think I tried that, now that you mention it, but I didn't like it switching back and forth, so I didn't go that route.

This works fine for me as when I'm working in one drawing (making groups) and see that I have the same group existing already over in anther drawing, I can switch drawings, select the group and end up back in the original drawing with the copied group displaying nicely, instead of making the group from scratch.