TheSwamp
Code Red => .NET => Topic started by: Ken Alexander on August 07, 2008, 10:27:25 AM
-
Hello Folks,
I'm in need of a little assistance. Here is my scenario: I would like to start AutoCAD and then load a pallete in a button click event. I have created an Interface and COM class to handle this and all works fine. The problem I am having is that I do not want the pallete to load on the call GetInterfaceObject or NETLoad. I want to load the pallete in a button click event not in the Initialize Sub of the COM Class. Is this even possible? Thanks for any insight.
Ken
Here is the click event:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim acAppObj As AcadApplication
acAppObj = CreateObject("AutoCAD.Application.17")
Dim acDoc As AcadDocument = acAppObj.ActiveDocument
Dim ThePalletObj As ClassLibrary1.IClass2 = acAppObj.GetInterfaceObject("ClassLibrary1.ComClass1")
'I would like to call this method to load the pallete.
'ThePalletObj.LoadIt()
End Sub
Here is the COM Class:
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports System.Reflection
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
Implements IClass2
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "78fc94bf-f16a-45cc-9bf2-ede66358e582"
Public Const InterfaceId As String = "d8ee9b8d-3c6e-419d-aa22-d033efe97228"
Public Const EventsId As String = "a4044d8f-b0c8-43e8-8aa5-7c3e8ae88310"
#End Region
Private WithEvents CtlToolsPalette As Autodesk.AutoCAD.Windows.PaletteSet
Private WithEvents DocManager As Autodesk.AutoCAD.ApplicationServices.DocumentCollection
Private mycontrol As New UserControl1
Public Sub New()
MyBase.New()
End Sub
Public Sub LoadIt() Implements IClass2.LoadIt
'I would like to load the pallete here
End Sub
Private Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
CtlToolsPalette = New Autodesk.AutoCAD.Windows.PaletteSet("TestPallete")
With CtlToolsPalette
.Add("TestPallete", mycontrol)
.Style = 10
.MinimumSize = New System.Drawing.Size(200, 400)
.Size = New System.Drawing.Size(254, 400)
.Opacity = 90
.Visible = True
.DockEnabled = DockSides.Left + DockSides.Right
.Visible = True
End With
DocManager = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
End Class
-
Are you demand loading the assembly? If so you could expose a method to com that launches the palette. The timing might be tough to get correct, i.e. the time it takes AutoCAD to launch, load the assembly etc.
BTY what’s your affiliation with Microvellum (if you don’t mind me asking) ?
-
No, I'm not wanting to use demand loading. I would like to start AutoCAD, load the dll, and then load the pallete from a Windows form. I need my exe to be the calling exe of the COM dll that loads the pallete.
I am one of the programmers for Microvellum.
-
No, I'm not wanting to use demand loading. I would like to start AutoCAD, load the dll, and then load the pallete from a Windows form. I need my exe to be the calling exe of the COM dll that loads the pallete.
So how are you planning to load your .NET DLL? It’s either autoload or via user input yes??
I am one of the programmers for Microvellum.
Cool, I’m in the casework business
-
I'm using the GetInterfaceObject method as in the example code below. This will return the COM object which I then can cast to my Interface and it's at that point I want to load the pallete.
Are you building casework or "building software" for casework manufacturers. or both?
-
I haven't worked with palettes, but it looks liek your creating and setting visible the palette in the Initialize function....is that your intent?
-
In my example I am. My desire is to create it and set visible in LoadIt method (This does not work).
-
I'm using the GetInterfaceObject method as in the example code below. This will return the COM object which I then can cast to my Interface and it's at that point I want to load the pallete.
I am missing something? how are you loading the code for the palette into AutoCAD?
It must be loaded via netload or demand before it will work. Once it’s loaded then you can party on it.
Are you building casework or "building software" for casework manufacturers. or both?
I was drawing but now I’m a wannabe coder :laugh:
-
Look at the button click event code of my example.
This line loads the dll:
Dim ThePalletObj As ClassLibrary1.IClass2 = acAppObj.GetInterfaceObject("ClassLibrary1.ComClass1")
If I have the code to load the pallete in the Initialize method (of the ComClass1), the pallete loads automatically just fine. I do not want to do it this way, I want to call the LoadIt method to load the pallete in my button click event.
-
I'm sorry I may have not provided enough info.
I have a Windows form application that I am using to start AutoCAD and load the pallete. I want my application to be responsible for loading the pallete, not AutoCAD.
-
Sorry, I really don’t know much about COM, but maybe you just need an interface.. I.e. :mrgreen:
public interface IComClass1
{
void loadPallete();
}
[ClassInterface(ClassInterfaceType.None)]
public class ComClass1 : IComClass1
{
loadPallete()
{
Palette code...;
}
}
-
In my initial post, you'll see that I am implementing IClass2 that has the sub LoadIt(). GetInterfaceObject returns a COM object that can only be cast to an Interface on the .NET side.
-
last shot .... then maybe you need to do
Public Sub LoadIt() Implements IClass2.LoadIt
'I would like to load the pallete here
End Sub
-
For some reason that does not work.
-
For anyone following, your COM class should derive from System.EnterpriseServices.ServicedComponent, and all works fine.
Thanks to those that tried helping.
-
Dang I wouldn’t have guessed that, thanks for sharing the solution :-)