Author Topic: Regen Acad, or Refresh entity ?  (Read 16964 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Regen Acad, or Refresh entity ?
« on: September 30, 2009, 07:31:41 PM »
I'm trying to do something in C# that I coded in Lisp.  The lisp isn't very fast, so I thought it could be a good exercise to try it in C# since I haven't done any coding in awhile.  I think I have most of it working now, but I can't figure out how to regen the drawing to show the entities' current visible state.  I was hoping that this could be done in just C#, but from what I have read, it doesn't appear so.  I'm hoping someone can point me in the right direction, or confirm what I hope isn't true.  I'm still on '06, and using .Net 2.0.

Thanks in advance.
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: Regen Acad, or Refresh entity ?
« Reply #1 on: September 30, 2009, 07:43:14 PM »

not sure about 2006, but in 2010

public void Regen();
Declaring Type: Autodesk.AutoCAD.EditorInput.Editor
Assembly: acmgd, Version=18.0.0.0

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Regen Acad, or Refresh entity ?
« Reply #2 on: October 01, 2009, 01:13:50 AM »
I didn't see that option in '06, but will check again tomorrow at work.

Thanks Kerry.
Tim

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

Please think about donating if this post helped you.

BillZndl

  • Guest
Re: Regen Acad, or Refresh entity ?
« Reply #3 on: October 01, 2009, 07:00:50 AM »
Don't know if this will help you Tim
but I had to use these when changing the entity
highlighting inside block records and references,
otherwise the changes wouldn't show.

Might be worth a try.

Code: [Select]
foreach (ObjectId blid in blkRefIds)
{
BlockReference BlkRef = (BlockReference)tr.GetObject(blid, OpenMode.ForWrite);
BlkRef.RecordGraphicsModified(true);
tr.TransactionManager.QueueForGraphicsFlush();

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Regen Acad, or Refresh entity ?
« Reply #4 on: October 01, 2009, 11:55:48 AM »
Kerry - Didn't see it in '06 or even '08, so I'm not sure when it came in.

Bill - Tried that in a couple different ways, but didn't work here.  I'll keep looking to see if I can find a way.  Found your way over I see.  Good people here.  I'm sure you will like.
Tim

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

Please think about donating if this post helped you.

ReneRam

  • Guest
Re: Regen Acad, or Refresh entity ?
« Reply #5 on: October 02, 2009, 05:50:02 AM »
Hi Tim,
maybe I misunderstood the question, but to update the screen in my apps I do the following:

Code: [Select]
' Update Screen
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()

or

Code: [Select]
Dim myDWG as ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim myDB as DatabaseServices.Database = myDWG.Database
Dim myEd as EditorInput.Editor = myDWG.Editor
' Update Editor
myEd.Regen()


Sorry it's Vb.Net, but I'm sure you can read it!
René

Draftek

  • Guest
Re: Regen Acad, or Refresh entity ?
« Reply #6 on: October 02, 2009, 08:38:58 AM »
Prior to '09 you can try method this on each object:

line.CloseAndPage(true);

Otherwise, your looking at Invoke an arx method.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Regen Acad, or Refresh entity ?
« Reply #7 on: October 02, 2009, 11:02:13 AM »
Thanks guys.  When I get a chance today I will test both ideas.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Regen Acad, or Refresh entity ?
« Reply #8 on: October 09, 2009, 11:45:12 AM »
Well I wasn't able to get it to work with '06.  I tried the ways listed here, and looked for some others, but I just couldn't find one.  I'm not sure if that will matter much, as we are moving to '09 soon.  Now the problem is that with '09 there is the regen method, but it doesn't regen the whole drawing.  I used the command in paper space with one viewport, and the viewport didn't regen.  I tried looking in the help, but I didn't see any way to get it to regen the whole drawing.  I don't know when I will get a chance to work on this again, maybe next week sometime, but just wanted to update people on what I tried, and how it turned out.

Thanks for the help.
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: 1883
Re: Regen Acad, or Refresh entity ?
« Reply #9 on: October 09, 2009, 08:08:27 PM »
This seemed to do the trick
Code: [Select]
[CommandMethod("rall")]
        public static void RegenAll()
        {

            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Viewport vp;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                LayoutManager lm = LayoutManager.Current;
                if (lm.CurrentLayout.ToLower() == "model") db.TileMode =false;
                lm.CurrentLayout = lm.CurrentLayout;
                Layout layout = tr.GetObject(lm.GetLayoutId(lm.CurrentLayout), OpenMode.ForRead) as Layout;
                ObjectIdCollection vpIds = layout.GetViewports();
                if (vpIds.Count <2) { ed.Regen(); return; }
                ed.SwitchToModelSpace();
                for (int i = 1; i < vpIds.Count; i++)
                {
                    vp = tr.GetObject(vpIds[i], OpenMode.ForWrite) as Viewport;
                    ed.SwitchToModelSpace();
                    acadApp.SetSystemVariable("Cvport", vp.Number);                 
                    ed.Regen();
                    ed.SwitchToPaperSpace();
                }
                tr.Commit();
            }

        }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Regen Acad, or Refresh entity ?
« Reply #10 on: October 09, 2009, 09:26:32 PM »

Tim ;  Bryce,

I just checked some old DLL's
The Editor.Regen in available from AC2007, not in AC2006.

Regards
Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Regen Acad, or Refresh entity ?
« Reply #11 on: October 09, 2009, 09:56:03 PM »
as suggested by Draftek , just p/invoke ads_regen. the function is exported so it should be compatible across all versions of acad  :-)

Code: [Select]
namespace ExecMethod
{
 public class Commands
 {
  [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
  static internal extern int ads_regen();

  [CommandMethod("doit")]
  static public void Doit()
  {
   ads_regen();
  }
 }
}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Regen Acad, or Refresh entity ?
« Reply #12 on: October 09, 2009, 10:03:11 PM »

I just came back to post similar code :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Regen Acad, or Refresh entity ?
« Reply #13 on: October 09, 2009, 10:11:47 PM »
... I used the command in paper space with one viewport, and the viewport didn't regen...
Thanks for the help.

I think the problem may be that your layouts are cached, I don't recall if I ever found a way around this

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Regen Acad, or Refresh entity ?
« Reply #14 on: October 09, 2009, 10:36:47 PM »
How about SendStringToExecute  :lol:

Code: [Select]
[CommandMethod("doit")]
  static public void Doit()
  {
   try
   {
    AcAp.Application.DocumentManager.
     MdiActiveDocument.SendStringToExecute
       ("REGENALL ", true, false, false);
   }
   catch (System.Exception ex)
   {
    AcAp.Application.DocumentManager.
      MdiActiveDocument.Editor.WriteMessage
       ("\n{0}\n{1}", ex.Message, ex.StackTrace);
   }
  }