Author Topic: Something about Xref functions...  (Read 9149 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Something about Xref functions...
« Reply #45 on: November 21, 2008, 11:35:54 AM »
Here is one that will work if it does / doesn't have an xclip already.

Code: [Select]
[CommandMethod( "TestCopyXClip" )]
public void TestCopyXClip() {
PromptEntityResult per;
ObjectId tempId;
DBDictionary nFltDict;

Document Doc = acadApp.DocumentManager.MdiActiveDocument;
Database Db = Doc.Database;
Editor Ed = Doc.Editor;

using ( Transaction Trans = Db.TransactionManager.StartTransaction() ) {
per = Ed.GetEntity( "\n Select xref to copy xclip from: " );
Entity FromEnt = Trans.GetObject( per.ObjectId, OpenMode.ForRead ) as Entity;

per = Ed.GetEntity( "\n Select xref to copy xclip to: " );
Entity ToEnt = Trans.GetObject( per.ObjectId, OpenMode.ForRead ) as Entity;

DBDictionary xDictFrom = Trans.GetObject( FromEnt.ExtensionDictionary, OpenMode.ForRead ) as DBDictionary;
tempId = xDictFrom.GetAt( "ACAD_FILTER" );
DBDictionary FltDict = Trans.GetObject( tempId, OpenMode.ForRead ) as DBDictionary;
tempId = FltDict.GetAt( "SPATIAL" );
SpatialFilter SptFlt = Trans.GetObject( tempId, OpenMode.ForRead ) as SpatialFilter;

if ( ToEnt.ExtensionDictionary == ObjectId.Null ) {
ToEnt.UpgradeOpen();
ToEnt.CreateExtensionDictionary();
ToEnt.DowngradeOpen();
}
DBDictionary xDictTo = Trans.GetObject( ToEnt.ExtensionDictionary, OpenMode.ForRead ) as DBDictionary;
if ( xDictTo.Contains( "ACAD_FILTER" ) ) {
tempId = xDictTo.GetAt( "ACAD_FILTER" );
nFltDict = Trans.GetObject( tempId, OpenMode.ForWrite ) as DBDictionary;
if ( nFltDict.Contains( "SPATIAL" ) )
nFltDict.Remove( "SPATIAL" );
SpatialFilter nSptFlt = SptFlt.DeepClone( nFltDict, new IdMapping(), true ) as SpatialFilter;
nFltDict.SetAt( "SPATIAL", nSptFlt );
Trans.AddNewlyCreatedDBObject( nSptFlt, true );
}
else {
xDictTo.UpgradeOpen();
nFltDict = FltDict.DeepClone( xDictTo, new IdMapping(), true ) as DBDictionary;
xDictTo.SetAt( "ACAD_FILTER", nFltDict );
Trans.AddNewlyCreatedDBObject( nFltDict, true );
}
Db.ResolveXrefs( true, true );
//Ed.Regen();
Trans.Commit();
}
}
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Something about Xref functions...
« Reply #46 on: November 21, 2008, 06:24:07 PM »

Nice job guys.
isn't it fun working at the bleeding edge :)
 .. but somehow satisfyng!


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<--

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Something about Xref functions...
« Reply #47 on: November 21, 2008, 06:29:31 PM »

Nice job guys.
isn't it fun working at the bleeding edge :)
 .. but somehow satisfyng!

Yea, but I was getting very frustrated when it wouldn't stick.  Stupid simple single command missing.
Tim

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

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Something about Xref functions...
« Reply #48 on: November 21, 2008, 06:31:23 PM »
Tim,
just a note on convention.
usually variable names begin with a lowercase letter.
while this makes absolutely no difference to the compiler, personally I find it helps when visually scanning code if this (convention) is follwed consistently.
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<--

T.Willey

  • Needs a day job
  • Posts: 5218
Re: Something about Xref functions...
« Reply #49 on: November 21, 2008, 07:04:57 PM »
Tim,
just a note on convention.
usually variable names begin with a lowercase letter.
while this makes absolutely no difference to the compiler, personally I find it helps when visually scanning code if this (convention) is follwed consistently.

I agree.  If this was code I was going to use I would rewrite it, or at least rename the variables.  I was just happy to get it working, so I didn't want to have to do anymore with it than I did today.   :wink:
Tim

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

Please think about donating if this post helped you.

Bryco

  • Water Moccasin
  • Posts: 1850
Re: Something about Xref functions...
« Reply #50 on: November 22, 2008, 12:07:35 AM »
Quote
isn't it fun working at the bleeding edge
Kerry I'm surprised at how often a search for something new to me ends up at your code.
I don't know how you start with so little info and end up with the right stuff.