Dynamically controlling menu content in a cui

Dynamically controlling menu content in a cui

Anonymous
Not applicable
405 Views
3 Replies
Message 1 of 4

Dynamically controlling menu content in a cui

Anonymous
Not applicable
I have VBA code which controls just how much of a custom drop down menu is displayed. Basically the VBA code presents 4 menu items by default when the user starts a new drawing or opens an existing one. Then, dependent on the existence of an identification block will also display a further 12 items. This has worked well since I developed it for v2000 (we're currently using v2005).

However we are migrating to 2008 and, whilst the code still works at drawing creation and opening, when the user changes workspace the menu disappears. I can't find a reactor that will trigger when the workspace changes so I can only think that I will have to create the menu dropdown in an Enterprise cui to make sure it stays on screen.

But can anyone advise how I can duplicate the testing for the identification block to control menu item display in the cui?
0 Likes
406 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Here is the example from help for using the Application Level SysVarChanged Event. The system variable you need is WSCURRENT.

Public WithEvents ACADApp As AcadApplication ' Use with Application Event Examples
Sub Example_AcadApplication_Events()
' This example intializes the public variable (ACADApp) which will be used
' to intercept AcadApplication Events
'
' The VBA WithEvents statement makes it possible to intercept an generic object
' with the events associated with that object.
'
' Before you will be able to trigger any of the AcadApplication events,
' you will first need to run this procedure.

' We could get the application from the ThisDocument object, but that would
' require having a drawing open, so we grab it from the system.
Set ACADApp = GetObject(, "AutoCAD.Application.16")
End Sub
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
' This example intercepts an Application SysVarChanged event.
'
' This event is triggered when the value of a system variable is changed.
'
' To trigger this example event:
' 1) Make sure to run the example that initializes
' the public variable (named ACADApp) linked to this event.
'
' 2) Change the value of a system variable in AutoCAD.
' For example: Type GRIDMODE on the command line and toggle the grid display on/off

' Use the "SysvarName" and "newVal" variables to determine which
' system variable has changed and its new value.
MsgBox "The system variable " & SysvarName & " was just changed to: " & newVal
End Sub
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thankyou Nathan, never thought of that. Works a treat.
0 Likes
Message 4 of 4

Anonymous
Not applicable
I spoke too soon! It works on starting a fresh drawing but the moment I run any code from the menu I add this way - basically setting up the drawing, adding frame etc - it stops working and the sysvarchanged stops being triggered.

Delving through the help files I see that the GetObject function only returns the first instance of AutoCAD. Whilst not actually opening a 2nd instance I am running in multiple interface mode. Can this be causing the problem? If it is I need to find some way around the problem (other than running in single).

If I manually rerun the application_events sub then it works again but I don't seem to be able to re-run it programatically.

Any ideas? My brains melting111111
0 Likes