How to use window form button to select Revit element?

How to use window form button to select Revit element?

peerawit.ru
Enthusiast Enthusiast
1,395 Views
7 Replies
Message 1 of 8

How to use window form button to select Revit element?

peerawit.ru
Enthusiast
Enthusiast

Hi everyone

I learning about how to create Revit add-in by Visual studio code.

I want to select Revit element via window form button but it seem like in not allow to access Revit when form open .

How to fix it?

 

Thank for your recommend.

0 Likes
Accepted solutions (1)
1,396 Views
7 Replies
Replies (7)
Message 2 of 8

moturi.magati.george
Autodesk
Autodesk

Hi @peerawit.ru,

 

There are a few forum questions on the same topic. They should get you started on the same.

https://forums.autodesk.com/t5/revit-api-forum/pickobject-from-windows-form-c/td-p/8021010

https://forums.autodesk.com/t5/revit-api-forum/revit-api-with-wpf/m-p/8209618

 

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 3 of 8

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @peerawit.ru 

To Display the Window form you have used ShowDialog(), Change ShowDialog() to Show(), Then Revit Will allow you to select the Elements.
One Important Note here
01. If you use Transactions then at Show() it will throw a Context Error. If there are no transactions you can use Show().
02. If you have transaction, You must implement the IExternalEventHandler interface and at Execute method, you have to write the Transaction.

03. And at the Form Button you have the raise the Event.

Kindly check the below links, It will help you with IExternalEventHandler Interface Implementation.
https://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html#... 

Hope this will resolve your issue 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 4 of 8

peerawit.ru
Enthusiast
Enthusiast
Thank you for your recommend.
I try to do follow this way but i found problem about Window form it allow to open another window when it open but I want to setting it can open only one.
How to solve that?

Thank a lot
0 Likes
Message 5 of 8

Mohamed_Arshad
Advisor
Advisor

HI @peerawit.ru 
You are using a Button to open another Form right? At that button event method, you have close the existing form

using this.Hide() and then you have to open another form.

arshad99_0-1682400408288.png

Hope this Helps.
If my understanding is wrong. Kindly Elaborate on your question.

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 6 of 8

peerawit.ru
Enthusiast
Enthusiast

I mean when use Form.Showdialog() it not allow to use command unless this form close.

peerawitru_0-1682404157143.png

 

But when use Form.Show() it allow to open form unlimit like this.

peerawitru_1-1682404202779.png

 

 

Can i setting for fix open just only one?

Message 7 of 8

Mohamed_Arshad
Advisor
Advisor

HI @peerawit.ru 

To Disable Revit's Tab Button, You have to Implement IExternalCommandAvailability. Kindly Follow the below steps.
01. Declare a Static Form Variable and Implement IExternalCommandAvailability Interface

arshad99_0-1682407978329.png

arshad99_1-1682408095726.png

 

02. Write a Condition to Check whether the form is opened or not in Interface Method

arshad99_2-1682408124485.png

 

03. Add the Availability Class in PushButton Data

arshad99_3-1682408172614.png

 

Hope this will helps

 


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 8 of 8

peerawit.ru
Enthusiast
Enthusiast
Hi @Mohamed_Arshad
I'm newbie for C#
I try to create dimension in Revit when i use another command after then dimension is gone
I try to follow solution in link about transaction but i don't .
Do you have a sample ?