Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: VBA startup routine does not get initialized itself...

  1. #1
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default VBA startup routine does not get initialized itself...

    Hi all,
    I am new to this forum and a beginner of AutoCAD VBA. I have a sub called acadstartup() in acad.dvb. When I open a drawing from the same folder of acad.dvb, it gets loaded automatically, but the startup function needs a trigger like click on the VBA manager from the tools menu or such VBA commands. As soon as the command is invoked, the acadstartup () function starts prior to that command. I wonder why it is not working its own! Any solution???? I am using AutoCAD 2005 with WinXP SP2.

    Thanks,

    Abdul Huck

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    If you don't have acad.dvb in one of your search path folders (Options>Files Tab) then the only way acad can find it is if its in the folder where the dwg is opened.
    C:> ED WORKING....

  3. #3
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Yes Ed, both the drawing and acad.dvb are in the same folder. the acad.dvb is having a sub routine in module1 called acadstartup (). The acad.dvb is getting loaded, fine. But the sub routine acadstartup is not running as a startup routine. My code looks some thing like this...

    Code:
     
    Sub AcadStartup()
    	Dim Fs As Object
    	Set Fs = CreateObject("scripting.filesystemobject")
    	Dim eCount As Integer
    	eCount = 0
    	Dim ACADPref As AcadPreferencesProfiles
    	Dim SourceProfile As String, DestinationProfile As String
    	Set ACADPref = ThisDrawing.Application.preferences.Profiles
    	On Error GoTo ERRORTRAP1
    	SourceProfile = "<<Unnamed Profile>>"
    	DestinationProfile = "ACAD2004_WP_KOC_R1"
    	ACADPref.CopyProfile SourceProfile, DestinationProfile
    	ACADPref.ActiveProfile = DestinationProfile
    .........
    end sub
    My intention is that when the user opens the drawing, this code should automatically get executed and set some preferences like profile, support file search path and a user menu.
    I tried to embed the dvb into the drawing also, but I need to initialize any of the VBA command, then AutoCAD prompts, "Initializing VBA system....." , then my code get executed, then the VBA command I invoked works (for example, VBAman), then AutoCAD prompts "Loading VBA startup file...". I am confused with the sequence of execution. Hope this gives you a clear picture...

    Many thanks,
    Abdul

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Let me say it another way.
    The proper way to use acad.dvb is to put it in one of your search folders, not with the dwg. It is supposed to be loaded when the program starts, not when the drawing loads. Do that, and vba will initialize when AcadStartup is run properly.
    C:> ED WORKING....

  5. #5
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Let me explain my requirement. I need to send a set of customized files to a remote site (I don't have access to that network). All I need to tell the user is that double click and open a drawing (eg. startup.dwg). Then the "acadstartup" routine should take care rest of the things like copying a profile, set it current, add a support path, load a user menu etc. This is only one time set up. I don't want to run this every time the application starts. That's why I prefer to embed it into a drawing or save it in the same folder as the drawing, because the user will be instructed to open the drawing only once.

    Kindly suggest me the best way to do this.

    Many thanks,

    Abdul

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    That explanation helps. AcadStartup will not work when a dwg 'starts up', only when the application starts up; just once. After all, its called "Acad" startup, not 'DwgStartup'. To get a sub to work when a doc is opened, you need to add code to an event handler. Depending upon what you need to do, you might choose one of the following ThisDrawing.BeginOpen, ThisDrawing.EndOpen, ThisDrawing.NewDrawing. These events need to be in a class that uses the WithEvents statement in the Declarations section.
    Last edited by Ed Jobe; 2006-06-28 at 02:12 PM.
    C:> ED WORKING....

  7. #7
    100 Club
    Join Date
    2000-11
    Location
    Adelaide, South Australia
    Posts
    116
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Another option would be to run the routine from acaddoc.lsp or acad.lsp if the acadlspasdoc variable is set to 1.

    Regards - Nathan

  8. #8
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Thanks Ed & Nathan,

    But I have a few points to get cleared.

    Quote Originally Posted by Ed Jobe
    That explanation helps. AcadStartup will not work when a dwg 'starts up', only when the application starts up; just once. After all, its called "Acad" startup, not 'DwgStartup'. To get a sub to work when a doc is opened, you need to add code to an event handler. Depending upon what you need to do, you might choose one of the following ThisDrawing.BeginOpen, ThisDrawing.EndOpen, ThisDrawing.NewDrawing. These events need to be in a class that uses the WithEvents statement in the Declarations section.
    Please correct me if I am wrong. When I double click and open a drawing, first the AutoCAD application starts. In this case, the "acadstartup" routine should work. But it works only when I trigger any VBA related command. And acadstartup routine runs before that command is executed! This is still a confusion for me. If I am opening a drawing with an existing AutoCAD session, then I understand as you explained.
    Thanks to remind me of the drawing events. It may help me to solve this. But regarding acadstartup, I still wait for some more feed back.

    Thanks again,

    Abdul Huck

  9. #9
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    You can force vba to initialize by putting a line with "acvba.arx" in a txt file called "acad.rx". Create this with Notepad and save where acad.exe is.
    C:> ED WORKING....

  10. #10
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: VBA startup routine does not get initialized itself...

    Thanks Ed.

    Regards,
    Abdul Huck

Page 1 of 2 12 LastLast

Similar Threads

  1. Exclude layer names in S::Startup routine
    By metron4 in forum AutoLISP
    Replies: 10
    Last Post: 2011-03-09, 11:21 PM
  2. loading lisp routine at startup
    By lee.johnson in forum AutoLISP
    Replies: 22
    Last Post: 2010-09-21, 07:13 PM
  3. not initialized
    By cynthia.biacofsky in forum AutoCAD General
    Replies: 1
    Last Post: 2008-11-26, 01:45 PM
  4. Replies: 2
    Last Post: 2006-08-17, 07:39 PM
  5. Layout not initialized
    By jmorgan in forum AutoCAD Plotting
    Replies: 4
    Last Post: 2004-12-23, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •