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

Install toolbar CUI.NET API

12 REPLIES 12
Reply
Message 1 of 13
jgarciaanton
1336 Views, 12 Replies

Install toolbar CUI.NET API

Hi,

I am trying to add a new toolbar to Acad 2007 from a windows installation
package using the CUI .NET API. The idea is to execute it from a custom action.

By modifying the C# code in the documentation I have the following code,

Sub Main()

Dim csstring As String = "C:\Documents and Settings\UserX\Application Data\Autodesk\AutoCAD 2007\R17.0\enu\Support\acad.cui"

Dim cs As CustomizationSection
cs = New CustomizationSection(csstring)

Dim newTB As Toolbar = New Toolbar("MyToolbar", cs.MenuGroup)
newTB.ToolbarOrient = ToolbarOrient.floating
newTB.ToolbarVisible = ToolbarVisible.show


Dim tbBtn As ToolbarButton = New ToolbarButton(newTB, -1)
tbBtn.Name = "Pline"
tbBtn.MacroID = "ID_Pline"

For Each wk As Workspace In cs.Workspaces
Dim wkTb As WorkspaceToolbar = New WorkspaceToolbar(wk, newTB)
wk.WorkspaceToolbars.Add(wkTb)
wkTb.Display = 1
Next

cs.Save()

End Sub


But I get the following error on the cs = New CustomizationSection(csstring) line.

System.IO.FileNotFoundException was unhandled
Message="The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Source="AcCustomize"

If I put the code into a command, NETLOAD the dll, and instead of
hardcoding the location of the acad.cui file I obtain it with the
application variable Application.GetSystemVariable("MENUNAME"),
the code works fine. But as the documentation says, the application
variable is not available to Stand-alone Applications, so I need to
get it to work with a hardcoded string.

The application MENUNAME variable returns EXACTLY the same value that I provide
in the hardcoded path (minus .cui), and I have also tried to use double
backslash in the path or move the file to c:\acad.cui but I still
get the same error.

Has anyone had the same problem or have any ideas on how to solve it ?


Thanks in advance

Julian
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: jgarciaanton

Are you sure that it is allowed to call AutoCAD .NET assembly from standalong application? IMHO it is impossible. Exception not pointed to path (string csstring) but to AcCustomize.dll which is not found. It is needed for CustomizationSection class. Message="The specified module could not be found" - describe this situation.

Oops! Sorry! I was wrong! It is possible! Copy your's application in AutoCAD directory and start it. I think problem that your's application can not found some of assembly/module those are in AutoCAD directory.

Another way is coping next files from AutoCAD directory to application directory:
[code]
ac1st17.dll
AcCui.dll
AcCustomize.dll
acdb17.dll
acdb17enures.dll
acdbmgd.dll
acge17.dll
acmgd.dll
AcMNUParser.dll
[/code]

Best Regards,
Alexander Rivilis.
Message 3 of 13
Anonymous
in reply to: jgarciaanton

Alex - The CUI interface is an exception.

It has no dependence on AutoCAD and was designed
that way so that it could be use for installation.

Unfortunately they left out a few key pieces, related
more to general information, such as what CUI files
are loaded into a given installation.

So, it must be done manually (look in registry for the
name of the main and enterprise menus, and then
use the AutoCAD library search path to find them).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5310255@discussion.autodesk.com...
Are you sure that it is allowed to call AutoCAD .NET assembly from standalong application? IMHO it is impossible. Exception not pointed to path (string csstring) but to AcCustomize.dll which is not found. It is needed for CustomizationSection class. Message="The specified module could not be found" - describe this situation.
Message 4 of 13
Anonymous
in reply to: jgarciaanton

Hi, Tony Tanzillo!
Many thanks for explanation!

I have a little question. Is it possible to load (LoadLibrary or any other way) all needed
dll-files in order to not copy its in directory of application?

Best Regards,
Alexander Rivilis.
Message 5 of 13
Anonymous
in reply to: jgarciaanton

Hi Alex.

Sorry, I'm not sure I understand the question.

(You can use Assembly.Load() to load a managed assembly)

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Alexander Rivilis" wrote in message news:5310540@discussion.autodesk.com...
Hi, Tony Tanzillo!
Many thanks for explanation!

I have a little question. Is it possible to load (LoadLibrary or any other way) all needed
dll-files in order to not copy its in directory of application?

Best Regards,
Alexander Rivilis.
Message 6 of 13
Anonymous
in reply to: jgarciaanton

Hi Tony!
Yes! You undestand me! 🙂 For Assembly I can Assembly.Load() but ac1st17.dll acdb17.dll acdb17enures.dll acge17.dll not Assembly. 😞 Is it possible to load ordinary dll-file? With P/Invoke LoadLibrary? Is it enough in order to application look for those dll-files in current directory?

Message was edited by: Alexander Rivilis
Message 7 of 13
Anonymous
in reply to: jgarciaanton

Ok! I've found solution:
[code]
'Declaration:
_
Private Shared Function SetDllDirectoryA(ByVal path As String) As Integer
End Function
'Using sample:
SetDllDirectoryA("C:\Program Files\AutoCAD 2007") ' Now Application looking for ordinary dll-files in AutoCAD directory.
[/code]
AcCui.dll, AcCustomize.dl,l acdbmgd.dll, acmgd.dll, AcMNUParser.dll have to be in
directory of application or loaded manually before using.

Best Regards,
Alexander Rivilis.
Message 8 of 13
Anonymous
in reply to: jgarciaanton

The system searches the directories on the PATH
environment variable; the current directory; and
the directory of the calling process, for DLLs loaded
via loadlibrary (without a path specified).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Alexander Rivilis" wrote in message news:5311336@discussion.autodesk.com...
Ok! I've found solution:
[code]
'Declaration:
_
Private Shared Function SetDllDirectoryA(ByVal path As String) As Integer
End Function
'Using sample:
SetDllDirectoryA("C:\Program Files\AutoCAD 2007") ' Now Application looking for ordinary dll-files in AutoCAD directory.
[/code]
AcCui.dll, AcCustomize.dl,l acdbmgd.dll, acmgd.dll, AcMNUParser.dll have to be in
directory of application or loaded manually before using.

Best Regards,
Alexander Rivilis.
Message 9 of 13
Anonymous
in reply to: jgarciaanton

Note that if you're doing a non-trivial amount of P/Invoke-ing, you might
want to consider using C++/CLI instead. This will let you access native
ObjectARX functionality directly and expose your own .NET interface.

Dan

"Alexander Rivilis" wrote in message
news:5311336@discussion.autodesk.com...
Ok! I've found solution:
[code]
'Declaration:
_
Private Shared Function SetDllDirectoryA(ByVal path As String) As Integer
End Function
'Using sample:
SetDllDirectoryA("C:\Program Files\AutoCAD 2007") ' Now Application looking
for ordinary dll-files in AutoCAD directory.
[/code]
AcCui.dll, AcCustomize.dl,l acdbmgd.dll, acmgd.dll, AcMNUParser.dll have to
be in
directory of application or loaded manually before using.

Best Regards,
Alexander Rivilis.
Message 10 of 13
Anonymous
in reply to: jgarciaanton

ObjectARX functionality is not allowed in standalone application (IMHO)! 🙂
Message 11 of 13
dwolfe01
in reply to: jgarciaanton

Can someone elaborate on this? I'm doing a similar thing (create an installation setup).

I've got all the information I need from the registry (cui location, program install path location), but I don't know how point my solution to allow looking in the local AutoCAD install folder for the AcCui.dll (and the others).

I'm using C# and I am not sure how to implement the SetDllDirectoryA function from VB.

Any clues?
Message 12 of 13
GTVic
in reply to: jgarciaanton

There was a free 2010 CUIX API webcast course recently. It has not yet been posted for download but there are others available. Here is the link.

http://www.adskconsulting.com/adn/cs/api_course_sched.php
Message 13 of 13
dwolfe01
in reply to: jgarciaanton

I emailed Wayne Brill about this since it (modifying a cui outside of AutoCAD) wasn't covered in the presentation. Here's the response (an excerpt from a previous case).
It is not legal to ship the AutoCAD specific DLL’s with your application. But you may copy the already installed CUI DLL’s on a machine into your applications installation directory during the installation process. That is the machine must have AutoCAD installed on it.

I am not sure if it is compulsory for you to go with the standalone approach but I would like to put forth some of the comments that came up during the discussion with my colleagues regarding this case. Although, it is mentioned that you can build standalone applications looks like it is not a good idea and the reasons being:

1. As I mentioned above, developers aren’t permitted to ship the CUI DLL’s with their applications, so that rules out installing CUI DLL’s with your application.
(Maybe a workaround to this would be for the installer to copy the already installed CUI DLL on a machine into its install directory, but that's messy)

2. The CUI DLL resides in the AutoCAD install directory, but is not a strong named assembly, so has no entry in the GAC. Therefore, to use it the developer must either
a. Run his executable from the AutoCAD install directory.

b. Dynamically find and load the CUI DLL at runtime
You may want to take a look at the following solution in MSDN:
How to load an assembly at runtime that is located in a folder that is not the bin folder of the application
http://support.microsoft.com/kb/837908

c. Have a hard coded dependency on a specific location for the CUI DLL. This then assumes AutoCAD is installed in the default directory.
System.IO.Directory.SetCurrentDirectory();

Of the above installing in the AutoCAD directory is probably the best.

Dynamically find and load the CUI DLL at runtime [would be] the best option if it worked. Unfortunately, it seems that .exe directory is hard-coded when AcCustomize.dll is loaded from AcCUI.dll. Even if AcCustomize.dll is already loaded, the FileNotFoundException is thrown if exe_dir\AcCustomize.dll is not found.
Please record this issue as a Change Request.

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