- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
How can we made interactive between user form button and model space? When I click a button in user form, it needs me to click the model space first. Only after that the task will begin.
I want it to be like what autocad have. Click on the button and directly begin the work in the model space, without needing to click the model space first.
Here is my code :
User Form setting :
Public Class UICall
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Friend Shared AcPs As Autodesk.AutoCAD.Windows.PaletteSet = Nothing
Private UIClass As LogicUI = Nothing
<CommandMethod("LogicUI")> _
Public Sub CallLogicUserInterface()
If AcPs = Nothing Then
AcPs = New Autodesk.AutoCAD.Windows.PaletteSet("Logic User Interface", New Guid("{3AD1B2B3-8194-4FA9-B91E-91BBB45279E3}"))
AcPs.Style = Autodesk.AutoCAD.Windows.PaletteSetStyles.ShowCloseButton
UIClass = New LogicUI
AcPs.Add("Logic UI", UIClass)
AcPs.Size = New Drawing.Size(200, 700)
End If
AcPs.Visible = False : AcPs.Visible = True
AcPs.WindowState = Autodesk.AutoCAD.Windows.Window.State.Normal
AcPs.Dock = Autodesk.AutoCAD.Windows.DockSides.Left
End Sub
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
CallLogicUserInterface()
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
AcPs = Nothing
AcPs.Dispose()
End Sub
End Class
Click Event in the userform :
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim cl As Class1 = New Class1
cl.CreateLine()
End Sub
Cad function :
Public Sub CreateLine()
Dim ed As Editor = App.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction
Dim ppr As PromptPointResult = ed.GetPoint(vbLf & "Specify base point")
Dim pt1 As Point3d = ppr.Value
ppr = ed.GetPoint(vbLf & "Specify next point")
Dim pt2 As Point3d = ppr.Value
Dim acLine As Line = New Line(pt1, pt2)
Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
btr.AppendEntity(acLine)
tr.AddNewlyCreatedDBObject(acLine, True)
tr.Commit()
End Using
End Sub
Solved! Go to Solution.