.NET

Reply
Contributor
Saumitra
Posts: 15
Registered: ‎09-12-2007
Message 1 of 3 (100 Views)

Interaction between Winform and Acad

100 Views, 2 Replies
10-08-2007 11:34 AM
Hi:

I have a winform which I invoke (as a modeless form) from within AutoCad. The User makes a selection in the listbox of the form and clicks on the button. On button click, the form is minimised and the user is prompted to Select a point on the screen upon which a MText and DbText are inserted (text is governed by the list box selection).

On clicking the form button, I have to click 3 times on the Autocad window to actually do the insertion (even though the selection for a point is prompted at the first click). I would like to transfer control from form to Autocad in 1 click. Below is my code:

Private Sub cmdInsert_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles cmdInsert.Click

Dim db As Database = Nothing
Dim promptPoint As PromptPointOptions = Nothing
Dim promptResult As PromptPointResult = Nothing
Dim ptMText As Point3d = Nothing
Dim ptDText As Point3d = Nothing
Dim ed As Editor = Nothing

Try

Me.TopMost = False
Me.TopLevel = False

HostApplicationServices.WorkingDatabase = Autodesk.AutoCAD.ApplicationServices _
.Application.DocumentManager.MdiActiveDocument.Database
db = HostApplicationServices.WorkingDatabase
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager. _
MdiActiveDocument.Editor

'Prompt the user to select the point where the Material Item is to be imported.
promptPoint = New PromptPointOptions("Select the Insertion Point")
promptResult = ed.GetPoint(promptPoint)

If promptResult.Status = PromptStatus.OK Then

ptMText = promptResult.Value

'call the function to Create MText.
CreateMText(ptMText)

'call the function to Create DText. Calculate the position of the DText relative
'to the MTexy chosen.
ptDText = New Point3d(ptMText.X - 0.5625 * db.Dimscale, _
ptMText.Y - 0.25 * db.Dimscale, 0)
CreateDText(ptDText)

_SelectedNode = Nothing
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()

End If

Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace)
Finally

Me.TopMost = True
Me.TopLevel = True
_SelectedNode = Nothing
db = Nothing
ed = Nothing
ptMText = Nothing
ptDText = Nothing

End Try

End Sub
*Tony Tanzillo
Message 2 of 3 (100 Views)

Re: Interaction between Winform and Acad

10-08-2007 11:41 AM in reply to: Saumitra
Don't minimize the form, hide it.

--
http://www.caddzone.com

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

wrote in message news:5743547@discussion.autodesk.com...
Hi:

I have a winform which I invoke (as a modeless form) from within AutoCad. The User makes a selection in the listbox of the form and clicks on the button. On button click, the form is minimised and the user is prompted to Select a point on the screen upon which a MText and DbText are inserted (text is governed by the list box selection).

On clicking the form button, I have to click 3 times on the Autocad window to actually do the insertion (even though the selection for a point is prompted at the first click). I would like to transfer control from form to Autocad in 1 click. Below is my code:

Private Sub cmdInsert_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles cmdInsert.Click

Dim db As Database = Nothing
Dim promptPoint As PromptPointOptions = Nothing
Dim promptResult As PromptPointResult = Nothing
Dim ptMText As Point3d = Nothing
Dim ptDText As Point3d = Nothing
Dim ed As Editor = Nothing

Try

Me.TopMost = False
Me.TopLevel = False

HostApplicationServices.WorkingDatabase = Autodesk.AutoCAD.ApplicationServices _
.Application.DocumentManager.MdiActiveDocument.Database
db = HostApplicationServices.WorkingDatabase
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager. _
MdiActiveDocument.Editor

'Prompt the user to select the point where the Material Item is to be imported.
promptPoint = New PromptPointOptions("Select the Insertion Point")
promptResult = ed.GetPoint(promptPoint)

If promptResult.Status = PromptStatus.OK Then

ptMText = promptResult.Value

'call the function to Create MText.
CreateMText(ptMText)

'call the function to Create DText. Calculate the position of the DText relative
'to the MTexy chosen.
ptDText = New Point3d(ptMText.X - 0.5625 * db.Dimscale, _
ptMText.Y - 0.25 * db.Dimscale, 0)
CreateDText(ptDText)

_SelectedNode = Nothing
Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()

End If

Catch ex As Exception
MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace)
Finally

Me.TopMost = True
Me.TopLevel = True
_SelectedNode = Nothing
db = Nothing
ed = Nothing
ptMText = Nothing
ptDText = Nothing

End Try

End Sub
Contributor
Saumitra
Posts: 15
Registered: ‎09-12-2007
Message 3 of 3 (100 Views)

Re: Interaction between Winform and Acad

10-08-2007 11:56 AM in reply to: Saumitra
Hey Tony,

That worked. Thanks a lot. I was grappling with this issue for 1 and a half days.

Thanks

Saumitra
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.