ecuas Posted May 20, 2009 Share Posted May 20, 2009 hi. This is my first post here. Hoping to get some help. I am working on a college project, wherein i am customizing autocad 2000 with VB 6. My guide wants me to stick to these two programs. I am trying to customize the Shortcut Menu that pops up when i right-click on a BlockReference Object inserted in the drawing. I want to append a menuitem, called ,say, GetShaftAttributes to the Shortcut Menu, . When I click on this menu item, I want the attributes for that Block object to be displayed in a Text box on my Form window. So far, I have managed to do this much: 1] Select an object from the drawing window using the GetEntity method. As of now, I invoke this method using a button on the form.I can display the attributes easily in a textbox by storing them in a variant. 2] I can add the GetSaftAttributes item to the shortcut menu, but dont know how to make it appear in a context-sensitive way, i.e., it should be visible in the menu only if the user selects and right-clicks on a BlockReference object. The problem is how do i invoke the GetEntity method from the GetShaftAttributes menuitem. Is there a way to implement such methods through menus? Or am I limited to macros? Quote Link to comment Share on other sites More sharing options...
ecuas Posted May 21, 2009 Author Share Posted May 21, 2009 please anyone? and I was playing around with the following rough code for adding menus programatically to the current loaded menugroup ("HSD") Private Sub Addmenu() Call handler app.Visible = True Dim objMenuGroup As AcadMenuGroup Dim objMenu As AcadPopupMenu Dim objNewMenu As AcadPopupMenu Dim objMenus As AcadPopupMenus Set objMenuGroup = app.Application.MenuGroups.Item("HSD") Set objMenus = objMenuGroup.Menus Set objNewMenu = objMenus.Add("Context Menu For Blocks") End Sub This does add a menu entry to the MNS file, but the menu created is a simple popup menu, after the Help menu, i.e. in the POP1x section in the MNS file. But all the context menus are POP500 and above. Is there a way to add a menu to this POP5xx series through code? The only solution I could come up with was to edit the whole MNS file through code, but it doesnt seem feasible. Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 21, 2009 Share Posted May 21, 2009 Part of the problem with getting help on this issue is that later releases of AutoCAD have abandoned the MNS menu file structure in favor of the XML based CUI. Some of us may still have pre CUI releases, but it will require some time to re-familiarize ourselves. Please be patient. Quote Link to comment Share on other sites More sharing options...
ecuas Posted May 21, 2009 Author Share Posted May 21, 2009 Yes that's true. Can you help me with the other problem? How can I run a Visual Basic 6 procedure from an autocad menu item? IS there a VB equivalent to -vbarun module.macro? Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 21, 2009 Share Posted May 21, 2009 You’re best bet would be to compile the VB6 code to a DLL which can be referenced from AutoCAD 2000’s VBAIDE. The code in that DLL can then be accessed and run by a simple VBA calling routine using that vbarun module.macro methodology just mentioned. Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 22, 2009 Share Posted May 22, 2009 This works in AutoCAD 2004, which also uses the older MNS menu structure. This code was written to run in AutoCAD's VBAIDE. The code will require a bit of modification to work from a standalone VB6 app. Sub NewMenuItem() Dim colMenus As AcadMenuGroups Dim objMenu As AcadMenuGroup Dim objApp As AcadApplication Dim objPopMen As AcadPopupMenu Dim NewMenuItem As AcadPopupMenuItem Dim strMacro As String strMenuNames = "" Set objApp = ThisDrawing.Application Set colMenus = objApp.MenuGroups For Each objMenu In colMenus If objMenu.Name = "ACAD" Then For Each objPopMen In objMenu.Menus If objPopMen.Name = "Context menu for BLOCK Objects" Then strMacro = Chr(3) & Chr(3) & Chr(95) & "-VBARUN CallingRoutine" & Chr(32) '"CallingRoutine" would need to be available Set NewMenuItem = objPopMen.AddMenuItem(objPopMen.Count + 1, "GetShaftAttributes ", strMacro) End If Next End If Next Quote Link to comment Share on other sites More sharing options...
ecuas Posted May 22, 2009 Author Share Posted May 22, 2009 hey it works great! I just compiled a dll and it worked nicely. thank you so much for your time. really appreciate it. I also have a question: As of now, I am loading the dvb file using the VBALOAD command in my VB application. I want to bundle my application, as in create a setup file so that ppl can install it on their comps. is it normal to include the dvb file in the bundle? So that during the installation the dvb file shall get copied somewhere and when my app fires it will load an autoacad instance with the dvb file loaded. I just want to know if thats what is normally done for such projects, or is the dvb file compiled or something? I am quite new to this so i apologize for being ignorant. Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 22, 2009 Share Posted May 22, 2009 A DVB file is not subject to further compilation until it is loaded by AutoCAD. From within a single company, deployment is usually a matter of the DVB located on a shared drive (Intranet). This makes it easier for the developer to modify code with minimal additional fuss. I can’t remember the exact number but there is a limit to the amount of machines that can share a DVB from any one server. If you do deploy it as a bundled app then the DVB containing the CallingRoutine would have to be placed on each machine. A potential location may be the one referenced by ThisDrawing.Application.preferences. Files.MenuFile. If more flexibility is required with regard to file location then, obviously, your deployment package would have to keep track of all those details. It is then just a matter of calling “AutoCADObject”.LoadDVB “DVBFile” Quote Link to comment Share on other sites More sharing options...
ecuas Posted May 22, 2009 Author Share Posted May 22, 2009 yes i tried it and it works. thanks a ton for ur help. :-) as for the deployment package, I think i will try the Package Manager that comes with VB6. I have a query, again :-P I have a class (class name acad) in my project for initializing and starting up an instance of AutoCAD and then adding a menu. The procedure for inserting the menu is a part of the acad class. The procedure gets called whenever the autocad object is initialized though. I What I want to do is execute the addmenu procedure when AutoCAD is started up for the first time. Just that once. For now, what I have done is placed a checkbox on the form, and when the addmenu procedure gets executed, the checkmark value is set to one. The procedure is called like this: if form1.check1.value= 0 then call addmenu() so once the procedure is executed, it cannot run again till I shutdown the application. I think this is really a cheeky way to do it though..is there a better way? Also, it causes a problem if I close autocad and then start it again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.