Combobox connection

Combobox connection

vjaqpf
Contributor Contributor
2,964 Views
17 Replies
Message 1 of 18

Combobox connection

vjaqpf
Contributor
Contributor

I am executing the AdnRevitApiLabsXtra de Jeremy and I have understood the connections to public class DBElement: IExternalCommand but the one corresponding to the Combobox only goes as far as announcing the selected item and I have not been able to give the instruction so that the DB Element is also executed. If anyone can tell me how to fix this case, I would greatly appreciate it.

 
 

 

 

 

 

 

0 Likes
Accepted solutions (1)
2,965 Views
17 Replies
Replies (17)
Message 2 of 18

jeremytammik
Autodesk
Autodesk

I have no idea how a 'DB Element can be executed'.

 

Do you mean to kill it?

 

You can do so by calling Delete.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 18

vjaqpf
Contributor
Contributor

Plop !! I don't to kill it. On the contrary, I want to know how I can connect to following instructions to perform actions in Revit, something that allows me to do things similar to the other options that are implemented in the example, in the image that I attached. Thank you.

0 Likes
Message 4 of 18

vjaqpf
Contributor
Contributor

Thank you for your answers. Through this forum I came to find the application that I mentioned and that I have studied in detail (AdnRevitApiLabsXtra-master.zip). My problem is that I have not been able to create the statement that responds to the option selected in the ComboBox. In such application the other buttons are still in public class DBElement: IExternalCommand ... I have not been able to make that connection.

vjaqpf_0-1602791187165.png

 

0 Likes
Message 5 of 18

jeremy_tammik
Alumni
Alumni

Taking another look at the image that you attached, I see that all of the connections you mention are simply the links between a Revit API ribbon button and the external command that is launched by clicking it.

 

In the Revit UI API, every ribbon button that you create is linked to an external command.

 

You are asking how that link is defined.

 

All of the links in your image are defined in the module 1_Ribbon.cs:

 

https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/2_Revit_UI_API/SourceCS/1_Ribbon.cs

  

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

vjaqpf
Contributor
Contributor
Jeremy, good morning. Thank you for your response and for your time.
Everything it tells me is true, what's more, the images I attached were
taken precisely from 1_Ribbon.cs
The fact is that when an item is selected from the ComboBox the connection
is only up to the message: "Your selection was ...." and not to the
executable in Revit "DB Element" and this is what I have not been able to
connect.
In the annex, I include sections of my project where I have done many tests
and I have not been able to connect a ComboBox item to an executable in
Revit. In this document I detail the steps.
Thanks again for your attention.
0 Likes
Message 7 of 18

vjaqpf
Contributor
Contributor

Annex the announced document.

0 Likes
Message 8 of 18

vjaqpf
Contributor
Contributor

I don't know if the advertised attachment was sent ... which is why I am attaching it again. Thanks.

0 Likes
Message 9 of 18

RPTHOMAS108
Mentor
Mentor

With ComboBoxes you can subscribe to ComboBox.CurrentChanged the event args of this give you:

Application (UIApplication) and NewValue(ComboBoxMember).

 

The signature for IExternalCommand.Execute is (CommandData, String, ElementSet)

 

You get UIApplication from CommandData.Application.

 

So from this you see that if you have a method with signature  (UIApplication) you can call it from both the event handler of ComboBox.CurrentChanged and IExternalCommand.Execute. I think in general I don't use the ComboBox this way as I don't see it as being that same as using IExternalCommand or ExternalEvent (that might be just me). You get similar event handling for 'TextBox'. ComboBox and TextBox are the only controls in the API that act with event handlers similar to stand alone applications.

0 Likes
Message 10 of 18

vjaqpf
Contributor
Contributor

Thanks for your reply.

Could you attach an example of how to connect an item from the CurrentChanged to an external command or to an existing method in the Application?

0 Likes
Message 11 of 18

jeremy_tammik
Alumni
Alumni

Why would you want CurrentChanged to trigger an external command?

 

Then, each time the user moves up and down in the menu, a new command is launched.

 

I do not think that would please your user.

 

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

RPTHOMAS108
Mentor
Mentor

Hello Jeremy

 

I believe the event is only executed if the ComboBox is closed and the item selected is not the same as it was when the box was opened. Means though that in order to do nothing upon closing the box you have to either pick the same item or press escape.

 

