Running .scr scripts in VBA through Access 97

Discussion in 'AutoCAD' started by stephenlecompte, Feb 4, 2005.

  1. I've got the following below code in a command button event! Basically what I'm trying to do is run a .scr script through an opened instance object of AutoCAD. I'm firing all this through an Access97 form and it seems to work fine up until the point I do a objDwg.SendCommand "script" & vbCr & txtNameFile & vbCr. Now no error message is showing at all in Access if I go ahead and remove the On Error GoTo Err_cmdAutocad statement... so I know that the VBA code is working just fine.

    It is just something in the AutoCAD instance of the object that will not continue to run the script. The first line of the script is basically opening a file. Thus you see in the code listing below, right before you run the script, you are doing a filedia and then setting it to 0.

    The next thing AutoCAD does is stop and place 'open' on one line and says it doesn't recognize the command. In this script the first line is something like open g:\pj\5500-50\mda\something.dwg
    Now my first thought looking at this is hey I don't have any quotations around the path right? But there is something else to this...
    In fact, if I type filedia or any other type of AutoCAD command it will not recognize them at all! I believe there is something else I must do besides just merely having Dim objDwg As AcadDocument / Set objDwg = New AcadDocument in order to bring up AutoCAD through VBA!

    I can post the entire script but I doubt it will help any. Here is the URL to it below.
    http://www.cadvault.com/forums/show...8635#post108635

    This has to do with the ActiveX control object that is referenced in Access!
    Has anyone here manipulated that before using VBA to run .scr scripts before? Should I use AcadApplication instead and if so what changes need to be made to duplicate the process?

    Private Sub cmdAutocad_Click()
    On Error GoTo Err_cmdAutocad

    MsgBox "You're going to have to open AutoCAD manually - type 'filedia' then '1' - go to Tools - Run Script and find: " & txtNameFile
    Exit Sub
    Dim objDwg As AcadDocument
    Set objDwg = New AcadDocument
    objDwg.Activate
    objDwg.SetVariable "FILEDIA", 0
    objDwg.SendCommand "script" & vbCr & txtNameFile & vbCr
    MsgBox "Script has been ran!"

    Exit_cmdAutocad:
    On Error Resume Next
    Exit Sub

    Err_cmdAutocad:
    MsgBox "You must have Full AutoCAD to run this and under Tools - Options... you must have Single-drawing compatibility mode checked on!"
    Call Error_Action(Err, Err.Description, "frmMainMenu @ cmdAutocad_Click")
    Resume Exit_cmdAutocad
    End Sub
     
    stephenlecompte, Feb 4, 2005
    #1
  2. Basically, you shouldn't be using scripts in the first place - convert them
    to vb/a code! There is nothing that your script does that you can't do with
    a little searching in the ng - all of the code is here.


    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Feb 4, 2005
    #2
  3. Ok so let me post a brief script here.
    What should the following look like if it were to be converted into VBA?

    open G:\pj\MDA\55015-30\xtag-07.dwg
    filedia
    0
    cmddia
    0
    -attext
    c
    I:\data\ACCESS\Template\Records\FINTAG.txt
    I:\proj\MDA\55015-30\TeamDocs\Fin-01
    -attext
    c
    I:\data\ACCESS\Template\Records\DOORTAG.txt
    I:\proj\MDA\55015-30\TeamDocs\Door-01
    -attext
    c
    I:\data\ACCESS\Template\Records\ROOMTAG.txt
    I:\proj\MDA\55015-30\TeamDocs\Xplan-01
    filedia
    1
    cmddia
    1
    quit
    y
     
    stephenlecompte, Feb 4, 2005
    #3
  4. There are always reasons why people ask for things.
    In my situation - I had an IT Manager that used Novell Zenworks to keep people from installing software on other machines. So because I didn't have full AutoCAD and go to the VBA editor screen - I needed to use what I had! I had Access97 and created a form that would perform VBA coding so I could show my worth to this architectural company.
    Here is the answer to my first question...
    I would appreciate someone taking the time to show how I can convert the above listed .scr file to what it should look like using VBA coding. Thanks to norrin radd for this piece of code.

    Private Sub Command156_Click()
    Dim acadapp As Object
    Dim acDocument As Object
    On Error Resume Next
    Set acadapp = GetObject(, "AutoCAD.application")
    If Err Then
    Err.Clear
    Set acadapp = CreateObject("AutoCAD.application")
    End If
    'you could use this to open a dwg directly
    'Set acDocument = acadapp.Documents.Open(dwgname)
    Set acDocument = acadapp.Documents.New
    acadapp.Visible = True
    acadapp.WindowState = acMax
    Set acDocument = acadapp.ActiveDocument
    acDocument.SetVariable "filedia", 0
    txtNameFile = "J:\SUPPORT\testopen.scr" 'for test
    acDocument.SendCommand "script" & vbCr & txtNameFile & vbCr
    End Sub
     
    stephenlecompte, Feb 4, 2005
    #4
  5. There are always reasons why people ask for things.
    And there are reasons why things won't work.You'll leave a far better
    impression with the company by learning what you need to do and
    implementing it properly. You've already received advice here and on
    CADVault to use straight VBA.

    Let's back up on the "why"...Using the SendCommand to run a command is
    always a bad idea because VBA will not know when the command is done and it
    is never a good idea to mix programming environments. You are magnifying
    the "bad" tenfold by trying to run a script.

    If all you know are scripts, download ScriptPro from Autodesk's website and
    use it. If you want to use VBA, read posts in this group related to
    starting AutoCAD, integrating with Access, etc. Matter of fact, there is
    even a VBA example in the AutoCAD Sample directory for dealing with
    Access. Check it out.

    *If* I have time this weekend, I'll throw something together for you. While
    Norrin's code is a start, it has issues too.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Feb 4, 2005
    #5
  6. Thank you for your reply, Mr. Tuersley.
    I appreciate it and maybe this can be a good springboard so that I could receive proper training in modifying AutoCAD correctly with using VBA.
     
    stephenlecompte, Feb 4, 2005
    #6
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.