Author Topic: P/Invoke acedGetAcadDwgView  (Read 1778 times)

0 Members and 1 Guest are viewing this topic.

AARYAN

  • Newt
  • Posts: 64
P/Invoke acedGetAcadDwgView
« on: June 20, 2014, 07:48:33 AM »
Dear All,

I have a problem with DCL dialogs not removing themselves after they have
been closed until the lisp function is actually finished. I found a way in ARX but not in .NET.

Can anyone please guide me to invoke these lines in c#.net using P/Invoke method.

Code: [Select]
acedGetAcadDwgView()->InvalidateRect(NULL, TRUE);
acedGetAcadDwgView()->UpdateWindow();

& also

Code: [Select]
acedGetAcadFrame()->InvalidateRect(NULL, TRUE);
acedGetAcadFrame()->UpdateWindow();

Thanks in Advance.

AARYAN

  • Newt
  • Posts: 64
Re: P/Invoke acedGetAcadDwgView
« Reply #1 on: June 25, 2014, 07:54:46 AM »
If any one at least point me How can it be done in .net it would be highly appreciable.


Thanks in Advance.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: P/Invoke acedGetAcadDwgView
« Reply #2 on: June 25, 2014, 08:10:39 AM »
Code - C#: [Select]
  1. var ed = Application.DocumentManager.MDIActiveDocument.Editor;
  2. ed.UpdateScreen
  3.  

Is that what you're looking for?
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: P/Invoke acedGetAcadDwgView
« Reply #3 on: June 25, 2014, 08:28:40 AM »
You can also try
Code: [Select]
System.Windows.Forms.Application.DoEvents()
If you need to interact with the Application window you can get its handle
Code: [Select]
[DllImport("user32.dll")]
static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
[DllImport("user32.dll")]
static extern bool UpdateWindow(IntPtr hWnd);
Application.MainWindow.Handle
« Last Edit: June 25, 2014, 08:39:29 AM by MexicanCustard »
Revit 2019, AMEP 2019 64bit Win 10

AARYAN

  • Newt
  • Posts: 64
Re: P/Invoke acedGetAcadDwgView
« Reply #4 on: June 25, 2014, 09:37:08 AM »
Thanks for your reply.

I have tried Editor.UpdateScreen but it does not cause any effect, then I tried Editor.Regen method with DoEvents() it removes the dialog box but does not show the process in the command line (e.g "\r" function) until the lisp get finishes.

I will try again with Handle and let you know.

Thanks for your time.

Regards

AARYAN

  • Newt
  • Posts: 64
Re: P/Invoke acedGetAcadDwgView
« Reply #5 on: June 27, 2014, 05:15:08 AM »
Dear  MexicanCustard,

I have tried the following code but with no success. Can you point me if I am missing anything as I am quite new in the .net world. I am using Windows7 x86.

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace ClassLibrary1
{
    public class Class1
    {
        [DllImport("user32.dll")]
        static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
        [DllImport("user32.dll")]
        static extern bool UpdateWindow(IntPtr hWnd);

        [LispFunction("sRedraw")]
        public object CDRedraw(ResultBuffer LispArgs)
        {
            Editor AcadEditor = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            IntPtr hWnd = AcadApp.MainWindow.Handle;
            InvalidateRect(hWnd, IntPtr.Zero, true);
            UpdateWindow(hWnd);  // Tested upto here but not working.

            // added following code to test again. It does remove the dialog box
            // but the process in the commandline is not showing
            // e.g (princ (strcat "\rCreating Points" (itoa (1+ counter)) " of 2500"))
            AcadEditor.Regen();
            AcadEditor.UpdateScreen();
            System.Windows.Forms.Application.DoEvents();

            return null;
        }
    }
}

Thanks

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: P/Invoke acedGetAcadDwgView
« Reply #6 on: June 27, 2014, 07:52:24 AM »
So you're trying to run a LISP routine while another LISP routine is active?  I'm not a LISP guy but I would think there is an easier solution going the modify the first LISP routine route. 

Anyway, you might want to try creating a .NET command as a Transparent command so it can execute while the LISP routine is still active. Try this article
Revit 2019, AMEP 2019 64bit Win 10