PDA

View Full Version : Running VBA code from tool bar button in Electrical 2005


RDAY
21-01-2005, 02:25 PM
Hey All,

I have a block of an enclosure back panel that I have divided up into a grid. I use the grid for laying out my components. I placed the lines of the grid in their own layer so I can turn them on or off as needed. Now the fun part. I have hashed together some VBA code that will toggle the layer and there by the grid on and off. I have a toolbar button to run this code. This seems to work but each time I open a new drawing I get a message box informing me that the project is already loaded.

According to the doc in the acad2005.lsp file this should only load at start up. Any ideas? The code is below.


Thanks for you help.

Button code:
^C^C-vbarun PanelGrid

VBA code:
Sub PanelGrid()

Dim layerObj As AcadLayer
Set layer = ThisDrawing.Layers.Add("PANELGRID")

If layerObj.LayerOn = True Then
layerObj.LayerOn = False
Else: layerObj.LayerOn = True

End If
ThisDrawing.Regen acActiveViewport
End Sub


Lisp I placed in “acad.lsp”:
(defun S::STARTUP()
(command "_VBALOAD" "PanelGrid.dvb")
)

Eddie
10-05-2005, 10:42 AM
:shock: Sorry for the extremely late reply on this one ... hopefully you've found a solution but just incase...

Your best option I believe is to add this the acad.mnl file as this file loads with each session only not each drawing.

(command "loadvba" "Path To Your DVB File.dvb")

Hope this helps

mbasa
19-01-2006, 01:17 PM
check this url:

http://usa.autodesk.com/adsk/servlet/ps/item?id=2888989&linkID=2475323&siteID=123112

Cad_Monkey
07-12-2008, 10:46 PM
For Ease of use i would reccomend setting up a Acaddoc.lsp with the following code within it.

(defun c:XRDO (/ cmdecho)
(princ "\nCreated by PBAJV CAD Systems")
(setq cmdEcho (getvar "CMDECHO"))
(setvar "cmdecho" 0)
(vl-vbarun "PBAJV_DRAWORDER.dvb!ThisDrawing.DoDrawOrder")
(setvar "CMDECHO" cmdEcho)
(princ)
)

I would also add the location of your .dvb file into the File support pathing to save the issue of putting file support pathing into the Lisp routine.