Author Topic: Changing Vp Standard scale with BarScale dynamic block  (Read 4834 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Changing Vp Standard scale with BarScale dynamic block
« on: June 01, 2011, 10:14:55 PM »
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..........

Code: [Select]
        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;

        }


Irvin

  • Guest
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #1 on: June 09, 2011, 04:11:15 AM »
Hi Jeff,


Do you mean the scaleing item on the status bar???

If so that's the annotation scaling feature. So i think there's an other event that needs to be triggerd. If you want to react to that.

Kind regards,

Irvin

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #2 on: June 09, 2011, 11:15:06 AM »
Hey Irvin,

It is about time you showed up here.

Your correct and I should have mentioned while in a paperspace layout if you select a viewport then change the annotation scale it changes the view scale.


Good to see you finally made it and thanks

jcoon

  • Newt
  • Posts: 157
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #3 on: June 09, 2011, 12:10:09 PM »
Jeff,

could you do the same with the diesel  $(*,$(getvar, dimscale), 5)
I use it to insert scale bars but its only good for one bar.

the anno one seems to be more versatile but I just get lost dealing with too many view ports. maybe could use the same idea with the annotation in dot net

john coon

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #4 on: June 09, 2011, 12:19:27 PM »
As it is the bar scale is only works with one viewport.

I am not fimilar diesel but the one posted below is limited to the 20 or so scales defined in the StandardScale enum.

Probably a better way would be to use the CustomScale property so you are not limited the scales in the standardScale enum.

jcoon

  • Newt
  • Posts: 157
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #5 on: June 09, 2011, 12:30:53 PM »
Jeff,

the anno scale bar "should" work in any viewports

John

jcoon

  • Newt
  • Posts: 157
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #6 on: June 09, 2011, 12:32:19 PM »
Jeff,

this scale bar works with the dim scale, only one per dwg

John

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #7 on: June 09, 2011, 12:50:50 PM »
Sorry,

I think I am confused and talking about something else


In paperspace
I was talking about if you use block in first post and change the visibility parameter the viewport updates its scale but the current implementation only works for scales defined in StandardScale enum

So insert block

Select block and change visibility parameter to be 3/4" = 1' then viewport scale changes to match change to 1/8" = 1' etc.........

Am I making any sense?

jcoon

  • Newt
  • Posts: 157
Re: Changing Vp Standard scale with BarScale dynamic block
« Reply #8 on: June 09, 2011, 12:53:59 PM »
Jeff,

sorry, I had it reversed......I get it now

John