If anyone wants to mess with it.
I have not spent much time with it but it is a simple idea of creating a dynamic block and naming the visibility states to match the StandardScale Enum.
If you change ViewPort using the properties pallette then the dynamic block will update, but does not change if you use the little thing at bottom of screen.
Most of the time was spent building the block I will attach the block. During testing I just used DC to insert it and canceled it.
You use the command to insert the block and select the Viewport to change with it.
Just stareted messing with it so no jigging etc..........
static ObjectId vpId;
static ObjectId brefId;
[CommandMethod("AddImperialBarScale")]
public void AddImperialBarScale()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = (BlockTableRecord)trx.GetObject(bt["HpadCadBarScalesImperial"], OpenMode.ForRead);
BlockTableRecord currentSpace = (BlockTableRecord)trx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
Point3d insertionPnt = ed.GetPoint("Pick Insertion Point").Value;
BlockReference bref = new BlockReference(insertionPnt, btr.ObjectId);
brefId = currentSpace.AppendEntity(bref);
trx.AddNewlyCreatedDBObject(bref, true);
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;
vpId = per.ObjectId;
Viewport vp = trx.GetObject(per.ObjectId, OpenMode.ForWrite) as Viewport;
DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
{
if (dynBrefProps.PropertyName == "HpadVisibilityProperty")
{
StandardScaleType stdScale = ReturnTypeFromString(dynBrefProps.Value.ToString());
vp.StandardScale = stdScale;
break;
}
}
bref.Modified += new EventHandler(bref_Modified);
vp.Modified += new EventHandler(vp_Modified);
trx.Commit();
}
}
void vp_Modified(object sender, EventArgs e)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockReference bref = trx.GetObject(brefId, OpenMode.ForWrite) as BlockReference;
Viewport vp = trx.GetObject(vpId, OpenMode.ForRead) as Viewport;
DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
{
if (dynBrefProps.PropertyName == "HpadVisibilityProperty")
{
try
{
dynBrefProps.Value = vp.StandardScale.ToString();
}
catch
{
dynBrefProps.Value = StandardScaleType.CustomScale.ToString();
}
}
}
trx.Commit();
}
}
void bref_Modified(object sender, EventArgs e)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
Viewport vp = trx.GetObject(vpId, OpenMode.ForWrite) as Viewport;
BlockReference bref = trx.GetObject(brefId, OpenMode.ForRead) as BlockReference;
DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)
{
if (dynBrefProps.PropertyName == "HpadVisibilityProperty")
{
try
{
StandardScaleType stdScale = ReturnTypeFromString(dynBrefProps.Value.ToString());
vp.StandardScale = stdScale;
}
catch
{
vp.StandardScale = StandardScaleType.CustomScale;
}
}
}
trx.Commit();
}
}
public static StandardScaleType ReturnTypeFromString(string sst)
{
foreach (StandardScaleType stdScl in Enum.GetValues(typeof(StandardScaleType)))
{
if (stdScl.ToString() == sst)
return stdScl;
}
return StandardScaleType.CustomScale;
}