TheSwamp
Code Red => .NET => Topic started by: T.Willey on March 25, 2011, 12:52:49 PM
-
I was wondering if there was a better way of doing this then using the ' HasContext ' method on each entity per each scale. I tried to step through the extension dictionary, but can't seem to figure out the final step with .Net. I can get there with lisp, to see the scales, but not with .Net. Here is the section of code I'm talking about. The objects that are returned in the spot marked are ' ACDBBLOCKREFOBJECTCONTEXTDATACLASS ' and I can see no way to use them, and they reference the annotation scale, so I need to get some information from them.
I can't cast them to an AnnotationScale or ObjectContext, as they are not from the DBObject class.
foreach ( ObjectId id in btr ) {
Entity Ent = Trans.GetObject( id, OpenMode.ForRead ) as Entity;
if ( Ent.Annotative == AnnotativeStates.False ) continue;
List<AnnotationScale> tempScList = new List<AnnotationScale>();
//foreach ( AnnotationScale asc in ScList ) {
// if ( Ent.HasContext( asc ) ) tempScList.Add( asc );
//}
ObjectId ExId = Ent.ExtensionDictionary;
if ( ExId.IsNull ) continue;
DBDictionary ExDict = Trans.GetObject( ExId, OpenMode.ForRead ) as DBDictionary;
if ( !ExDict.Contains( "AcDbContextDataManager" ) ) continue;
DBDictionary CdmDict = Trans.GetObject( ExDict.GetAt( "AcDbContextDataManager" ), OpenMode.ForRead ) as DBDictionary;
if ( !CdmDict.Contains( "ACDB_ANNOTATIONSCALES" ) ) continue;
DBDictionary AnsDict = Trans.GetObject( CdmDict.GetAt( "ACDB_ANNOTATIONSCALES" ), OpenMode.ForRead ) as DBDictionary;
foreach ( DBDictionaryEntry de in AnsDict ) {
// this is the problem area
}
foreach ( AnnotationScale asc in tempScList ) ScList.Remove( asc );
}
-
Here is some code I have messing with Scales
I thought Viewport were the only ones with AnnotationScale property?
[CommandMethod("AddTWilleyScale")]
static public void AddTWilleyScale()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectContextManager contextManager = db.ObjectContextManager;
if (contextManager == null)
return;
ObjectContextCollection contextCollection = contextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
if (contextCollection == null)
return;
AnnotationScale annoScale = new AnnotationScale();
annoScale.Name = "TWileyScale";
annoScale.PaperUnits = 1;
annoScale.DrawingUnits = 23;
contextCollection.AddContext(annoScale);
}
[CommandMethod("PrintScaleList")]
static public void PrintScaleList()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectContextManager contextManager = db.ObjectContextManager;
if (contextManager == null)
return;
ObjectContextCollection contextCollection = contextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
if (contextCollection == null)
return;
foreach (ObjectContext objCxt in contextCollection)
{
AnnotationScale scale = objCxt as AnnotationScale;
ed.WriteMessage("\n AnnoScale is " + scale.Name);
}
}
[CommandMethod("ChangeVpAnnoScale")]
static public void ChangeVpAnnoScale()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Viewport: ");
peo.SetRejectMessage("\nInvalid selection...");
peo.AddAllowedClass(typeof(Viewport), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
Viewport vp = per.ObjectId.GetObject(OpenMode.ForWrite) as Viewport;
ObjectContextManager contextMgr = db.ObjectContextManager;
ObjectContextCollection contextCollection = contextMgr.GetContextCollection("ACDB_ANNOTATIONSCALES");
AnnotationScale scale = contextCollection.GetContext("TWileyScale") as AnnotationScale;
vp.AnnotationScale = scale;
trx.Commit();
}
}
-
Viewports are the only ones that have that property ( AnnotationScale ) that you can get that way.
-
[color=blue]using Autodesk.AutoCAD.Internal;[/color]
[CommandMethod("GetEntityScales")]
public void GetEntScales()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("Select an ent: ");
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
using (Transaction t = db.TransactionManager.StartTransaction())
{
Entity e = t.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;
if (e == null) return;
[color=blue]List<ObjectContext> contexts =
ObjectContexts.GetContexts(e, "ACDB_ANNOTATIONSCALES");[/color]
foreach (ObjectContext context in contexts)
{
[color=blue]AnnotationScale scale = (AnnotationScale)context;[/color]
ed.WriteMessage("{0} ({1}:{2})", scale.Name, scale.PaperUnits, scale.DrawingUnits);
}
}
}
-
Is that new Dan? I don't seem to have it in 2009. :cry:
-
whoops -- edited for dll name.
Hrm; I never checked in the days of yore and am not sure I have a copy lying around. Autodesk.AutoCAD.Internal in '09 requires an additional reference, though -- add a reference to acmgdinternal.dll in your Program Files folder [unless you already did...].
-
Hrm; I never checked in the days of yore and am not sure I have a copy lying around. Autodesk.AutoCAD.Internal in '09 requires an additional reference, though -- add a reference to acmgdinternal.dll in your Program Files folder [unless you already did...].
I do still have it. Once you add that reference and the Using Autodesk.AutoCAD.Internal, you should be golden.
-
Thanks Dan. That worked.
Now I got other trouble though. :-D If I can't figure that out I'll be back.
-
All is working now as it should. Thanks again.
-
You're welcome.