Author Topic: Automatically load .dll file in 2010?  (Read 7332 times)

0 Members and 1 Guest are viewing this topic.

deathman20

  • Guest
Automatically load .dll file in 2010?
« on: February 28, 2011, 09:48:06 AM »
Ok trying to make an installer for my dll, easier to deploy in my little department.  Though having issues trying to get the correct registry settings to make it automatically load the DLL?

So far the registry entry is.

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8005:409\Applications\ConveyorDept]
"DESCRIPTION"="Layout Department Ribbon Bar"
"LOADER"="C:\\Program Files\\AutoCAD RibbonBar\\BottleConveyorRibbon.dll"
"MANAGED"=dword:00000001
"LOADCTRLS"=dword:00000002

Yet it doesn't load.  Was trying to follow what others have done but just doesn't seem to be working.  Any suggestions?

I know it loads it in memory, because the commandline paramaters I use work (though incorrectly) but the ribbon bar I have doesn't load up.  It works perfectly fine if I run "netload" though.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #1 on: February 28, 2011, 10:02:51 AM »
I've not done that much work with the Ribbon Bar in AutoCAD, but might it be related to the profile you're using? i.e. what ribbons are loaded and when.

Failing that, have you checked out Kean's posts regarding demand loading? - It's how I got around having to work with AutoCAD 2009 and the Ribbon Bar for the tool(s) I've created; AutoCAD 2009 didn't (unless I'm mistaken) have the combined Ribbon-specific libraries that newer versions have.

Which version of AutoCAD are you using by the way? It always helps make finding the answer easier.

(Do any of the admins know if there's a "useful info to post when looking for an answer" post?)

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #2 on: February 28, 2011, 10:12:11 AM »
Ah shoot thought I had put it in there, using AutoCAD 2010.  Well its a Mechanical install but just using plain AutoCAD.

Just tried another way.  Different spot in the registry and failed so the location I had it before is working just not fully loaded the module.  

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\ConveyorDept]
"DESCRIPTION"="Test"
"LOADER"="C:\\Program Files\\AutoCAD RibbonBar\\BottleConveyorRibbon.dll"
"MANAGED"=dword:00000001
"LOADCTRLS"=dword:0000000e


As for Kean's post... now that you show the search that way, was just hitting up a few of those, there is some new ones I didn't see there yet.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #3 on: February 28, 2011, 10:39:22 AM »
Ah shoot thought I had put it in there, using AutoCAD 2010.  Well its a Mechanical install but just using plain AutoCAD.

Just tried another way.  Different spot in the registry and failed so the location I had it before is working just not fully loaded the module.  

[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.0\ACAD-8001:409\Applications\ConveyorDept]
"DESCRIPTION"="Test"
"LOADER"="C:\\Program Files\\AutoCAD RibbonBar\\BottleConveyorRibbon.dll"
"MANAGED"=dword:00000001
"LOADCTRLS"=dword:0000000e


As for Kean's post... now that you show the search that way, was just hitting up a few of those, there is some new ones I didn't see there yet.
RE: the search, I was quite surprised that "demand loading" shows up that much too. :)

As it is AutoCAD Mechanical you're using, I'd definitely recommend you check what profile you're using when starting AutoCAD - that may be affecting your tool and what it loads.


deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #4 on: February 28, 2011, 10:44:52 AM »
Well strange glitch per say I guess, it actually is loaded but I have to click on my workspace (what ever one I want) and it will show up then.

Didn't try that before so not sure if its the RegDL I got from http://through-the-interface.typepad.com/through_the_interface/2010/02/creating-demand-loading-entries-for-net-modules-outside-of-autocad.html or if my registry entry was making it run.  Edit: Actually notice that is using the exact same registry settings that I had, so it was running before just not showing up in the workspace properly.

I know I spend a few hours on Friday working with this and wasn't getting anywhere.  Maybe its dealing with the code for the ribbon bar where its not launching properly?  I believe this is the code for how its inserted into the workspace.

Code: [Select]
   Public Sub TrapWSCurrentChange(ByVal sender As Object, _
                                   ByVal e As cadAppSrvs.SystemVariableChangedEventArgs)
        If e.Name.Equals("WSCURRENT") Then createRibbon()
    End Sub

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #5 on: February 28, 2011, 10:53:03 AM »
That's an interesting (and seemingly obvious) method you've got there - would you mind sharing how you implement it? I'm guessing you're simply trapping the (and I'm making this up off the top of my head) "Workspace_changed" event to call TrapWSCurrentChange()?

Thanks,

Alex.

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #6 on: February 28, 2011, 10:57:14 AM »
Im not 100% sure exactly whats going on with it.  The code is copied from others that I've gotten but here is a bigger snip it, minus the main ribbon button area.  Though here is majority of the code dealing with the ribbon bar itself.

Code: [Select]
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Windows.Media.Imaging

Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.Windows
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

Imports cadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports cadAppSrvs = Autodesk.AutoCAD.ApplicationServices


Public Class BottleConveyorRibbon

    Public Shared BlockName As String

    Public Sub TrapWSCurrentChange(ByVal sender As Object, _
                                   ByVal e As cadAppSrvs.SystemVariableChangedEventArgs)
        If e.Name.Equals("WSCURRENT") Then createRibbon()
    End Sub


    'Creates the Ribbon Tabs
    Public Sub createRibbon()
        Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
        If ComponentManager.Ribbon Is Nothing Then
            Return
        End If

        For i As Integer = 0 To ribCntrl.Tabs.Count - 1
            If ribCntrl.Tabs(i).Id.Equals("My_Rib_ID") Then
                Return
            End If
        Next

        'Creates a tab
        Dim mbc1Tab As New RibbonTab()
        mbc1Tab.Title = "Bottle Conveyor Mattop 1-10"
        mbc1Tab.Id = "Bottle_Conveyor_Mattop_1_10"
        ribCntrl.Tabs.Add(mbc1Tab)

        Dim mbc2Tab As New RibbonTab()
        mbc2Tab.Title = "Bottle Conveyor Mattop 12-20"
        mbc2Tab.Id = "Bottle_Conveyor_Mattop_12_20"
        ribCntrl.Tabs.Add(mbc2Tab)

        Dim bcmiscTab As New RibbonTab()
        bcmiscTab.Title = "Bottle Conveyor Misc"
        bcmiscTab.Id = "Bottle_Conveyor_Misc"
        ribCntrl.Tabs.Add(bcmiscTab)

        'Create and add the panels
        'Bottle Conveyor Mattop 1-10
        addmbc1c(mbc1Tab)
        addmbc2c(mbc1Tab)
        addmbc3c(mbc1Tab)
        addmbc4c(mbc1Tab)
        addmbc5c(mbc1Tab)
        addmbc6c(mbc1Tab)
        addmbc7c(mbc1Tab)
        addmbc8c(mbc1Tab)
        addmbc10c(mbc1Tab)

        'Bottle Conveyor Mattop 12-20
        addmbc12c(mbc2Tab)
        addmbc14c(mbc2Tab)
        addmbc16c(mbc2Tab)
        addmbc18c(mbc2Tab)
        addmbc20c(mbc2Tab)

        'Bottle Conveyor Misc
        addmbcFM(bcmiscTab)
        addmbcclean(bcmiscTab)
        addmbcAccum(bcmiscTab)
        addssbcAccum(bcmiscTab)
        addmbcWF(bcmiscTab)

        'set as active tab
        mbc1Tab.IsActive = True

    End Sub

    Private Sub removeRibbon()
        Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
        'find the custom tab using the Id
        For i As Integer = 0 To ribCntrl.Tabs.Count - 1
            If ribCntrl.Tabs(i).Id.Equals("Mattop_Bottle_Conveyor") Then
                ribCntrl.Tabs.Remove(ribCntrl.Tabs(i))
                Return
            End If
        Next
    End Sub


  ''' Bunch of Ribbon Bar Buttons :)


    'Imaging Information
    Public Function getBitmap(ByVal image As Bitmap) As BitmapImage
        Dim stream As New MemoryStream()
        image.Save(stream, ImageFormat.Png)
        Dim bmp As New BitmapImage()
        bmp.BeginInit()
        bmp.StreamSource = stream
        bmp.EndInit()

        Return bmp
    End Function

End Class

Public Class AdskCommandHandler
    Implements System.Windows.Input.ICommand

    Public Function CanExecute(ByVal parameter As Object) _
    As Boolean Implements System.Windows.Input.ICommand.CanExecute
        Return True
    End Function

    Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
    Implements System.Windows.Input.ICommand.CanExecuteChanged

    Public Sub Execute(ByVal parameter As Object) _
    Implements System.Windows.Input.ICommand.Execute
        Dim ribBtn As RibbonButton = TryCast(parameter, RibbonButton)
        If ribBtn IsNot Nothing Then
            BottleConveyorRibbon.BlockName = ribBtn.Text
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute( _
                ribBtn.CommandParameter, True, False, True)
        End If
    End Sub
End Class

Another Piece of the code that deals with the trap function.

Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports cadApp = Autodesk.AutoCAD.ApplicationServices.Application

<Assembly: ExtensionApplication(GetType(BottleConveyorRibbonApp.IntialEnd))>

Namespace BottleConveyorRibbonApp


    Public Class IntialEnd
        Implements IExtensionApplication

        Public Sub Initialize() Implements IExtensionApplication.Initialize
            Dim cnvrRib As New BottleConveyorRibbon
            cnvrRib.createRibbon()
            AddHandler cadApp.SystemVariableChanged, AddressOf cnvrRib.TrapWSCurrentChange
        End Sub

        Public Sub Terminate() Implements IExtensionApplication.Terminate

        End Sub
    End Class


End Namespace

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #7 on: February 28, 2011, 11:21:01 AM »
So, from your last post; what isn't working as expected?

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #8 on: February 28, 2011, 11:32:12 AM »
It loads, but...  I have to click the (first image) workspace for it to pop up.

(Second image) this is what it shows up on loading autocad
(Third image) this is what it looks like after I click the workspace button and load or reload a workspace

It can be any workspace but you have to click one for it to show.  As well it defaults as it should to the ribbon tab as it should, as done when manually loading it.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #9 on: February 28, 2011, 11:57:36 AM »
From your description and the screenshots, it seems like it's working as designed - i.e. Your Ribbon Bar is only created when you click the Workspace button which fires the "SystemVariableChangedEvent" the TrapWSCurrentChange() method is looking for.

I'd suggest you rethink how/when your add-in is loaded - unless you only need it in a specific workspace; which as far as I can tell from your code isn't the case? You're not filtering for a specific workspace name, only whether the current workspace has changed?!

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #10 on: February 28, 2011, 01:22:19 PM »
Yeah noticing that now.  I'd like it to load on startup of autocad like everything else without any interaction.

Right now deploying it via a executable file, just for ease of doing so.  Figured the registry method would of been the best for this, and hopefully some tweaking of the code will fix it.

Glenn R

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #11 on: February 28, 2011, 03:07:50 PM »
There is a sysvar called 'WSCURRENT' if I remember correctly - maybe that needs setting in an acad/acaddoc.lsp startup file? I'm only guessing as i haven't touched ribbon stuff before.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #12 on: March 01, 2011, 04:08:15 AM »
Thanks Glenn,

The "WSCURRENT" sysvar is what the TrapWSCurrentChange() routine is watching and when it's value changes that's when the Ribbon Bar is loaded.

I think targeting a specific workspace is the way forward, but I don't know of a solution to that..

Glenn R

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #13 on: March 01, 2011, 05:03:20 AM »
Whoops! Sorry about that - I was only skimming through the thread.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #14 on: March 01, 2011, 05:51:36 AM »
Hey, No worries Glenn!

At least it proves that I understand what he's trying to do.. Which makes a nice change. :)

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #15 on: March 01, 2011, 09:26:44 AM »
Exactly AlexF.  Just need to figure out how.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #16 on: March 01, 2011, 11:30:27 AM »
Hey, I found something you might like using this Google search:

http://au.autodesk.com/?nd=material&session_material_id=5314 is a link to an Autodesk University class handout (hosted by Wayne Brill) from 2009 and on pages 19 onwards it details how to add a Ribbon to a specific Workspace.

The code in that document seems to be based around creating a new workspace and adding your ribbon bar to it - in this case the Workspace being modified is named "Demo Workspace".

It wouldn't be too much of a stretch I don't think to have it modify an existing workspace - although if you really wanted to get your users' attention you could have your add-in create its very own workspace.

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #17 on: March 01, 2011, 12:41:27 PM »
Oh good find Alex.  I'll put this on my list to check out but looks like what I need.  Thanks!

Right now in the mix of figuring out a block inserting issue with jigging which isn't making me a happy camper.  But thats for another thread.

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #18 on: March 01, 2011, 03:30:09 PM »
Well had to do something productive today so looked further into this.

Removed this....
Code: [Select]
    Public Sub TrapWSCurrentChange(ByVal sender As Object, _
                                   ByVal e As cadAppSrvs.SystemVariableChangedEventArgs)
        If e.Name.Equals("WSCURRENT") Then createRibbon()
    End Sub

Added this instead.....
Code: [Select]
    Overridable Sub Initialize() Implements IExtensionApplication.Initialize
        If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then
            'load the custom Ribbon on startup, but at this point
            'the Ribbon control is not available, so register for
            'an event and wait
            AddHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized
        Else
            'the assembly was loaded using NETLOAD, so the ribbon
            'is available and we just create the ribbon
            createRibbon()
        End If
    End Sub

    Overridable Sub Terminate() Implements IExtensionApplication.Terminate

    End Sub

    Private Sub ComponentManager_ItemInitialized(ByVal sender As Object, ByVal e As RibbonItemEventArgs)
        'now one Ribbon item is initialized, but the Ribbon control
        'may not be available yet, so check if before
        If Autodesk.Windows.ComponentManager.Ribbon IsNot Nothing Then
            'ok, create Ribbon
            createRibbon()
            'and remove the event handler
            RemoveHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized
        End If
    End Sub

Did that and worked like a charm.  It will only load on the workspace that is currently open but if you change to a new workspace and close/reopen the program it will be there.  So really for most purposes it works as intended.  That document helped out lots Alex thanks.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #19 on: March 02, 2011, 04:30:54 AM »
I might be wrong but wouldn't keeping the TrapWSCurrentChange() method allow the code to create the ribbon bar regardless of which workspace you switch to?

deathman20

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #20 on: March 02, 2011, 09:11:35 AM »
I might be wrong but wouldn't keeping the TrapWSCurrentChange() method allow the code to create the ribbon bar regardless of which workspace you switch to?


Yes, though there is a minor glitch with it.  Sometimes, not always it was opening another instance of the tabs if going back to a different workspace that already had it open.  Really it won't bother us here that I know of since we just use a single workspace and thats it.  Course can be something to look at in the future.

vegbruiser

  • Guest
Re: Automatically load .dll file in 2010?
« Reply #21 on: March 02, 2011, 09:25:08 AM »
You mean it was duplicating Ribbon Tabs?

That could be solved by checking whether there's already a tab with the same name in this whatever workspace you're switching to couldn't it?