How Do You Save a Project With Drawings and VBA in a single file

How Do You Save a Project With Drawings and VBA in a single file

Anonymous
Not applicable
786 Views
6 Replies
Message 1 of 7

How Do You Save a Project With Drawings and VBA in a single file

Anonymous
Not applicable
I'm an AutoCAD Newbie so be kind.

But I have a lot of experience with VBA in the Microsoft Access domain where the databases and the code are all naturally saved in a single file.

Not so apparently with AutoCad and VBA, at least I haven't discovered the trick despite reading that it can be done.

So my question is simple: Can I save a Drawing File with embedded VBA? If so, how?
0 Likes
Accepted solutions (1)
787 Views
6 Replies
Replies (6)
Message 2 of 7

Ed__Jobe
Mentor
Mentor

Use VBAMAN. Create a project with the New button or select an existing project, then cllick on EMBED. It will be saved in the currently selected dwg. If you do embed the project, you have to have the dwg open to use it. Whereas a dvb can be loaded and used on any dwg. You can even save the dvb as acad.dvb and if it has a method called AcadStartup, it will autoload and run at startup.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 7

Anonymous
Not applicable
Thanks for your reply I will give that a try. But I wonder if this is really doing things the "AutoCad Way". After thinking about it some more it seems like I should go with a .dVb approach. My application requires the generation of about an 8 page construction permit that will be based on standard templates for each page, a PDF version and printed or plotted versions as well.

So I'm assuming I should be able to launch the .dvb file to a menu form that would allow me to generate either a new 8 document Project or bring up an existing one.

Question: is this the more conventional way of working with AutoCAD? Right now, as the Programmer I'm much more interested in understanding the AutoCad architecture than the ins and outs of the drawing capabilities.

So any advice or reference material that push me along would be greatly appreciated.

ip2
0 Likes
Message 4 of 7

Anonymous
Not applicable

See my previous Post for background.

Here is where I'm at now:

I took the acad.vbd approach. That looks like the right way to do what I'm trying to do.

 

I've created acad.vbd and added it's location to the Autocad search path

I've built a simple form: Command button and a "Hello World" MsgBox that pops up when it's pressed just to be original. 😉

I've added Module1 in the VBA

I've added the Macro AcadStartup to Module1:

Sub AcadStartup()
UserForm1.show
End Sub 

This almost works but the form does not show up on startup until I click on the Manage/Visual Basic Editor button on the main drawing menu. So I must need another statement besides UserForm1.show.

 

I'll try to figure this out but if anyone has the solution please post. I just want UserForm1 to show at Startup automatically.

 

ip2

0 Likes
Message 5 of 7

Ed__Jobe
Mentor
Mentor

Which version of Autocad are you using?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 7

Anonymous
Not applicable

AutoCad 2013. But I've figured out my problem. I had to add an acad.lsp file to the path:

 

acad.lsp

(defun-q Startup ()
(command "-vbarun" "AcadStartup")
)
(setq S::STARTUP (append S::STARTUP Startup))

 That fixed it. The simple minded Form shows up on Startup and functions correctly.

 

So I think I am good to go at this point on this thread. 

Thanks for the help.

 

ip2

0 Likes
Message 7 of 7

Ed__Jobe
Mentor
Mentor
Accepted solution

If you have to call the function then it isn't an automatic sub. The problem is that the vba environment doesn't automatically load. It loads when you issue a command that requires it, e.g. VBAMAN, VBARUN. The trick is to manually load the vba environment at startup. Then AcadStartup will run automatically. Replace your previous acad.lsp line with this one.

 

(arxload "acvba.arx" "\nACVBA.ARX file not loaded.")

 

Also, if this solved your question, please mark it as solved, maybe give kudos. Thanks.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature