Author Topic: Copying plot settings  (Read 14022 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #30 on: January 30, 2007, 09:54:11 PM »
Excellent...why?

no sensible idea ..

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #31 on: January 30, 2007, 09:59:46 PM »
Also, click on one of the anon names (*A?), then in the right hand pane view, look at the 001 code...what do you notice?
Post your findings here.

I'd noticed the name .. was trying to find a relationship with ID's, but ..
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Copying plot settings
« Reply #32 on: January 30, 2007, 10:06:21 PM »
It's because they're dictionary entries and they aren't hard owned by default. Groups don't survive a wblock do they...
I remember reading some little tidbit of info in the ARX docs to support this, hence, when code copies them over, it gives them anonymous 'keys' in the dictionary.

Here is one way of copying them over.Note that I probably could have responded to the endDeepClone event instead of this:
Code: [Select]
public static bool ImportPageSetups(Document doc) {

// Do we have our template dbase?
if (_batchPageSetupTemplate == null)
return false; // Nope - bail out immediately!

// Get a pointer to the current doc's dbase...
Database curDb = doc.Database;

// Declare 2 transaction objects - one for each dbase...
Transaction curDbTr = null;
Transaction psDbTr = null;

Transaction psRenameTr = null;

// Objectid collection to hold the pagesetups we're going to clone...
ObjectIdCollection psIds = new ObjectIdCollection();

IdMapping psIdMap = null;

using (DocumentLock docLock = doc.LockDocument()) {

// Using a try/finally construct here as it's neater than
// trying to nest multiple using statements.
try {
// Kick off the transaction on the template dbase...
psDbTr = _batchPageSetupTemplate.TransactionManager.StartTransaction();
// ...also, kick off a trtansaction on the current dbase as well...
curDbTr = curDb.TransactionManager.StartTransaction();

// Open up the PlotSettings Dictionary on both dbase's...
DBDictionary curDbPsDict = (DBDictionary)curDbTr.GetObject(curDb.PlotSettingsDictionaryId, OpenMode.ForRead);
DBDictionary psDbPsDict = (DBDictionary)psDbTr.GetObject(_batchPageSetupTemplate.PlotSettingsDictionaryId, OpenMode.ForRead);

// Loop over the plot settings dictionary in the template and
// try to get the same entry in the current drawing.
// If we DO get it, erase it...
foreach (System.Collections.DictionaryEntry psDbPs in psDbPsDict) {
// Get the name...
string psName = (string)psDbPs.Key;

// Does it exist in our current dbase?
if (curDbPsDict.Contains(psName)) {
// Get it...
ObjectId curDbPsId = curDbPsDict.GetAt(psName);
// open it up...
PlotSettings curDbPs = (PlotSettings)curDbTr.GetObject(curDbPsId, OpenMode.ForWrite);
// Erase it...
curDbPs.Erase();
// Add this page setup object id into our collection of objects to clone...
psIds.Add((ObjectId)psDbPs.Value);
} else
psIds.Add((ObjectId)psDbPs.Value);

}//foreach

// OK, we now should have our list of objectid's to clone, but to be
// safe we check...
if (psIds.Count == 0)
return false;

// Got id's, so clone 'em
psIdMap = curDb.WblockCloneObjects(psIds, curDb.PlotSettingsDictionaryId, DuplicateRecordCloning.Ignore, false);

// Commit the transaction on our current dbase - we can abort the
// one on the template as we're not doing anything...
curDbTr.Commit();


// We need to commit the last transaction, above, and start a new one,
// as I suspect the cloned objects id's are in flux inside the above transaction,
// and we can't reliably access them.

psRenameTr = curDb.TransactionManager.StartTransaction();

DBDictionary dbDict = (DBDictionary)psRenameTr.GetObject(curDb.PlotSettingsDictionaryId, OpenMode.ForWrite);

// OK, we have an idmap, so loop it...
foreach (IdPair psIdPair in psIdMap) {
ObjectId id = psIdPair.Value;
DBObject obj = psRenameTr.GetObject(id, OpenMode.ForRead);

PlotSettings newPs = obj as PlotSettings;
if (newPs == null)
continue;

// Upgrade open...
newPs.UpgradeOpen();

string anonymousName = dbDict.NameAt(id);
// Set the correct name...
dbDict.SetName(anonymousName, newPs.PlotSettingsName);
}

psRenameTr.Commit();

} finally {

if (curDbTr != null)
curDbTr.Dispose();

if (psDbTr != null)
psDbTr.Dispose();

if (psRenameTr != null)
psRenameTr.Dispose();

}
}

return true;
}

Hope this helps.

Cheers,
Glenn.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #33 on: January 30, 2007, 10:12:06 PM »
.... and they aren't hard owned by default. ...

I'll need to stop and think about this later, but OK :-)

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #34 on: January 30, 2007, 10:15:02 PM »
Here is one way of copying them over.Note that I probably could have responded to the endDeepClone event instead of this:
Code: [Select]
public static bool ImportPageSetups(Document doc) {
///.......................
}

Hope this helps.

Cheers,
Glenn.

I'll print this out and have a good look tonight Glenn

Thanks Mr. !!
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Copying plot settings
« Reply #35 on: January 30, 2007, 10:23:20 PM »
Note that this was being used in a batch scenario, hence the Document argument to the function and also the document locking, as it was called from the Application execution context.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #36 on: January 30, 2007, 10:33:13 PM »
Note that this was being used in a batch scenario, hence the Document argument to the function and also the document locking, as it was called from the Application execution context.

Yep, I noticed the Template Database _batchPageSetupTemplate was a class variable ( or property)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #37 on: January 30, 2007, 11:22:40 PM »
...

Here is one way of copying them over.....

That's a fairly intricate solution Glenn ... must have taken a couple of concept jumps to get there ..

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #38 on: January 30, 2007, 11:28:06 PM »
Looks like I was sortof on the right track ..  :|
http://www.theswamp.org/index.php?topic=14290.msg172196#msg172196
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Copying plot settings
« Reply #39 on: January 30, 2007, 11:41:59 PM »
Quote
That's a fairly intricate solution...

Not really Kerry - it's essentially what I mentioned to try in pseudo form earlier in this thread, which you did. Kudos.
I wrote this quite a while ago and it probably could be cleaned up a bit.

The concept was what I had in mind from the start. I've known about the anon entries for a few years now, from when I implemented a VBA batching program. I got around the duplicates by blatantly erasing all the pagesetups in the target drawing during the batch run. This has the added bonus that you can change them in your template and be assured that every drawing batched will always have the latest page setup.

I still do this, however I now go through and 'fix' the anon names to what they should be.

Essentially, you read your template dbase, get the ids of all the pagesetups you're interested in, clone 'em, commit that transaction, then open the newly cloned pagesetups and fix up their names - not really that intricate...once you sort it out ;)

Somebody might come up with a revised version of this...

Hope it helps some Kerry.

Cheers,
Glenn.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #40 on: January 30, 2007, 11:49:39 PM »
........  I got around the duplicates by blatantly erasing all the pagesetups in the target drawing during the batch run. This has the added bonus that you can change them in your template and be assured that every drawing batched will always have the latest page setup.
.........


Just been through this .. a new printer here at home, and some changes at 'work' mean that almost ALL the Pagesetups changed.

I used PSETUPIN in a script situation on ALL drawings [ I'll leave the quantum to your imagination]

I'll have a good look at your solution when my head clears ..

Thanks
/// kwb
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Copying plot settings
« Reply #41 on: January 30, 2007, 11:53:40 PM »
You're welcome Kerry.
Once you have a page setup, or should I say, PlotSettings object, it makes  plotting a WHOLE lot easier as you just apply the page setup.
I'm interested to hear your comments.

Cheers,
Glenn.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #42 on: January 31, 2007, 12:05:10 AM »
To me, importing from a template wins hands down over trying to set the properties in code .. one reason is that the config can be modified without the necessity of re-working/recompiling the solution .. and the methodology is transparent and auditable.

I'd still like to investigate the copyFrom() method just for my education .. but that won't be this week .. :-D
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: Copying plot settings
« Reply #43 on: January 31, 2007, 12:11:22 AM »
Can you elaborate there Kerry - I might have a go at it and see what I come up with.
Me

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Copying plot settings
« Reply #44 on: January 31, 2007, 12:14:11 AM »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--