Community
Navisworks API
Welcome to Autodesk’s Navisworks API Forums. Share your knowledge, ask questions, and explore popular Navisworks API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C# - Automatically updating a textbox when measurement command is used

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1858 Views, 4 Replies

C# - Automatically updating a textbox when measurement command is used

I apologize in advance for this being a kinda vague and/or simple question. This is using C#.

 

My plugin creates a dockable pane with textboxes in it. As the user uses the measurement tool I want my textboxes to update with the data obtained from CurrentMeasurement.FirstPoint and CurrentMeasurement.EndPoint. I'm able to populate my textboxes with this data manually by running the plugin each time.. but that is extremely inefficient.

 

I want the textboxes to update automatically at the same time the Measurement Tools window pane updates (the one that comes with Navis). How do I do this? If anybody can provide the name of the command I should be using that'd be great, and if somebody has a code example that'd be 100x more awesome.

 

The only thing I can relate this to is creating a LocationListener when I'm making an android app in Java. It watches a button for user interaction and executes specific commands once that button is pressed.

 

I just started teaching myself (with many many many many thanks to Xiaodong Liang for the info on his AEC DevBlog and his posts here!) C# for the sole purpose of making some plugins for work.. it's quite a bit different than what I'm used to!

 

Thank you in advance.

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

So it looks like I need to use an EventHandler... and the API has a few built in but I can't find one that would do exactly what I'm looking for, nor do I have any idea how to make it actually work. I've written the code error free a number of times but the event never fires so there is something I'm doing wrong (or maybe I have working code that does nothing).. but I've tried with ActiveSheetChanged/Changing and MainDocumentChanged/Changing.

Message 3 of 5
Anonymous
in reply to: Anonymous

Well I got it to work using:

 

Autodesk.Navisworks.Api.Application.Idle += GenerateNewPoints;

void GenerateNewPoints(object sender, System.EventArgs e)
{
getPoints();
MyDockPane.control.textBox1.Text = newPos;
}

I'm going to add in something that does a check to see if the CurrentMeasurement.FirstPoint has been changed before running getPoints and updating the panel... but there has to be a better event handler to use than Application.Idle, isn't there?

 

I can't find any that do anything when I use the point-to-point measurement tool.

 

Message 4 of 5
xiaodong_liang
in reply to: Anonymous

Hi Ixath,


This is an interesting question. I do not either find an event. In theory, it is best to provide an event for DocumentCurrentMeasurement. I have not a better idea than you have tried. I can log a wish.

 

There is a possibility we would provide MouseEvent in release 2014. Probably you could implement your own measure workflow.

Message 5 of 5
Anonymous
in reply to: xiaodong_liang

It would be great if there was an event for the mouseclick.

 

I've tried using some tutorials online to set up my own event for (CM) Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentMeasurement and have no clue what to do to make it work. I've given up on it until I get a bit smater.

 

I've also unsuccessfully (due to my coding ability) tried using INotifyPropertyChanged to watch a variable (Point3D curFirstPoint = CM.FirstPoint) for a change, and executing the code when it changes. If anybody has any advice on how I'd set something like this up I would be greatful.

 

If anybody has a better way of writing this please let me know, but this is what I could come up with:

public Boolean timer_WaitPeriod = false;

StartTimer();
Autodesk.Navisworks.Api.Application.Idle += GenerateNewPoints;

public void StartTimer()
{
   public Timer timer_NewPoints = new Timer();
   timer_NewPoints.Interval = 150;
   timer_NewPoints.Enabled = true;
   timer_NewPoints.Start();
   timer_NewPoints.Tick += ResetTimer;
}

public void ResetTimer(object sender, EventArgs e)
{
   timer_WaitPeriod = false;
}

public void GenerateNewPoints(object sender, System.EventArgs e)
{
   if (timer_WaitPeriod == false)
   {
      ..code to process the points goes here...
   }

   timer_WaitPeriod = true;
}

 Application.Idle fires off constantly so I tried to slow it down a bit. I'm not sure if this was necessary or not. I'm also never issuing -= GenerateNewPoints; or -=ResetTimer. Do I need to? I thought about removing Application.Idle alltogether and having the timer run GenerateNewPoints every .15 seconds, but I imagine it would cause problems if Navis was in the middle of loading a new file or something.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report