Revit API

Reply
Distinguished Contributor
a7v1n
Posts: 216
Registered: ‎10-02-2008
Message 1 of 7 (811 Views)

pick 2 points consecutively

811 Views, 6 Replies
07-04-2011 12:12 PM

Hi,

 

i am using Visual Studio 2010 and I want to pick 2 points consecutively using Selection.Pickpoint.

The problem occurs after picking the first point, an error is thrown saying "The user aborted the pick operation." If I put MsgBox in between picking the first and second point, there are  no errors. Why is this so? Thanks!

 

 

Code:


            pt1 = uiDocument2.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader end...")
            pt2 = uiDocument2.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader elbow...")

 

If I do the next code, theres no error:


            pt1 = uiDocument2.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader end...")

            MsgBox("test")
            pt2 = uiDocument2.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader elbow...")

ADN Support Specialist
Joe.Ye
Posts: 333
Registered: ‎03-05-2010
Message 2 of 7 (796 Views)

Re: pick 2 points consecutively

07-06-2011 11:10 PM in reply to: a7v1n

I used the two lines your provided, it work well on my side. Probably you pressed ESC key, or you right click the view. You can use the try and catch to handle user's wrong interaction.

 

My First Revit plug-in handled the wrong user interaction for PickPoint , PickObject.

http://jprdintprev-wac.autodesk.com/adsk/servlet/index?siteID=123112&id=16849745&preview=1 

 

 



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Distinguished Contributor
a7v1n
Posts: 216
Registered: ‎10-02-2008
Message 3 of 7 (781 Views)

Re: pick 2 points consecutively

07-07-2011 08:03 AM in reply to: Joe.Ye

Thanks for the reply joe. Probably the difference between our codes is that I used a modeless dialog box. I show the dialog box and after clicking the image button, I closed the dialog box using dispose and immediately after that, I execute 2 pickpoints consecutively. I am able to pick 1 point but not the second point. Do you have this same problem? Thanks!

ADN Support Specialist
Joe.Ye
Posts: 333
Registered: ‎03-05-2010
Message 4 of 7 (689 Views)

Re: pick 2 points consecutively

08-01-2011 08:20 PM in reply to: a7v1n

Hi a7v1n,

 

i tried your steps, and find it is possible to pick twice consecutively.

 

here is my code.

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using  Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;

using Template2010CS;


  [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
  [RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class RevitCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {

      UIApplication app = commandData.Application;
      Document doc = app.ActiveUIDocument.Document;
      Transaction trans = new Transaction(doc, "ExComm");
      trans.Start();

      Form1 myform = new Form1();
      myform.Show();

      XYZ pt1 = app.ActiveUIDocument.Selection.PickPoint("please pick first pt");
      XYZ pt2 = app.ActiveUIDocument.Selection.PickPoint("please pick second pt");

      trans.Commit();
   
        return Result.Succeeded ;
    }
}

 

In the modless dialog , there is a button. click button to dispose the dialog.

Here is the code.

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      this.Dispose();
    }
  }

 

Run the command, click the button, i can consecutively pick twice.

 

your code maybe different with me. If this doesn't help, please let me see you code.

Good luck.



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
Valued Contributor
jta_albert
Posts: 75
Registered: ‎01-10-2006
Message 5 of 7 (616 Views)

Re: pick 2 points consecutively

09-16-2011 12:05 PM in reply to: Joe.Ye

I have this same problem using a modeless dialog. I have a section of code that is called when a button is pressed. Within that section of code I am trying to select 2 elements, but upon trying to select the second element I get the "User Aborted..." error.

 

The code in the last post does not seem to respond to a button click.

 

Have you figured this out original poster?

 

 

Valued Contributor
jta_albert
Posts: 75
Registered: ‎01-10-2006
Message 6 of 7 (614 Views)

Re: pick 2 points consecutively

09-16-2011 12:20 PM in reply to: jta_albert

I should mention that I do not want to dispose of the dialog. Rather I want to leave the dialog open and display information about the 2 elements selected.

Distinguished Contributor
a7v1n
Posts: 216
Registered: ‎10-02-2008
Message 7 of 7 (556 Views)

Re: pick 2 points consecutively

10-05-2011 03:24 PM in reply to: jta_albert

Yes I finally figured it out. You have to code your selection inside the class where you call the Form and not inside the Form. I did it that way and I didnt get errors while picking 2 points consecutively using a modal dialog.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!