Author Topic: Loading Palletes  (Read 5705 times)

0 Members and 1 Guest are viewing this topic.

Ken Alexander

  • Newt
  • Posts: 61
Loading Palletes
« 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
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #1 on: August 07, 2008, 12:05:56 PM »
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) ? 

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #2 on: August 07, 2008, 12:40:18 PM »
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.
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #3 on: August 07, 2008, 12:46:10 PM »
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

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #4 on: August 07, 2008, 12:54:57 PM »
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? 
Ken Alexander

Glenn R

  • Guest
Re: Loading Palletes
« Reply #5 on: August 07, 2008, 12:58:05 PM »
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?

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #6 on: August 07, 2008, 01:01:34 PM »
In my example I am.  My desire is to create it and set visible in LoadIt method (This does not work).
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #7 on: August 07, 2008, 01:19:14 PM »
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:

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #8 on: August 07, 2008, 01:26:28 PM »
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.
Ken Alexander

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #9 on: August 07, 2008, 01:28:58 PM »
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.
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #10 on: August 07, 2008, 02:13:33 PM »
Sorry, I really don’t know much about COM, but maybe you just need an interface.. I.e.  :mrgreen:

Code: [Select]
  public interface IComClass1
  {
    void loadPallete();
  }

  [ClassInterface(ClassInterfaceType.None)]
  public class ComClass1 : IComClass1
  {
    loadPallete()
    {
      Palette code...;
    }
  }

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #11 on: August 07, 2008, 02:19:31 PM »
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.
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #12 on: August 07, 2008, 02:50:39 PM »
last shot .... then maybe you need to do

Code: [Select]
     Public Sub LoadIt() Implements IClass2.LoadIt
       'I would like to load the pallete here
     End Sub

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #13 on: August 07, 2008, 02:52:17 PM »
For some reason that does not work.
Ken Alexander

Ken Alexander

  • Newt
  • Posts: 61
Re: Loading Palletes
« Reply #14 on: August 07, 2008, 07:56:07 PM »
For anyone following, your COM class should derive from System.EnterpriseServices.ServicedComponent, and all works fine.



Thanks to those that tried helping.
Ken Alexander

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8743
  • AKA Daniel
Re: Loading Palletes
« Reply #15 on: August 08, 2008, 12:35:41 PM »
Dang I wouldn’t have guessed that, thanks for sharing the solution  :-)