There is no real guidance in terms of document/application state during these events so I tend to avoid them in general i.e. there is no transaction mode as exists with IExternalCommand so don't know if state is ReadOnly or Manual (I assume it is Manual).

 

 Public Sub HandleComboBoxChanged(s As Object, e As Autodesk.Revit.UI.Events.ComboBoxCurrentChangedEventArgs)

        If e.NewValue Is Nothing Then
        Else
            Select Case e.NewValue.Name
                Case = "TestA"
                    RunMethod_A(e.Application)
                Case = "TestB"
                    RunMethod_B(e.Application)
                Case Else

            End Select

        End If
    End Sub
    Public Sub RunMethod_A(UIApp As UIApplication)
        'We could have also reached this point from within Execute method of ExternalApplication
        TaskDialog.Show("A", "Now we can Do something A related With method With UIApp")
    End Sub
    Public Sub RunMethod_B(UIApp As UIApplication)
        'We could have also reached this point from within Execute method of ExternalApplication
        TaskDialog.Show("B", "Now we can Do something B related With method With UIApp")
    End Sub

 

 

 

 

 

0 Likes
Message 13 of 18

vjaqpf
Contributor
Contributor

It seems that I do not explain my problem well. I have not been able to connect an item from a combobox with the code that must perform some operation in revit. I have tried actions in App.cs and Command.cs and it doesn't work for me. More specifically, in the example 1_Ribbon.cs, how and where is the instruction to connect to "DB Element" written from any item in the ComboBox? and the executable code in revit where should it be?

0 Likes
Message 14 of 18

vjaqpf
Contributor
Contributor
Thomas, good morning. Thank you for your interest in helping me.
I understand your observation of the first 2 paragraphs. It is a problem with the ComboBox, in several languages: a selected item cannot be used again immediately, unless its value is set to Null. I have solved that, putting an item that does nothing to then be able to repeat the same item immediately. For this reason I like to use the SplitButton better.

As for your example, it will surely work but I am in the same situation because I understand that it is written in VB.net and my problem is in C#. Could you do it in this language? Thanks.
0 Likes
Message 15 of 18

RPTHOMAS108
Mentor
Mentor
Accepted solution

 

public void HandleComboBoxChanged(object s, Autodesk.Revit.UI.Events.ComboBoxCurrentChangedEventArgs e)
	{
		
		if (e.NewValue == null) {
		} else {
			switch (e.NewValue.Name) {
				case "TestA":
					RunMethod_A(e.Application);
					break;
				case "TestB":
					RunMethod_B(e.Application);
					break;
				default:

					break;
			}

		}
	}
	public void RunMethod_A(UIApplication UIApp)
	{
		//We could have also reached this point from within Execute method of ExternalApplication
		TaskDialog.Show("A", "Now we can Do something A related With method With UIApp");
	}
	public void RunMethod_B(UIApplication UIApp)
	{
		//We could have also reached this point from within Execute method of ExternalApplication
		TaskDialog.Show("B", "Now we can Do something B related With method With UIApp");
	}

 

0 Likes
Message 16 of 18

vjaqpf
Contributor
Contributor
Very good RPThomas, with your example I deducted 2 points:
1. I had 2 errors in my application: sending parameters and the scope of the executable (I had it as private void ...)
2. The code in C# is almost identical to that of VB.net ... which language is best for you ?
Thank you very much for your effective help and for your time.
0 Likes
Message 17 of 18

RPTHOMAS108
Mentor
Mentor

It is a very personal thing but I prefer VB. The languages are very similar but the IDE support for VB appears better. VB is more verbose but C# seems to make up for that with empty space (page heights seem longer with C#).

 

If I take out type safety I can get a character count which is only slightly more than equivalent Python code. Although gap would increase with overall code length.

 

Type:

Public Class XX

Implements  IExternalCommand + Return (and the rest is autocomplete).

 

Type:

public class xx : IExternalCommand + Return (then I get an error / question asking me what to do next)

 

I don't know if there is an option for that in C# i.e. a 'do the obvious thing next for me' option? I probably don't use it long enough to find out.

 

I think the IDE for VB is getting worse though due to shared components. I'm sure intellisense used to ignore case but someone has made it so you must practically type the case correctly to get what you are looking for faster. Case sensitivity is a C# thing but even in C# it makes no sense to compare by case in a suggestions list when the autocorrect will eventually change to what is selected anyway. Some C# puritan has tinkered with that and not seen the bigger picture.

 

However C# always appears to have less future uncertainty. We should all go back to C++ really, the original option for cross platform support. 

Message 18 of 18

vjaqpf
Contributor
Contributor
OK, RPThomas. I got started in C # because my colleague, an expert in
Revit, suggested it to me so that I could support him in his projects.
However if I had known a little more about VB.net at that time, maybe I
would have preferred it, because I have quite a lot of experience with VBA.
C# has made me gray! In short, new languages appear and it will be
necessary to choose a line and not stumble between one and the other. Thank
you very much again. I am Víctor J. Alvarez, Geographical Engineer, from
Colombia.
0 Likes