Here is a complete cs file, using mostly your code, modified so it works without error. Note, you need to change the CopyLocal property of the Autodesk References to False. I also removed the Session flag from the IFC command.
using System;
using System.Windows.Controls;
using System.Windows.Input;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Private.Windows;
using Autodesk.Windows;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Microsoft.Win32;
namespace IfcC3DAddIn.main
{
public class C3DIfcAlignmentAddIn
{
//added this command
[CommandMethod("IFCImportTest")]
public void ifcimporttest()
{
//Read my IFC File...
var dlg = new OpenFileDialog();
var result = dlg.ShowDialog();
var ifcFile = dlg.FileName;
if (result == true)
{
//Start Import:
var civilDatabase = Application.DocumentManager.MdiActiveDocument.Database;
var civilDocument = CivilApplication.ActiveDocument;
//Create C3D Alignment:
var civilAlignment = Alignment.Create(civilDocument, "My Name (1)", "", "C-ROAD", "Proposed", "All Labels");
}
}
[CommandMethod("ifc")]
public void Main()
{
var ribbon = ComponentManager.Ribbon; //Get C3D UI-Information
var btab = ribbon.FindTab("CIVIL.ID_Civil3DAddins"); //Find the correct Ribbon
//------------------ Check if the Panel already exists ------------------------
if (btab != null)
{
if (btab.Panels != null)
{
foreach (var panel in btab.Panels)
{
if (panel.UID == "UID_IfcPanel") //if the Panel already exists...
{
var removePnl = panel;
btab.Panels.Remove(removePnl); //...delete the Panel
break;
}
}
}
}
//-------------------------------------------------------------------------------
//------------------------ Create the new Button ------------------------------
var civilPanel = new RibbonPanel
{
UID = "UID_IfcPanel",
Id = "ID_IfcPanel"
};
var source = new RibbonPanelSource
{
Id = "ID_IfcPanelSource",
Name = "IfcPanelSource",
Title = "IFC Alignment v1.1"
}; //Create Panel Source
civilPanel.Source = source; //... and bind it to the Panel
var rbb1 = new RibbonButton
{
Name = "Export Ifc...",
Text = "Ifc Export",
GroupLocation = RibbonItemGroupLocation.Single,
ResizeStyle = RibbonItemResizeStyles.HideText,
Orientation = Orientation.Horizontal,
ShowText = false,
//CommandHandler = new ExportCmdHandler(),
Id = "ID_TestButton",
ShowImage = true,
Size = RibbonItemSize.Large
}; //Create Ribbon Button 1
var rbn1Tt = new RibbonToolTip
{
Command = "IFC",
Title = "Ifc-Export",
Content = "This Add-in let's you export your current .dwg-file to an IFC 4 (.ifc) File.",
ExpandedContent = "In the dialog box, navigate to the file directory you want to save your file."
}; //Create Tooltip
rbb1.ToolTip = rbn1Tt;
var rbb2 = new RibbonButton
{
Name = "Import Ifc...",
Text = "Ifc Import",
GroupLocation = RibbonItemGroupLocation.Single,
ResizeStyle = RibbonItemResizeStyles.HideText,
Orientation = Orientation.Horizontal,
ShowText = false,
Id = "ID_TestButton",
ShowImage = true,
CommandHandler = new ImportCmdHandler(),
Size = RibbonItemSize.Large,
CommandParameter="_.IFCImportTest " //<<<<<<<<<<added this line
}; //Create Ribbon Button 2
//rbb2.CommandHandler = new MyCmdHandler();
//Get Button Image
var rbn2Tt = new RibbonToolTip
{
Command = "IFC",
Title = "Ifc-Import",
Content = "This Add-in let's you import a IFC 4 (.ifc) File to your current drawing.",
ExpandedContent = "In the dialog box, navigate to the file directory your IFC-File ist stored."
}; //Create Tooltip
rbb2.ToolTip = rbn2Tt;
var rbSplitButton = new RibbonSplitButton
{
Text = "Ifc Add-in",
ShowText = true,
Size = RibbonItemSize.Large,
//LargeImage = GetBitmap("ifclogo.png"),
//ShowImage = true,
Name = "Ifc Add-in"
}; //Create new Split-Button
rbSplitButton.Items.Add(rbb1); //Add Button 1 to the Split-Button
rbSplitButton.Items.Add(rbb2); //Add Button 2 to the Split-Button
if (btab != null)
{
if (btab.Panels != null) btab.Panels.Add(civilPanel); //Add Panel to the Add-ins Tab
btab.IsActive = true; //...and set as active
}
source.Items.Add(rbSplitButton); //Add Split-Button to the Panel
}
public class ImportCmdHandler : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (parameter is RibbonButton) //if Button is clicked...
{
//removed the original code, added the following:
string esc = "";
string cmds = (string)Application.GetSystemVariable("CMDNAMES");
if (cmds.Length > 0)
{
int cmdNum = cmds.Split(new char[] { '\'' }).Length;
for (int i = 0; i < cmdNum; i++)
esc += '\x03';
}
string cmdString = parameter.GetType().GetProperty("CommandParameter").GetValue(parameter, null) as string;
if (!String.IsNullOrEmpty(cmdString))
Application.DocumentManager.MdiActiveDocument.SendStringToExecute(esc + cmdString, true, false, true);
//end of added code
}
}
}
}
}