WindowsForms and PickPoint

WindowsForms and PickPoint

apointeau
Participant Participant
1,051 Views
6 Replies
Message 1 of 7

WindowsForms and PickPoint

apointeau
Participant
Participant

Hi everyone!

I'm trying to create windows form to place unplaced rooms by picking a point in the interface.

So, I have to create an interface with generated button (for each rooms) to which I apply a function called place_room().

 

I want the function to:

- hide the forms

- pick a point in UI

- place the room at the point

- unhide the forms

 

I have one big problem: it seems that when the form is hidden, it's always on focus so I can't pick a point...

I'm aware of the external event to place a room with the help of Jeremy: https://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html

 

I tried the solution of Jeremy here: https://thebuildingcoder.typepad.com/blog/2015/11/pickpoint-with-wpf-and-no-threads.html But it's not working too.

My code now:

private void place_room()
        {
            this.Hide();
            var pt = uidoc.Selection.PickPoint("Merci de sélectionner un point");
            //do stuff to place the room at the selected point
            this.Show();
        }

 With this code, the form hides itself but I can't pick a point...

 

Sorry if this problem was solved somewhere in the forum but I didn't find it...

 

Have a nice day

0 Likes
1,052 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

There are various Windows API calls that you can use to set the focus back to the Revit graphics window. One example of using SetFocus is given here:

 

https://thebuildingcoder.typepad.com/blog/2016/03/implementing-the-trackchangescloud-external-event....

   

There may be other tricks that you can apply as well. Nowadays, you can use the Revit main window property instead of ComponentManager.ApplicationWindow.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 7

apointeau
Participant
Participant

Thanks for your answer!

I implemented the SetFocusToRevit() but my screen is always waiting for something and I can't select something.

apointeau_0-1646057511828.png

But when I press the Esc I have the error message that I didn't select something...

0 Likes
Message 4 of 7

EATREVITPOOPCAD
Collaborator
Collaborator

Is your form modeless? 

 

https://thebuildingcoder.typepad.com/blog/2011/09/modeless-forms-in-revit.html

 

EDIT: Nevermind... looks like it is

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes
Message 5 of 7

apointeau
Participant
Participant

Hello @jeremy_tammik and @EATREVITPOOPCAD  and thank you for your help!

 

I'm sorry I didn't come back but I found the solution!

I didn't remenber where exactly I found the solution but probably on this forum!

 

The solution :

The main class to call the forms

 

public class ManageUnplacedRooms : IExternalCommand
{

// do stuff

ManageUnPlacedRoomsForms forms = new ManageUnPlacedRoomsForms(doc, uidoc);
forms.Show();
return Result.Succeeded;

}

 

public partial class ManageUnPlacedRoomsForms : System.Windows.Forms.Form
{
        place_rooms myplace_rooms;
        ExternalEvent placeroomcommand;

        public ManageUnPlacedRoomsForms(Document document, UIDocument uidocument)
        {
            InitializeComponent();
            myplace_rooms = new place_rooms();
            placeroomcommand = ExternalEvent.Create(myplace_rooms);
            doc = document;
            uidoc = uidocument;
        }

        //do a lot a stuff

        //private void link to a button
        private void place_room(object sender, EventArgs e)
        {
            // external command?
            placeroomcommand.Raise();
        }
}

 

public class place_rooms : IExternalEventHandler
    {
        public void Execute(UIApplication a)
        {
            UIDocument uidoc = a.ActiveUIDocument;
            Document doc = uidoc.Document;
            // do stuff again

            //Start the transaction
            Transaction transaction = new Transaction(doc);
            transaction.Start("Placement temp pièce :" + nameelem);
            // ask user to pick point
            XYZ pt = uidoc.Selection.PickPoint("Position de la pièce");
            // do stuff again
            transaction.Commit();
        }
        // public string requiered for the IExternalEventHandler  I think
        public string GetName()
        {
            return "Mise en place de pièce";
        }
    }

 

I hope that help others !

Have a nice day !

Message 6 of 7

jeremy_tammik
Alumni
Alumni

Brilliant! Congratulations on solving and thank you for a very nice sample!

   

By the way, have you looked at the Revit SDK sample ModelessDialog/ModelessForm_ExternalEvent?

 

I believe it has certain similarities. Maybe it even achieves the same thing in the same way...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 7

apointeau
Participant
Participant

@jeremy_tammik Yes, exactly ! I remember looking at that ! Helps me a lot !

0 Likes