How to load a project via VBE?

Discussion in 'AutoCAD' started by MP, Jul 22, 2004.

  1. MP

    MP Guest

    The help on vbe says to add a project to the projects collection
    (which I assume is the same as loading a dvb via vbaman load)
    to use the add method of the projects collection

    Dim oNewProj As VBProject
    Set oNewProj = VBE.VBProjects.Add(vbext_pt_StandAlone)

    this gives error runtime error 440
    method add of vbprojects failed

    even if it succeeded I don't see how to pass it the file name to load a
    specific project

    any one tried this?

    I know Ed Jobe is the master of the VBE so maybe he knows?

    maybe this only works in vb6, not vba autocad
    since the constant doesn't sound right for a dvb file

    tia
    Mark Propst
     
    MP, Jul 22, 2004
    #1
  2. MP

    Mark Propst Guest

    well, now trying it on vb6 and i cant' even get the vbe object
    this works in vba autocad but not vb6
    what am i missing?
    Sub CountModules()
    Dim iNumModules As Integer
    iNumModules = Application.VBE.CodePanes.Count
    Debug.Print "There are " & iNumModules & " modules"

    End Sub

    i get variable not defined at "Application"
    in the line
    iNumModules = Application.VBE.CodePanes.Count

    i have the 'vbaext5.3' lib referenced ok
    i am testing in a std module in a std exe proj
    running it in the ide via f5
    statup object sub Main
    Sub main()
    'test
    'CountLines
    CountModules

    End Sub
    Sub CountModules()
    Dim iNumModules As Integer
    'iNumModules = Application.VBE.CodePanes.Count ' variable not defined
    "Application"
    'iNumModules = VBE.CodePanes.Count ' variable not defined
    VBE"
    iNumModules = VBIDE.CodePanes.Count 'method or data member
    not found "VBIDE"

    Debug.Print "There are " & iNumModules & " modules"

    End Sub


    what's weird is this works in acad vba
    iNumModules = Application.VBE.CodePanes.Count
    in fact it works even without the vbaext5.3 lib referenced
    i don't see how that works?


    any help out there?
    tia
    mark
     
    Mark Propst, Jul 22, 2004
    #2
  3. MP

    Mark Propst Guest

    continuing my one sided conversation!
    I can connect to acad with vb6, and get acad's vbe
    but I still cant see how to redirect back to the "vb6 ide itself" to,
    for example, list the modules, projects etc
    Sub main()
    Dim oAcad As AcadApplication
    Set oAcad = GetAcad2;function that finds acad and returns the application
    object

    Dim oVbe As VBE
    Set oVbe = oAcad.VBE

    'revised module to take an arg of the vbe to act on
    CountModules oVbe

    End Sub

    Sub CountModules(oVbe As VBE)
    Dim iNumModules As Integer
    iNumModules = oVbe.CodePanes.Count
    Debug.Print "There are " & iNumModules & " modules"
    Dim i As Long
    For i = 1 To iNumModules
    Debug.Print oVbe.VBProjects.Item(i).Name
    Next i
    End Sub
     
    Mark Propst, Jul 22, 2004
    #3
  4. MP

    wivory Guest

    I'm not clear what it is you're actually trying to achieve Mark, but you can do the following in AutoCAD's VBA IDE:

    Code:
    Set CurrentProject = ThisDrawing.Application.VBE.ActiveVBProject
    LoadDVB "NewProject.dvb"
    Set NewProject = ThisDrawing.Application.VBE.VBProjects(ThisDrawing.Application.VBE.VBProjects.Count)
    
    HTH

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jul 22, 2004
    #4
  5. MP

    MP Guest

    That's it!
    I didn't know about the LoadDVB command(or statement).
    I wonder what the .Add method on the .VBProjects collection is for then???
    any thoughts?

    background:
    I'm trying to do some cleanup on my toolbox utilities functions.
    I have a multitude of .bas and .cls modules that deal with specific areas.
    For example BlockFuncs.bas has subs and functions relating to blocks and
    inserts.
    If a project needs to read attribute values for example I would, in the
    past, import the blockfuncs module and then have the subs available to call.

    However, all my utilities are evolving over time as I add functions as I
    come upon the need for a certain function, and frequently while working on
    some project, I'll need an abiltiy that lends itself to being a re-usable
    utility function, so while working on the project I'll also edit the utility
    mods that are being used - eg BlockFuncs.bas.

    But with vba, if I edit the blockFuncs mod while working on the project, in
    the past I didn't know to export the file back to disk.
    So the possibility exists that in some old forgotten project from the past I
    may have imported BlockFuncs.bas, added some sub or other, and now the one
    on disk doesn't have that sub in it.
    So with the intent of not losing some already written piece of code, I want
    to make sure that all versions of BlockFuncs (etc) have the same content.

    What I want to do is load each dvb in my folder in turn.
    Get list of all the 'modules' in each dvb.
    See if, for example BlockFuncs is included in that project
    If it is, get a list of all the subs/funcitons defined in it,
    compare that list to the list of subs in the current disk version of
    BlockFuncs,
    And then if any useful subs are found hiding out there, I can add them to
    the disk version.

    I need to reorganize how I work in vba to use the reference technique
    instead of importing modules into the project. once I'm sure all the work
    i've done in the past is safely collected into one place(in the disk files)
    then I can recompile my utilities dll which will have BlockFuncs and all the
    others in it, and reference that into projects rather than importing the
    modules directly any more.


    Does that just sound way too crazy?

    anyway, thanks for the tip on LoadDvb

    also curious is that I can use vbe in acad vba but cant' seem to get it to
    work in vb6
    is there another trick i need to know?
    or does vbe only work with vba and not with full vb?
    I guess that makes sense since it's the ms*vba* extensibility reference.

    so in vb6 is there no way to use the vbe to read or edit code modules?

    Mark


    can do the following in AutoCAD's VBA IDE:
     
    MP, Jul 22, 2004
    #5
  6. MP

    Ed Jobe Guest

    The ide object model for vb is different than the ide object model for vba.
    But they have conflicting class names, so you shouldn't even be able to
    reference the vbaide from vb if you are trying to reference them at the same
    time. Create an addin. Create a new project using the addin wizard. In the
    project browser, dc on the addin designer and change the type from vb to
    vba.

    --
    ----
    Ed
    ----
     
    Ed Jobe, Jul 22, 2004
    #6
  7. <eek>

    Mark, you *are* aware that you can use an external .dvb as a reference, and
    then create objects in the main dvb from the referenced classes? There is no
    need to *import* a class simply to use it in a main project.

    Seems to me that Ed and I posted on this not too long ago. Try a search, or
    I'll post back here later if you haven't found it.

    --
    R. Robert Bell


    That's it!
    I didn't know about the LoadDVB command(or statement).
    I wonder what the .Add method on the .VBProjects collection is for then???
    any thoughts?

    background:
    I'm trying to do some cleanup on my toolbox utilities functions.
    I have a multitude of .bas and .cls modules that deal with specific areas.
    For example BlockFuncs.bas has subs and functions relating to blocks and
    inserts.
    If a project needs to read attribute values for example I would, in the
    past, import the blockfuncs module and then have the subs available to call.

    However, all my utilities are evolving over time as I add functions as I
    come upon the need for a certain function, and frequently while working on
    some project, I'll need an abiltiy that lends itself to being a re-usable
    utility function, so while working on the project I'll also edit the utility
    mods that are being used - eg BlockFuncs.bas.

    But with vba, if I edit the blockFuncs mod while working on the project, in
    the past I didn't know to export the file back to disk.
    So the possibility exists that in some old forgotten project from the past I
    may have imported BlockFuncs.bas, added some sub or other, and now the one
    on disk doesn't have that sub in it.
    So with the intent of not losing some already written piece of code, I want
    to make sure that all versions of BlockFuncs (etc) have the same content.

    What I want to do is load each dvb in my folder in turn.
    Get list of all the 'modules' in each dvb.
    See if, for example BlockFuncs is included in that project
    If it is, get a list of all the subs/funcitons defined in it,
    compare that list to the list of subs in the current disk version of
    BlockFuncs,
    And then if any useful subs are found hiding out there, I can add them to
    the disk version.

    I need to reorganize how I work in vba to use the reference technique
    instead of importing modules into the project. once I'm sure all the work
    i've done in the past is safely collected into one place(in the disk files)
    then I can recompile my utilities dll which will have BlockFuncs and all the
    others in it, and reference that into projects rather than importing the
    modules directly any more.


    Does that just sound way too crazy?

    anyway, thanks for the tip on LoadDvb

    also curious is that I can use vbe in acad vba but cant' seem to get it to
    work in vb6
    is there another trick i need to know?
    or does vbe only work with vba and not with full vb?
    I guess that makes sense since it's the ms*vba* extensibility reference.

    so in vb6 is there no way to use the vbe to read or edit code modules?

    Mark


    can do the following in AutoCAD's VBA IDE:
     
    R. Robert Bell, Jul 22, 2004
    #7
  8. MP

    MP Guest

    cool, I'll check that out
    Thanks
    Mark

     
    MP, Jul 22, 2004
    #8
  9. MP

    MP Guest

    Yes, I do know that *now*!
    Only I didn't know that a couple years ago when I started trying to learn vb

    So now I just wanted to look back through old dvbs, check the imported
    versions, make sure I've got all subs worth keeping, then I can rebuild the
    dvbs using the reference technique.

    I am grateful to you and Ed for pointing out the error of my sinful ways of
    the past and am endeavoring to change my behaviour!
    :)
    it's just so hard for an old dog...
    Mark
     
    MP, Jul 22, 2004
    #9
  10. <whew> I *thought* you knew, but you never know what you don't know, unless
    you know. Or know. <rambling>

    --
    R. Robert Bell


    Yes, I do know that *now*!
    Only I didn't know that a couple years ago when I started trying to learn vb

    So now I just wanted to look back through old dvbs, check the imported
    versions, make sure I've got all subs worth keeping, then I can rebuild the
    dvbs using the reference technique.

    I am grateful to you and Ed for pointing out the error of my sinful ways of
    the past and am endeavoring to change my behaviour!
    :)
    it's just so hard for an old dog...
    Mark
     
    R. Robert Bell, Jul 22, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.