Hi, I dont know why click button, form not close()
must double click middle point of mouse then form close
Thank advance!
import clr
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
from System import IntPtr
def sp():
try:
a = uidoc.Selection.PickPoint(ObjectSnapTypes.Endpoints,"Please select point")
except:
a = "NA"
return a
class pickPoint(Form):
def __init__(this):
this.button1 = Button()
#
#button1
#
this.button1.Location = System.Drawing.Point(288, 129)
this.button1.Name = "button1"
this.button1.Size = System.Drawing.Size(150, 34)
this.button1.TabIndex = 0
this.button1.Text = "Please Pick Point"
this.button1.Click += this.button1Click
#
#Form1
#
this.ClientSize = System.Drawing.Size(452, 196)
this.Controls.Add(this.button1)
this.Name = "Form1"
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
this.Text = "pickPoint"
this.ResumeLayout(False)
def button1Click(this,sender,e):
this.p = sp()
this.Close()
form = pickPoint()
Application.Run(form)
OUT = form.p
Hi,
Seem work fine
Note:
in python the name of the parameter which corresponds to the instance is ‘self
’ by convention not ‘this
’
2 Likes
Hi,
I Keep same code and changed “This” to “Self” but when click to button of Form, not get API menthod.
In the first time to click LeftMouse, not get API menthod. must press to scond time
If want Snap point before pickpoint I must press mid of mouse 2 times then can be snap points of element in Revit.
Last of video you can see, I used C# to pick point (result I can ObjectSnapTypes.Endpoints)
maybe there is a conflict with an add-ins, try to dispose the form at the end
1 Like
Here an alternative with Hide()
and Show()
import clr
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
from System import IntPtr
def sp(form):
form.Hide()
try:
a = uidoc.Selection.PickPoint(ObjectSnapTypes.Endpoints,"Please select point")
except Exception as ex:
print(ex)
a = "NA"
form.Show()
return a
class pickPoint(Form):
def __init__(self):
self.button1 = Button()
self.button2 = Button()
self._label1 = Label()
self.p = None
#
# label1
#
self._label1.Location = System.Drawing.Point(30, 50)
self._label1.Name = "label1"
self._label1.Size = System.Drawing.Size(300, 23)
self._label1.TabIndex = 0
self._label1.Text = "Point : "
#
#button1
#
self.button1.Location = System.Drawing.Point(288, 129)
self.button1.Name = "button1"
self.button1.Size = System.Drawing.Size(150, 34)
self.button1.TabIndex = 0
self.button1.Text = "Please Pick Point"
self.button1.Click += self.button1Click
#
#button1
#
self.button2.Location = System.Drawing.Point(30, 129)
self.button2.Name = "button2"
self.button2.Size = System.Drawing.Size(150, 34)
self.button2.TabIndex = 0
self.button2.Text = "Cancel"
self.button2.Click += self.button2Click
#
#Form1
#
self.ClientSize = System.Drawing.Size(452, 196)
self.Controls.Add(self.button1)
self.Controls.Add(self.button2)
self.Controls.Add(self._label1)
self.Name = "Form1"
self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
self.Text = "pickPoint"
self.ResumeLayout(False)
def button1Click(self,sender,e):
self.p = sp(self)
self._label1.Text = "Point : {}".format(self.p.ToString())
def button2Click(self,sender,e):
self.Close()
form = pickPoint()
Application.Run(form)
OUT = form.p
2 Likes
You are Idol !!
But as you said “maybe there is a conflict with an add-ins”, my code OK in my computer.