Editing AutoCad Drawing from Microsoft Access

Discussion in 'AutoCAD' started by SushilS, Aug 5, 2004.

  1. SushilS

    SushilS Guest

    I am opening AutoCad drawing from Microsoft Access. I have routine written in MS Access to open a AutoCad drawing and select objects and edit the required objects. It works when I open Microsoft Access for first time and clicks the button but if I click button again it does not select the required objects even if the AutoCad application is closed. If I close both Access and AutoCad again it works.
    While debugging I noticed that when I use breakpoint This program works fine but once I remove the breakpoint it start doing the same thing. Do I need reset some variable or what.


    Can anybody help me on this.
    Thanks,

    Dim acadapp As Object
    Dim acDocument As Object
    Dim aCIR2 As AcadCircle
    Dim objcircle As AcadCircle
    Dim objss As AcadSelectionSet
    Dim intcodes(0) As Integer
    Dim varcodevalues(0) As Variant
    Dim filintcodes As Variant
    Dim filvarcodevalues As Variant
    On Error Resume Next
    Set acadapp = GetObject(, "AutoCAD.application")
    If Err Then
    Err.Clear
    Set acadapp = CreateObject("AutoCAD.application")
    End If
    acDocument = acadapp.documents.Open("C:\Documents and Settings\Sushil\Desktop\149700-322.dwg")
    acadapp.Visible = True




    'acadapp.LoadDVB ("C:\Documents and Settings\Sushil\Desktop\acad.dvb")

    'On Error Resume Next
    'Err.Clear
    'UserForm1.Hide

    intcodes(0) = 0
    varcodevalues(0) = "CIRCLE"
    filintcodes = intcodes(0)
    filvarcodevalues = varcodevalues(0)
    Set objss = ActiveDocument.SelectionSets.Add("trpotpfiltercodet")
    objss.Select acSelectionSetAll, , , intcodes, varcodevalues
    objss.Highlight True
    For Each objcircle In objss

    If objcircle.Handle = "20CBC" Then
    Set aCIR2 = ActiveDocument.HandleToObject("20CBC")
    aCIR2.Radius = 2.25
    aCIR2.Update
    MsgBox "done"

    End If

    Next
    ActiveDocument.SelectionSets.Item("trpotpfiltercodet").Delete

    Set aCIR2 = Nothing
    Set objss = Nothing
    Set acDocument = Nothing
    Set acadapp = Nothing

    'acadapp.UnloadDVB
    End Sub
     
    SushilS, Aug 5, 2004
    #1
  2. SushilS

    Norman Yuan Guest

    Access VBA, not like Acad VBA, is pretty tough to runtime error: in Acad
    VBA, if you get unhandled runtime error, you get kicked out your VBA app. In
    Access, it is often not the case: your form is still there, but the button
    that runs the offensive code stops working, just as what you see: first
    click is working and then stoped working until you rerun the Access form.
    The offending line of code, from what I can see, is right after you updated
    the circle (that is why you saw te circle is updated after the first click
    but not working thereafter):

    ActiveDocument.SelectionSets.Item("trpotpfiltercodet").Delete

    Here Access cannot recognize what "ActiveDocument" is. If you put a msgbox
    before and after this line of code and run it, you can tell where the code
    is stoped. Also, I doubt you can step through the error in debugging mode.

    It should be:

    acDocument.SelectionSets.Item(.....).Delete



    in MS Access to open a AutoCad drawing and select objects and edit the
    required objects. It works when I open Microsoft Access for first time and
    clicks the button but if I click button again it does not select the
    required objects even if the AutoCad application is closed. If I close both
    Access and AutoCad again it works.
    fine but once I remove the breakpoint it start doing the same thing. Do I
    need reset some variable or what.
     
    Norman Yuan, Aug 5, 2004
    #2
  3. SushilS

    SushilS Guest

    Re: Selecting Entities in AutoCAD from MicroSoft Access
    Thanks! NORMAN , I fixed it. Info was of great help. I edited the code now its working.

    Private Sub Command144_Click()
    Dim acadapp As Object
    Dim acDocument As Object
    Dim aCIR2 As AcadCircle
    Dim objcircle As AcadCircle
    Dim objss As AcadSelectionSet
    Dim intcodes(0) As Integer
    Dim varcodevalues(0) As Variant
    Dim filintcodes As Variant
    Dim filvarcodevalues As Variant

    On Error Resume Next
    Set acadapp = GetObject(, "AutoCAD.application")
    If Err Then
    Err.Clear
    Set acadapp = CreateObject("AutoCAD.application")
    End If

    Set acDocument = acadapp.documents.Open("C:\Documents and Settings\Sushil\Desktop\149700-322.dwg")
    acadapp.Visible = True








    'acadapp.LoadDVB ("C:\Documents and Settings\Sushil\Desktop\acad.dvb")




    intcodes(0) = 0
    varcodevalues(0) = "CIRCLE"

    filintcodes = intcodes(0)
    filvarcodevalues = varcodevalues(0)
    Set objss = acDocument.SelectionSets.Add("trpotpfiltercodet")
    objss.Select acSelectionSetAll, , , intcodes, varcodevalues
    objss.Highlight True

    For Each objcircle In objss
    'MsgBox objcircle.Handle
    If objcircle.Handle = "20CBC" Then
    Set aCIR2 = acDocument.HandleToObject("20CBC")
    aCIR2.Radius = 2.25
    aCIR2.Update
    ' MsgBox "done"

    End If

    Next

    acDocument.SelectionSets.Item("trpotpfiltercodet").Delete

    Set aCIR2 = Nothing
    Set objss = Nothing
    Set acDocument = Nothing
    Set acadapp = Nothing


    'acadapp.UnloadDVB

    End Sub
     
    SushilS, Aug 5, 2004
    #3
  4. It's also a good idea to remember to turn your error handling back on. See
    below.
    --
    John Goodfellow
    irtfnm
    use john at goodfellowassoc dot com


    ' add this line
    On Error GoTo 0 ' turn the default error handler back on
     
    John Goodfellow, Aug 6, 2004
    #4
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.