.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with automatically loading a .cui(x) file on startup

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
1130 Views, 3 Replies

Help with automatically loading a .cui(x) file on startup

Hi all,

I am trying to get a menu file to load automatically on application startup with AutoCAD 2010. I have tried 3 different ways of doing this and run into 3 different problems.

The first way is with the following code, and this works fine when loading the module via netload, but I need to have the module loaded automatically when AutoCAD starts, and the call to SendStringToExecute fails because the Application.DocumentManager.MdiActiveDocument is not yet available:

//disable dialogs
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("filedia 0 ", false, false, true);
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiload " + fileNameWithQuotes + "\n", false, false, true);
//enable dialogs
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("filedia 1 ", false, false, true);

The second way is with the following code, which works with both netload and when the module is loaded when AutoCAD starts, but the last call to ads_queueexpr to re-enable the file dialogs is not working, so after the code is run the user has to manually type "filedia 1" to re-enable the dialogs:

ads_queueexpr(unicodeEncoding.GetBytes("(setvar \"FILEDIA\" 0)"));
String fileNameWithQuotes = "\"" + fileName + "\"";
ads_queueexpr(unicodeEncoding.GetBytes("(Command \"_.CUILOAD\")"));
ads_queueexpr(unicodeEncoding.GetBytes(fileNameWithQuotes));
ads_queueexpr(unicodeEncoding.GetBytes("(setvar \"FILEDIA\" 1)"));

The third way is with the following code, which I based on the following sample: http://adn.autodesk.com/adn/servlet/item?siteID=4814862&id=13109407&linkID=4900509 This code doesn't work at all, with netload or when loading on startup, and in fact is crashing AutoCAD:

//disable dialogs
resultBuffer = new ResultBuffer();
resultBuffer.Add(new TypedValue(5005, "FILEDIA"));
resultBuffer.Add(new TypedValue(5005, "0"));
acedCmd(resultBuffer.UnmanagedObject);

String fileNameWithQuotes = "\"" + fileName + "\"";
resultBuffer = new ResultBuffer();
resultBuffer.Add(new TypedValue(5005, "_CUILOAD"));
resultBuffer.Add(new TypedValue(5005, fileNameWithQuotes));
acedCmd(resultBuffer.UnmanagedObject);

//enable dialogs
resultBuffer = new ResultBuffer();
resultBuffer.Add(new TypedValue(5005, "FILEDIA"));
resultBuffer.Add(new TypedValue(5005, "1"));
acedCmd(resultBuffer.UnmanagedObject);

Any help would be greatly appreciated.
Thanks in advance.
3 REPLIES 3
Message 2 of 4
cadMeUp
in reply to: Anonymous

Maybe you can try this, hopefully it will work for you, I've got this for AutoCAD 2010:
{code}
using System;
using System.Collections;
using System.Collections.Generic;

// AutoCAD Specific
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
//using Autodesk.AutoCAD.Customization; // Reference to AcCui.dll in 'inc-win32' or 'inc-x64'

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: ExtensionApplication(typeof(_Master.ExtApp))]

namespace _Master
{
public class ExtApp : IExtensionApplication
{
public ExtApp()
{
}

public void Initialize()
{
string cuiFileName = @"C:\tester.cuix";
AcadApplication acadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
acadApp.MenuGroups.Load(cuiFileName, null);

//From reference to AcCui.dll
//CustomizationSection sec = new CustomizationSection(@"C:\tester.cuix");
}

public void Terminate()
{
}
}
}
{code}
Message 3 of 4
cadMeUp
in reply to: Anonymous

Sorry I hit the post message button prematurely.

I also wanted to say, I tried adding a reference to the Autodesk.AutoCAD.Customization and use some objects in there but can't find a method in there right now that will load a .cuix file. There are alot of useful objects within the Autodesk.AutoCAD.Customization namespace though.

This line will open a .cuix file but not load it, just loads into the object:
CustomizationSection sec = new CustomizationSection(@"C:\tester.cuix");
Message 4 of 4
Kevin.Bell
in reply to: Anonymous

cadmeup - did you get this to work??

I'm trying to load my custom ribbon tab from my CUIx file, but am surprised that it cannot be done with LISP...

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


Autodesk Design & Make Report

”Boost