loop in revit program

loop in revit program

Anonymous
Not applicable
1,424 Views
10 Replies
Message 1 of 11

loop in revit program

Anonymous
Not applicable
Hi, i am trying to run an api program written C#. How can i get it to keep running continously. For example, to perform an operation every 10milliseconds. Is there a command for this?
0 Likes
1,425 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
They have you pushing the envelop don't they... To run a program on a timer, you can: open a form that never closes, and uses its own 'on timer' event. Or spin off a thread that runs it's own on timer. The product of what happens on that timer will determine your biggest problem. Are you accessing the Revit database on that timer? Does the timer stop to allow the user/program to do other things, or is it running the entire time expecting the user to work simultaneously? Most external commands expect the control to return to Revit when it's DONE running, but if your not going to finish, then control is never returned, hince the reason for a separate thread, or form that never closes.

jvj
0 Likes
Message 3 of 11

Anonymous
Not applicable
Jamie, Yes i am accessing the Revit database and i want my program to keep running continiously. Can you give an example of what you wrote earlier? Thanks
0 Likes
Message 4 of 11

Anonymous
Not applicable
Because of the complexity your about to approach, strap in and hang on. What is the tool supposed to do every 10 seconds, that's hardly long enough to let the machine process a single command? First lets use the easier method, and just create a form that does NOT open modal, just use form.show (not form.showDialog). Then the external command can quit, return succeeded. This form should stay open until the user closes it.
To get the timer you need to go to the VisualStudio Toolbox, Components group, and drag the timmer onto the form (it hides at the bottom of the screen). Set the interval on the timmer (in millisecons) in its properties. Then place your event code on the form. (I'm a vb Programmer so bear with me)

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

End Sub
After you open the form, the timmer will continue to tick away until you close the form, or write code to bypass the timmer tick procedure like
If runTimmer Then
'do something
End If
As such you can but a button on the form that affects the runTimmer boolean so that the tick will do something or not.

jvj

0 Likes
Message 5 of 11

Anonymous
Not applicable
Thanks Jamie, but the revit application uses a class and not a windows form application. I cannot even access the toolbox and properties window. So how do i do this?
0 Likes
Message 6 of 11

Anonymous
Not applicable
When you are working in a Visual Studio, or even VSTA project, you can right click on the project, or solution, and select Add Windows Form. That form will become part of your custom dll when you build.

jvj
0 Likes
Message 7 of 11

Anonymous
Not applicable
Hello Jamie, I am a little lost. Pls, find attached my code. Can you help me out? Thanks alot. (You can create your own database and change the path to the database).
0 Likes
Message 8 of 11

Anonymous
Not applicable
Hello,
1. In VisualStudio when writing to RevitAPI.dll, there are differences than VSTA. Document.get_element is now Document.Element; and same with parameter. You don't really have to get the parameter to set it in two lines. You can say element.parameter(name).set(value)
2. No clue what your multitable variable is, so I'll assume that's not the problem here.
3. It would be a VERY good idea to confirm that the variable myElement is valid after getting it. If myElement isnot nothing then get to work. You very well my have element id's that are not in the drawing.
4. IF your database stores information, then you close the project, then you open the project and expect those ids to be the same, your in for a world of hurt. The only value that is the same is element.UniqueID (which is a guid object type). Currently finding an object by it's uniqueID is a bit different. myElement = Document.Element(guid.tostring)
That all I got.
jvj
0 Likes
Message 9 of 11

Anonymous
Not applicable
Oh you got me wrong. The program actually works and runs fine. All i want you to do is to help me place it in a loop so that it keeps looking into the database and getting values to set. That is, i want it to keep running continiously.
I could not follow the procedure you gave me. Pls help.
0 Likes
Message 10 of 11

Anonymous
Not applicable
Ok It appears you are using VSTA. So you need to right click on the project name in the Project Explorer Window and select Add, Windows Form... Then it will create a form that consists of 3 files. A form.vb, a form.designer.vb, and a form.resex file. That is where you will setup your timer. The code for my form.vb and form.designer.vb are attached in this text file.
jvj
0 Likes
Message 11 of 11

Anonymous
Not applicable
Thanks alot. I finally had it work. I am actually new to C#. I also have another question: How can i change the colors of elements and have them display on the interface. E.g. making a door change to red or blue to display its status. Does revit have that functionality? If this is not possible, is it possible to use "transparency"?
0 Likes