.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Returning focus to AutoCAD

6 REPLIES 6
Reply
Message 1 of 7
montaljo
952 Views, 6 Replies

Returning focus to AutoCAD

Hi all!

I'm creating a C# app that calls an imported function from a DLL that is a wrapper for a legacy ARX application. When the C# app calls the ARX routine (through the wrapper DLL), the ARX routine prompts the user for a point to place an Xref. This part works fine.

My problem is that the C# form has focus and I can't get back to AutoCAD to place the Xref. I've tried to Hide() and Show() the form around the call to the DLL function, but that only serves to hide the form and I have to terminate AutoCAD from the Task Manager. Is there a way to return focus to AutoCAD so I can place my Xref?

I'm developing on XP in Visual Studio 2002 for AutoCAD 2006. I'm new to the wonderful world of .NET and AutoCAD development, so any help would be greatly appreciated.

Thanks
-john
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: montaljo

try calling Visible = false, then call the ARX library,
and after it returns set Visible = true again.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5580739@discussion.autodesk.com...
Hi all!

I'm creating a C# app that calls an imported function from a DLL that is a wrapper for a legacy ARX application. When the C# app calls the ARX routine (through the wrapper DLL), the ARX routine prompts the user for a point to place an Xref. This part works fine.

My problem is that the C# form has focus and I can't get back to AutoCAD to place the Xref. I've tried to Hide() and Show() the form around the call to the DLL function, but that only serves to hide the form and I have to terminate AutoCAD from the Task Manager. Is there a way to return focus to AutoCAD so I can place my Xref?

I'm developing on XP in Visual Studio 2002 for AutoCAD 2006. I'm new to the wonderful world of .NET and AutoCAD development, so any help would be greatly appreciated.

Thanks
-john
Message 3 of 7
montaljo
in reply to: montaljo

Thanks Tony, but that gave me the same results. Here is my code that calls the ARX wrapper function. Maybe I'm doing something strange here:

private void button1_Click(object sender, System.EventArgs e)
{
Button myButton = (Button)sender;
Form myForm = (Form)myButton.Parent;

myForm.Visible = false;

XrefDevice testDev = new XrefDevice();
testDev.drawDevice();

myForm.Visible = true;
}

The XrefDevice class contains the imported wrapper function which is called by XrefDevice.drawDevice().

Thanks!
Message 4 of 7
dmarcotte4
in reply to: montaljo

you can try something like this

[DllImport("user32.dll")]
private static extern System.IntPtr SetFocus(System.IntPtr hwnd);
//
private void SetFocusToActiveDocument()
{
SetFocus(AcadApp.MainWindow.Handle);
}
Message 5 of 7
Anonymous
in reply to: montaljo

Try replacing the call to the Arx library with a calll
to the Editor's GetEntity() method, and see if that
works. If it does, then the problem being caused
by something the ARX library is doing.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5581337@discussion.autodesk.com...
Thanks Tony, but that gave me the same results. Here is my code that calls the ARX wrapper function. Maybe I'm doing something strange here:

private void button1_Click(object sender, System.EventArgs e)
{
Button myButton = (Button)sender;
Form myForm = (Form)myButton.Parent;

myForm.Visible = false;

XrefDevice testDev = new XrefDevice();
testDev.drawDevice();

myForm.Visible = true;
}

The XrefDevice class contains the imported wrapper function which is called by XrefDevice.drawDevice().

Thanks!
Message 6 of 7
montaljo
in reply to: montaljo

The GetEntity worked. I'll have to take a look at the old ARX lib.

Thanks for your help! This stuff is almost fun! 🙂
-john
Message 7 of 7
mohnston
in reply to: montaljo

I found that graphscr worked for switching focus from a palette to the drawing. I don't know if it will work in your situation.
I found graphscr in acmgdinternal.dll
Autodesk.AutoCAD.Internal.Utils

Regarding acmgdinternal.dll:
"Thunk to AutoCAD from .NET - not intended for public API consumption" Message was edited by: Mark Johnston - I thunk of something I should probably add to my post.
CAD Programming Solutions

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost