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

Using forms in your application

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
kennethgv
3149 Views, 8 Replies

Using forms in your application

Hello there.

(I am new to develop in Revit API and programming the application in C#).

 

 

I have a push button which I want to start op a form called utility_room_data. I tried following Autodesk Revit 2015 Help as close as possible, but there is no mention of how to implement forms or other addons.

 

My code is as follows in App.cs:
string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
PushButtonData buttonUtility = new PushButtonData("ButtonUtilityRoom", "Place utility room", thisAssemblyPath, "Likan_Room_Numbering.Utility_room_data");

 

My code is as follows in Utility_room_data:
namespace Likan_Room_Numbering
{
[Transaction(TransactionMode.Manual)]
public partial class Utility_room_data : Form
{
public Utility_room_data()
{
InitializeComponent();
}
}
}

 

When I push the button in Revit I get following errormessage:

Revit cannot run the external command "Place utility room". Contact the provider for assistance. Information they provided to Revit about their identity: The Building Coder, http://thebuildingcoder.typepad.com

 

I am wondering whether I am missing some standard code or some more code in App.cs when adding forms etc. or in Utility_room_data.cs for that matter?

 

Can somebody please help or navigate me in the right direction?

Help is highly appreciated! Smiley Happy

8 REPLIES 8
Message 2 of 9
kennethgv
in reply to: kennethgv

Anyone?
Message 3 of 9
kennethgv
in reply to: kennethgv

I have tried implementing the example shown in the revit api guide:
http://help.autodesk.com/view/RVT/2015/ENU/?guid=GUID-0A0D656E-5C44-49E8-A891-6C29F88E35C0

But unfortunately it does still not work. Any help?
Message 4 of 9
arnostlobel
in reply to: kennethgv

I believe that the fact you have not gotten any responses here yet is due to your case being either too trivial or too complex. For one, the code you used as an example does not look like anything that could work in Revit. I guess that what you wanted to do (and it is what I would suggest you try first when starting with the Revit API) is to have an external command that an end user could invoke from within Revit. If that is the case, you need to have a class that implements (i.e. inherits from) the IExternalCommand interface and implements its only Execute method. That class needs to have the “Transaction Mode” attribute specified. The attribute has no meaning nor effect when used with any other class. I suggest you start with one the many simple samples Revit provides in the SDK samples and documentation. There are also some very basic walkthroughs provided both in the on-line documentation as well as here in this very forum (first thread on the main page). Once you make that working successfully you would be better off to continue with some more complicated implementation.

 

In you last post you referenced a code illustrating an External Event. I am not sure that is what you need or want, but I may be wrong, for I simply have no idea what it is you are trying to achieve. At this point I would simply state that External Events is a very special framework in the Revit API that was designed to support modeless external dialogs within Revit. However, External Events need to have at least one external command or external application within which they get acquired and initialized. Again, I recommend you start with a command or application (e.g. “hello world” samples), and progress from that. One you have that nailed, I suggest you look into one of the SDK samples in the ModelessDialog folder to get more ideas.

Arnošt Löbel
Message 5 of 9
kennethgv
in reply to: arnostlobel

The simple thing I want at this time, is for a push button to trigger a "window" where I am able to implement some functionality, it might be very simple, but I can't figure it out at the moment.
I thought that I needed to make a form directly in visual studio, and not a IExternalCommand, but I will look more into that.
I actually oversaw all the great samples that followed with the SDK, thanks for the heads up.

It might be the wrong path I chosen to go, so I will change my direction and try a different approach.
Thank you for the reply. I will get back to you in a few days to accept your answer as a solution, when I have looked at it some more.
Message 6 of 9
DavidIntVeld
in reply to: kennethgv

If all you are trying to do is launch a Form inside revit and continue your code within the form you can do the following.

 

1 you need an IExternalCommand

 

2.

inside your code you simply call your form (Lets Call it frm_RoomNumber)

 

frm_RoomNumber RoomNumber = new frm_RoomNumber(commandData);

 

Then Show the form using:

 

var result = RoomNumber.ShowDialog();

if (result == DialogResult.OK)
{

   //Code after form was closed using OK

}

 

inside the code of your form:

 

   public partial class frm_RoomNumber : System.Windows.Forms.Form
    {
        ExternalCommandData commandData;

        public frm_RoomNumber(ExternalCommandData cData)
        {
            commandData = cData;

            UIApplication app = commandData.Application;
            UIDocument uidoc = app.ActiveUIDocument;
            Document doc = uidoc.Document;

            //CodeStuff
            
            InitializeComponent();

          }
}

 

now you can continue your API program filtering etc within your Form...

 

Hope this helps

 

 

Message 7 of 9
kennethgv
in reply to: DavidIntVeld

Thank you so much for your reply. That is almost exactly what I'm trying to do.


At the moment I use the premade Revit 2014 Addin, when I create a new project.
This automatically creates an app.cs and a command.cs file. I have added a form to the project and implemented the code you typed in command.cs and the form.


What I simply want to do is when a button in the ribbon panel is pressed, it should start a form.
I'm in doubt how I will get the form running, while using this code in app.cs:

 

// Create a push button to trigger opening the form "Utility room data"
string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
PushButtonData buttonUtility = new PushButtonData("ButtonUtilityRoom", "Place utility room", thisAssemblyPath, "Likan_Room_Numbering.Utility_room_data");

// Add push button to Ribbon panel
PushButton pushButton = ribbonPanel.AddItem(buttonUtility) as PushButton;

 

I figure this is probably the wrong way to do it, but I'm just trying to follow the help documentation guide .

Does this make any sense, and can you guide me in the right direction?

 

I might not be the strongest C# programmer yet, but I'm really trying!

Message 8 of 9
kennethgv
in reply to: DavidIntVeld

With the code you supported, I found the last error in my code. It is now functioning

I switched

PushButtonData buttonUtility = new PushButtonData("ButtonUtilityRoom", "Place utility room", thisAssemblyPath, "Likan_Room_Numbering.Utility_room_data");

with 

PushButtonData buttonUtility = new PushButtonData("ButtonUtilityRoom", "Place utility room", thisAssemblyPath, "Likan_Room_Numbering.Command");

 

Thank you very much your help. Highly appreciated.

Message 9 of 9
DavidIntVeld
in reply to: kennethgv

I dont know what pre-made app you are using, but giving the names of the file 

the app.cs is the 

 

The app.cs is the

Autodesk.Revit.UI.IExternalApplication

and to this class your .addin file will reference

it will be executed when Revit is launched.

 

the IExternalApplication creates the application button and when you click it will

start the IExternalCommand in your command.cs

 

It is here in the command.cs where you can load your form

 

in the bit between:

 

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class SelectOnLevel : IExternalCommand
{

public Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{

    //you code here

 

 

 

                return Result.Succeeded;

 

}

}

 

Try follwing the Hello world example, 

that should make it all clear

 

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community