2002 vs 2004 menu problem

2002 vs 2004 menu problem

Anonymous
Not applicable
423 Views
12 Replies
Message 1 of 13

2002 vs 2004 menu problem

Anonymous
Not applicable
Can anyone tell me why this chunk of code works fine on Acad2004 but gives an "automation catastropy" type error in 2002? In the debugger, the menuname (path) looks fine. This is weird... Public Sub LoadMenu(path As String) 'Load the Tblocker drop down menu if it is not already present. 'Path is the full path and file name of the menu 'Called by -> "main-Tbinit" 'Attach to AutoCAD Dim ObjAcad As Object Dim ObjDoc As Object Set ObjAcad = GetObject(, "AutoCAD.Application") Set ObjDoc = ObjAcad.ActiveDocument Dim ObjMenuGroup As AcadMenuGroup Set ObjMenuGroup = ObjAcad.MenuGroups.item(0) Dim ObjMenuGroups As AcadMenuGroups Set ObjMenuGroups = ObjAcad.MenuGroups Dim ObjPopup As AcadPopupMenu Dim MenuExists As Boolean For Each ObjPopup In ObjAcad.MenuBar If ObjPopup.NameNoMnemonic = "Title Block" Then MenuExists = True Exit For End If Next ObjPopup If Not MenuExists Then On Error Resume Next ' trap any load errors ObjMenuGroups.Load path If Err.Number <> 0 Then MsgBox "Unable to load Tblocker menu" Err.Clear GoTo done End If Set ObjMenuGroup = ObjMenuGroups.item("TBlocker") Set ObjPopup = ObjMenuGroup.menus.item(0) ObjPopup.InsertInMenuBar (ObjAcad.MenuBar.Count + 1) End If done: Set ObjDoc = Nothing Set ObjAcad = Nothing End Sub -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
424 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
by the way, path evaluates to "C:\Program Files\graphics\Tblocker\tblocker.mnu" -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 3 of 13

Anonymous
Not applicable
First off you can't use GetObject(, "AutoCAD.Application") if both are installed. You need to use Application.16 and Application.15. -- Mike ___________________________ Mike Tuersley CADalyst's CAD Clinic Rand IMAGINiT Technologies ___________________________ the trick is to realize that there is no spoon...
0 Likes
Message 4 of 13

Anonymous
Not applicable
Another weird thing, are you trying to late bind? If you are, then you should be diming everything as object - which you are getting away with because you haven't declared option explicit. -- Mike ___________________________ Mike Tuersley CADalyst's CAD Clinic Rand IMAGINiT Technologies ___________________________ the trick is to realize that there is no spoon...
0 Likes
Message 5 of 13

Anonymous
Not applicable
Sorry I took so long getting back, kinda tied up this weekend ;) Thanks for the tip Mike, Im pretty good at missing the obvious (application.15). I think thats one of the biggest pains of developing apps is having to maintain multiple versions where the only difference is they are linking to different libraries. Anyways, I made 2 versions of this app, one using (application.15) for acad2002 and one using (application.16) for acad2004. That didnt seem to fix the problem though, my code is still croaking at the "menugroups.load" statement even though its getting a valid menu name. Pretty annoying, just cant figure it. Oh and by the way, I do have "Option explicit" at the top of EVERY module I make, just to play it safe. It just didnt make it into my skillful cut&paste operation. I cant imagine why I would want this code to late bind??? -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 6 of 13

Anonymous
Not applicable
> I cant imagine why I would want this code to late bind??? Then why are you? This is your code snippet: Dim ObjAcad As Object Dim ObjDoc As Object That IS late binding. If you are early binding, then it should be: Dim oAcad As AcadApplication Dim oDoc As AcadDocument Normally you'd late bind to have your app work with multiple versions of AutoCAD. -- Mike ___________________________ Mike Tuersley CADalyst's CAD Clinic Rand IMAGINiT Technologies ___________________________ the trick is to realize that there is no spoon...
0 Likes
Message 7 of 13

Anonymous
Not applicable
Well, I never claimed to be a VB guru. Is that THE way to differentiate late/early binding in VBA? Late binding in this case didnt seem to help with my menu problem. How does late binding in this way help code work on different versions of Acad if we still have to reference specific libraries? Thanks -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Mike Tuersley" wrote in message news:1dlzyc9vxjntz.wzrm41r6egby.dlg@40tude.net... > > I cant imagine why I would want this code to late bind??? > Then why are you? This is your code snippet: > > Dim ObjAcad As Object > Dim ObjDoc As Object > > That IS late binding. If you are early binding, then it should be: > > Dim oAcad As AcadApplication > Dim oDoc As AcadDocument > > Normally you'd late bind to have your app work with multiple versions of > AutoCAD. > > > -- Mike > ___________________________ > Mike Tuersley > CADalyst's CAD Clinic > Rand IMAGINiT Technologies > ___________________________ > the trick is to realize that there is no spoon...
0 Likes
Message 8 of 13

Anonymous
Not applicable
Ok, forget the early/late question, I called upon my typical minimal effort, and with a bit of help from google found a document on MSDN which cleared this up nicely. Im of the impression now that early binding is probably better, since Im going to have to maintain 2 versions of this anyway might as well. Will alter code accordingly, but I have a feeling it may not fix the menu problem. I'll let you know shortly. thanks -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 9 of 13

Anonymous
Not applicable
Well I went through the code checking all the references and set them for earling binding. By the way doesnt that make the Set ObjAcad = GetObject(, "AutoCAD.Application.15") reference moot? that construct itself created an error until I replaced it with Set ObjAcad = ThisDrawing.Application. As I suspected though, none of this fixed my menu problem, any other ideas on this?? Thanks -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 10 of 13

Anonymous
Not applicable
Okay, Perry, I haven't got time at the moment to look at your code but I will in the morning. Till then, have you looked at/compared to the VBA Sample in the Samples\VBAIDE folder? -- Mike ___________________________ Mike Tuersley CADalyst's CAD Clinic Rand IMAGINiT Technologies ___________________________ the trick is to realize that there is no spoon...
0 Likes
Message 11 of 13

Anonymous
Not applicable
Thanks for the time Mike, here is my latest code for that function... Option Explicit Public Sub LoadMenu(path As String) 'Load the Tblocker drop down menu if it is not already present. 'Path is the full path and file name of the menu 'Called by -> "main-Tbinit" 'Attach to AutoCAD Dim ObjAcad As AcadApplication Dim ObjDoc As AcadDocument Set ObjAcad = ThisDrawing.Application Set ObjDoc = ObjAcad.ActiveDocument Dim ObjMenuGroup As AcadMenuGroup Set ObjMenuGroup = ObjAcad.MenuGroups.item(0) Dim ObjMenuGroups As AcadMenuGroups Set ObjMenuGroups = ObjAcad.MenuGroups Dim ObjPopup As AcadPopupMenu Dim MenuExists As Boolean For Each ObjPopup In ObjAcad.MenuBar If ObjPopup.NameNoMnemonic = "Title Block" Then MenuExists = True Exit For End If Next ObjPopup If Not MenuExists Then On Error Resume Next ' trap any load errors 'autocad 2002 bombs here, even though "path" is valid ("C:\Program Files\graphics\Tblocker\tblocker.mnu") ObjMenuGroups.Load path If Err.Number <> 0 Then MsgBox "Unable to load " & path & " : " & Err.Description Err.Clear GoTo done End If Set ObjMenuGroup = ObjMenuGroups.item("TBlocker") Set ObjPopup = ObjMenuGroup.menus.item(0) ObjPopup.InsertInMenuBar (ObjAcad.MenuBar.Count + 1) End If done: Set ObjDoc = Nothing Set ObjAcad = Nothing End Sub -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon
0 Likes
Message 12 of 13

Anonymous
Not applicable
I tried your code in 2002 and it worked fine. It must be something within your menu file ???? -- Mike ___________________________ Mike Tuersley CADalyst's CAD Clinic Rand IMAGINiT Technologies ___________________________ the trick is to realize that there is no spoon...
0 Likes
Message 13 of 13

Anonymous
Not applicable
Thanks for the help Mike ;) Ill try it with a different file and see what happens, strange though this same menu file works in 2004. Is there something different between 2002 and 2004 menus? -- Perry Leets Inovec Optimization and Control Systems Eugene, Oregon "Mike Tuersley" wrote in message news:fs6ly5gbupuy.nm81law2em5p$.dlg@40tude.net... > I tried your code in 2002 and it worked fine. It must be something within > your menu file ???? > > -- Mike > ___________________________ > Mike Tuersley > CADalyst's CAD Clinic > Rand IMAGINiT Technologies > ___________________________ > the trick is to realize that there is no spoon...
0 Likes