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: 

How to do a simple login form in a Command

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Supamiu
958 Views, 5 Replies

How to do a simple login form in a Command

Hello,

 

Since some days I try to start my plugin's dev with some tests (i will need database connection etc, all of that is done). But the fact is that i'm pretty new to C# and xaml, so i created a xaml template using Visual Express 2013, here it is :

 

<UserControl x:Class="UserConnect.UILogin"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
             mc:Ignorable="d"  
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid HorizontalAlignment="Left" Height="149" Margin="51,72,0,0" VerticalAlignment="Top" Width="200">
            <PasswordBox HorizontalAlignment="Left" Margin="31,61,0,0" VerticalAlignment="Top" Width="140"/>
            <TextBox HorizontalAlignment="Left" Height="23" Margin="31,22,0,0" TextWrapping="Wrap" Text="Username" VerticalAlignment="Top" Width="140"/>
            <Button Content="Button" HorizontalAlignment="Left" Margin="61,86,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
        </Grid>
 
    </Grid>
</UserControl>

 

And a little class file, to start my UI :

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
 
namespace UserConnect
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UILogin dialog = new UILogin();
            return Result.Succeeded;
        }
 
 
        public Result OnShutdown(UIControlledApplication application)
        {
            throw new NotImplementedException();
        }
 
        public Result OnStartup(UIControlledApplication application)
        {
            UILogin dialog = new UILogin();
            return Result.Succeeded;
        }
    }
}

 

The problem is that i can perfectly load the class in my add-ins menu, but nothing happens, not even an error message, so i don't know why it doesn't works, and i can't find the solution.


Thanks for your help.

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: Supamiu

Dear Supamiu,

 

Please work through the Revit API getting started material, especially the 'My first Revit plugin' and DevTV tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Good luck and have fun!

 

Best regards,

 

Jeremy



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

Message 3 of 6
DavidVeld
in reply to: Supamiu

Just a quick look but I believe a user control should be embedded inside a

winform or WPF, I dont believe it is possible to just show it like that. 

 

Then you can show your winform easilly

 

 

MyWinform myWinform = new MyWinForm();

myWinform.ShowDialog();

 

There should be your usercontrol inside...

 

 

Message 4 of 6
Supamiu
in reply to: jeremytammik

Thx for your answers I'm going to try it today and give some feedback.@ I've done the "my first plugin" tutorial and watched 2 videos of DevTV, but i found nothing in those tutorials that could help me to create just a simple Xaml and show it in my addin.

Message 5 of 6
jeremytammik
in reply to: Supamiu

Too true, no XAML in there, just Windows Forms, indeed.

 

Thanks to David for the better explanation!

 

The Building Coder and one or two SDK samples do include XAML forms, though...

 

Cheers,

 

Jeremy



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

Message 6 of 6
arnostlobel
in reply to: jeremytammik

Admittedly, I have no experience with XAML forms, for I try avoiding to work with UI as much as I can. However, looking at the posted code, it strikes me as surprising that by merely constructing a form one should expect it to show up. I would definitely assume some form of a Show method needing to be invoked on the object in order to get it displayed.
 
As for the whole example itself, it does not exactly follow the SDK samples or the my-first-addin tutorial to the point. For one, the IExternalCommand interface does not have OnStartup and OnShutdown methods to implement, thus adding them to an External Command class serves no purpose; Revit will not invoke them. Furthermore, I do not recall seeing in any of the SDK samples having the OnStartup or OnShutdown implemented so they throw a NotImplementedException. In fact, the Revit API would be rather surprised by that exception and would report in the journal such an external application as misbehaving.

Arnošt Löbel

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