Custom Programs

Discussion in 'AutoCAD' started by Matthew Hastings, Jan 6, 2005.

  1. Hi, I have a custom program writen in VB6 that works without a problem in AutoCad 2002. But if I run the program in AutoCad 2005 it stop in the code and I get a runtime error.

    frmProgress.ProgressBar1.Value = 27

    Application.Update
    Application.ZoomExtents <<<stops here
    Unload frmProgress
    Unload frmDrawShed

    This is the error message I get . Run-time error '-2145320932 (8021001c)':AutoCAD Main window is invisible.
    Any help would be appreciated. I have support subscription with autodesk. This is what they suggested which wasn't much help (Thank you for choosing Autodesk Subscription.

    We are unable to help you with customization issues, as the Product Support team provides support only on product related queries and we do not have the required resources to support API related queries.

    Request you to please go through Questions and Answers available at the following link

    http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=770215

    For a complete description of the new and changed objects, as well as instructions on how to migrate your VBA projects, please refer the Active X and VBA Developers Guide in the AutoCAD 2005 help files.

    You may refer to http://www.autodesk.com/adn for more details on API support.

    I am sorry for not being able to help you much on this occasion.

    Hope the above information helps.)
    This makes me wounder why I paid for support in the first place. If anyone can help me it would be much appreciated.
     
    Matthew Hastings, Jan 6, 2005
    #1
  2. Hi Matthew,

    In addition, they could have told you that you can join the Autodesk
    Developers Network where you can get support for things like this. (Cost
    may be prohibitive for an individual.)

    However, their advice to come here is sensible as there are many users here
    who will try to help.

    Most likely you will find that your VB code has a reference to the R2000
    format drawing objects.

    In later versions of AutoCAD you will need a reference to the R2004 format
    drawing objects.

    Open your VB project and check the references. Compile the file under a
    suitable name to distinguish it from the original.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    AutoCad 2002. But if I run the program in AutoCad 2005 it stop in the code
    and I get a runtime error.
    (8021001c)':AutoCAD Main window is invisible.
    This is what they suggested which wasn't much help (Thank you for choosing
    Autodesk Subscription.
    Support team provides support only on product related queries and we do not
    have the required resources to support API related queries.
    instructions on how to migrate your VBA projects, please refer the Active X
    and VBA Developers Guide in the AutoCAD 2005 help files.
    can help me it would be much appreciated.
     
    Laurie Comerford, Jan 7, 2005
    #2
  3. Do you have an active document at the time of the zoom ??
     
    Jorge Jimenez, Jan 7, 2005
    #3
  4. Hi Jorge, no at the time the program is run all that is active is AutoCad 2005, the form from the program, and a progress bar. I have tried unloading the form and progress bar before zooming but it get the error.
     
    Matthew Hastings, Jan 7, 2005
    #4
  5. Hi Laurie, do you mean in the visual basic editor, tools menu, reference I had a look there but I couldn't find R2000
    format drawing objects or R2004 format drawing objects. In the list. Is this the spot you are talking about I'm still learning. Thanks.
     
    Matthew Hastings, Jan 7, 2005
    #5
  6. Hi Laurie, had alook at you companys web site it mentions training just woundering what AutoCad and Visual basic training courses you have in Melbourne ?
     
    Matthew Hastings, Jan 7, 2005
    #6
  7. What Jorge meant was is there a drawing open. If no drawing is open, then
    you can't do a zoom extents.

    You also need to show more code. For example what is Application and how do
    you set it? By default, Application is the program you are runnning which
    would be your VB6 app [or are you really in VBA?]; Application would not be
    AutoCAD.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jan 7, 2005
    #7
  8. Yes there is a drawing open after the program stops. you can zoom from the command line. I've posted more code I hope it helps.

    Private Sub Form_Load()

    frmDrawShed.Caption = "Draw Shed Ver - " & App.Major & "." & App.Minor & "." & App.Revision

    On Error Resume Next
    'Get the AutoCad Application
    Set acadApp = GetObject(, "AutoCAD.Application")
    If Err Then
    Err.Clear
    'Start AutoCAD
    Set acadApp = CreateObject("AutoCAD.Application")
    acadApp.Visible = True
    If Err Then
    MsgBox Err.Description
    Exit Sub
    End If
    End If
    Set acadDoc = acadApp.ActiveDocument
    Set ModelSpace = acadDoc.ModelSpace

    cmbColumnType.SetFocus
    NumBay = txtNumBays.text
    UpDown1.Max = NumBay


    ShedWidth = txtShedWidth
    ReDim BaySize(4)
    NumBay = 4
    BaySize(1) = 6000: BaySize(2) = 6000: BaySize(3) = 6000: BaySize(4) = 6000

    ReDim MullSizeA(2)
    MullNumA = 1
    MullSizeA(1) = 5835
    MullSizeA(2) = 5835
    ReDim MullSizeB(2)
    MullNumB = 1
    MullSizeB(1) = 5835
    MullSizeB(2) = 5835

    Private Sub cmdDraw_Click()
    Dim pnt1(0 To 2) As Double
    Dim n As Integer
    Dim MullTotal As Double
    Dim MullTotalB As Double

    pnt1(0) = 0: pnt1(1) = 0
    If Not CheckBaySize() Then
    MsgBox "There is a Zero value in the Bay Size." & Chr(10) & "You should correct the error.", 48
    txtBaySize.SetFocus
    Exit Sub
    End If

    SWidth = 0
    SWOver = 0
    For n = 1 To cmbMullNumbera + 1
    SWidth = SWidth + MullSizeA(n)
    Next n
    If SWidth > txtShedWidth Then
    SWOver = SWidth - txtShedWidth
    MsgBox "The Mullion spacings(c) exceed the Shed Width by " & SWOver
    Exit Sub
    End If
    SWidth = 0
    SWOver = 0
    For n = 1 To cmbMullNumberb + 1
    SWidth = SWidth + MullSizeB(n)
    Next n
    If SWidth > txtShedWidth Then
    SWOver = SWidth - txtShedWidth
    MsgBox "The Mullion spacings(d) exceed the Shed Width by " & SWOver
    Exit Sub
    End If
    SWidth = 0
    SWOver = 0
    If chkPropCleat = vbChecked Or chkPropCleat = True Then
    If cmbPropNoHoles = "" Then
    MsgBox "Please choose the Cleat Size", vbOKOnly
    Exit Sub
    End If
    End If

    If optMSYes = True Then
    If Left(cmbColumnType, 1) <> "C" Then
    MsgBox "You can only rotate 'C' Section Columns"
    Exit Sub
    End If
    If optColumnSameNo = True Then
    If Left(cmbColumnType, 1) <> "C" Then
    MsgBox "You can only rotate 'C' Section Columns"
    Exit Sub
    End If
    End If
    End If

    If optMSYes = True Then
    If Left(cmbMullionType, 1) <> "C" Then
    MsgBox "You can only rotate 'C' Section Mullions"
    Exit Sub
    End If
    End If

    frmProgress.Show
    frmProgress.ProgressBar1.Max = 27
    frmProgress.ProgressBar1.Value = 1
    SaveBackup
    frmProgress.ProgressBar1.Value = 2
    SetShedVars
    frmProgress.ProgressBar1.Value = 3
    SetDrawingVars
    frmProgress.ProgressBar1.Value = 4
    DrawShedStructual
    frmProgress.ProgressBar1.Value = 21
    DrawShedFloorPlan
    If optMSYes = True Then
    RollerDoors
    End If
    frmProgress.ProgressBar1.Value = 26
    OffsetBlocks
    frmProgress.ProgressBar1.Value = 27

    Application.Update
    Application.ZoomExtents >>>>stops here
    Unload frmProgress
    Thanks,
    Matt
     
    Matthew Hastings, Jan 7, 2005
    #8
  9. Try this to see what happens.
    Maybe ACAD is still busy when you issue the zoomextents
    If so, a check for no activity (IsQuiescent = True) would be a good idea
    before doing the zoom.
     
    Jorge Jimenez, Jan 7, 2005
    #9
  10. Hi Matthew,

    We do a one day introduction to VBA course and a whole range of Land
    Desktop, Civil Design, Survey, Civil 3D courses as well as training in our
    own software.

    Any further discussion on this is not appropriate in the public NG. Please
    write to to get further details.


    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au




    woundering what AutoCad and Visual basic training courses you have in
    Melbourne ?
     
    Laurie Comerford, Jan 7, 2005
    #10
  11. Hi, I removed the application.update and add the code before zoom but i still have the same problem it stops at zoomextents. Thanks for your help.

    Matt.
     
    Matthew Hastings, Jan 11, 2005
    #11
  12. Just to be sure, is the acad window visible at the time ??
    Is the active document (dwg) visible??
     
    Jorge Jimenez, Jan 11, 2005
    #12
  13. BTW, have you tried making the acad windows the top window
    using the system API call

    Public Const SWP_NOMOVE = 2
    Public Const SWP_NOSIZE = 1
    Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2

    Declare Function SetWindowPos Lib "User32" _
    (ByVal hwnd As Long, _
    ByVal hWndInsertAfter As Long, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, _
    ByVal wFlags As Long) As Long

    SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS) before doing any zoom
    ???
     
    Jorge Jimenez, Jan 11, 2005
    #13
  14. I had a second look at the program reference you were right. I didn't see it the first time I looked. Feel pretty stupid anyway thanks a bunch.

    Kind Regards,
    Matt
     
    Matthew Hastings, Jan 12, 2005
    #14
  15. Matthew Hastings

    Jackrabbit Guest

    Hi Matthew,

    I had similar problems with several programs that I had written in Delphi. They ran fine in AutoCAD 2000 but would cause AutoCAD 2005 to throw and exception--usually before/after Saves, Regens, and Zooms. It appears that the out-of-process automation controller is getting ahead of AutoCAD. I added code to check the state of AutoCAD before/after Saves, Regens, and Zooms and that seems to have eliminated the freeze-ups.

    Here's my code in Delphi and a VB version (which I didn't test):
    [pre]
    // Delphi
    procedure WaitForAcad( const Acad : AcadApplication );
    var
    IsIdle : Boolean;
    State : AcadState;
    begin
    State := Acad.GetAcadState;
    IsIdle := False;
    repeat
    IsIdle := State.IsQuiescent;
    until IsIdle;
    end;

    ' Visual Basic
    Public Sub WaitForAcad( Acad As AcadApplication )
    Dim IsIdle As Boolean
    Dim State As AcadState

    State = Application.GetAcadState;
    IsIdle = False;
    Do
    IsIdle = State.IsQuiescent;
    Loop Until IsIdle;
    End Sub

    ' In your code...
    WaitForAcad Application
    Application.ZoomExtents
    [/pre]

    There may be a better method of resolving this problem but the above solution works and got my users up and running for the time being.
     
    Jackrabbit, Jan 12, 2005
    #15
  16. Hi, Thanks for the code I wil give it a try. I've had some luck with changing the program references in some of my programs to get them going.Thanks.

    Matt.
     
    Matthew Hastings, Jan 13, 2005
    #16
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.