I'm working on automating some workflows in AutoCAD using VBA macros. I want to create a .bundle that loads my .dvb (VBA project) files at AutoCAD startup and makes the macros available as commands. Here's what I need to achieve:
Create a
.bundlestructure for AutoCAD.Define the
PackageContents.xmlto ensure the.dvbfiles are loaded when AutoCAD starts.Automatically register the macros as commands so they can be invoked directly.
Could someone guide me through the steps to achieve this? Examples of the necessary folder structure, XML content, and AutoLISP/VBA code to load the .dvb and register commands would be very helpful.
I have created the .bundle Folder Structure:
MyVBAProject.bundle
├── Contents
│ ├── MyVBAProject.dvb
│ ├── MyStartup.lsp
│ └── PackageContents.xml
Here's my current PackageContents.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<ApplicationPackage
SchemaVersion="1.0"
AutodeskProduct="AutoCAD"
Name="My VBA Project Loader"
Description="Loads VBA macros at AutoCAD startup"
Version="1.0.0"
Author="Your Name"
ProductType="Application">
<Components>
<RuntimeRequirements OS="Win64" Platform="AutoCAD" SeriesMin="R24.0" SeriesMax="R27.0"/>
<ComponentEntry AppName="MyStartupLSP" ModuleName="./Contents/MyStartup.lsp" LoadOnAutoCADStartup="true"/>
</Components>
</ApplicationPackage>
Here’s my MyStartup.lsp file to load the .dvb project:
(defun c:LoadVBAProject ()
(vl-load-com)
(vla-LoadDVB
(vla-get-vbamanager (vlax-get-acad-object))
(findfile "MyVBAProject.dvb")
)
(princ "\nVBA Project Loaded.")
)
;; Automatically call LoadVBAProject on startup
(c:LoadVBAProject)
My questions are:
Am I structuring the
.bundleandPackageContents.xmlfile correctly?How can I ensure that the macros in the
.dvbfile are exposed as AutoCAD commands automatically?Are there better ways to handle VBA project loading at startup or registering VBA macros as commands?
Any guidance or examples would be greatly appreciated!
1 Answer 1
The PackageContents.xml file should be at the root of the .bundle folder.
MyVBAProject.bundle
|__ PackageContents.xml
|__ Contents
|__ MyVBAProject.dvd
|__ MyStartup.lsp