Selecting Entities in AutoCAD from MicroSoft Access

Discussion in 'AutoCAD' started by SehgalS, Aug 3, 2004.

  1. SehgalS

    SehgalS Guest

    I am having problem in updating the objects in the selection sets in the AutoCad Drawing from Microsoft form. I can open the drawing from Access but couldnt select the objects in the drawing until I type VBALOAD command in command line and select the .dvb file. once I do this then whenever I try to run the code from access it updates the entities values.
    Could anyone help in how can I fully automize this program, so that I dont have to type VBALOAD command in autocad.

    Private Sub Command144_Click()
    Dim acadapp As Object
    Dim acDocument As Object




    Dim acdobj As AcadObject
    Dim objentity As AcadEntity
    Dim varpick As Variant
    Dim strobjname As String
    Dim objlayer As AcadLayer
    Dim aCIR1 As AcadCircle
    Dim aCIR2 As AcadCircle
    Dim objcircle As AcadCircle
    Dim var As Variant
    Dim objss As AcadSelectionSet
    Dim intcodes(0) As Integer
    Dim varcodevalues(0) 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\myname\Desktop\abb.dwg")
    acadapp.Visible = True



    acadapp.LoadDVB ("C:\Documents and Settings\myname\Desktop\Project.dvb")


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


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

    Set objss = ActiveDocument.SelectionSets.Add("trpotpfiltercodet")

    MsgBox "Select Entity"
    objss.Select acSelectionSetAll, , , intcodes, varcodevalues
    MsgBox "objss"
    objss.Highlight True




    For Each objcircle In objss
    Dim cname As String
    cname = "Object Name: " & objcircle.Name & vbCrLf
    MsgBox objcircle.Handle

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

    End If

    Next

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


    'If objentity.ObjectName = "AcDBLine" Then

    'MsgBox objentity.Length
    'Set aline, varpick)


    'MsgBox aline("AcDBLine").Length
    'MsgBox aline.ObjectName
    'MsgBox objentitey.Handle
    'End If



    'Set aline = ThisDrawing.Utility.GetEntity


    'objentity.Handle2,152E

















    acadapp.UnloadDVB


    End Sub
     
    SehgalS, Aug 3, 2004
    #1
  2. SehgalS

    MP Guest

    looks like you're on pre-2004?
    do you have an acad.rx file?
    on your search path?

    with the line:

    acadvba.arx

    that will initialize the vba environment on startup

    I'm assuming that's all you're doing by loading the .dvb file?
    It looks like your code is in your access vba module?

    AutoCad Drawing from Microsoft form. I can open the drawing from Access but
    couldnt select the objects in the drawing until I type VBALOAD command in
    command line and select the .dvb file. once I do this then whenever I try to
    run the code from access it updates the entities values.
    have to type VBALOAD command in autocad.
     
    MP, Aug 3, 2004
    #2
  3. That'll work but it'd be like throwing gasoline on a fire because it just
    perpetuates the real problem: why does a dvb need loaded in the first
    place? You're already running AutoCAD from Access so everything in the dvb
    you're trying to load can just be placed within the Access code.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 4, 2004
    #3
  4. SehgalS

    SushilS Guest

    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
    #4
  5. SehgalS

    MP Guest

    if the code you posted is working then apparently it's not necessary to put
    the arrays into variants
    since you're not using the variants you could eliminate those lines
    I always thought it was necessary to put them in variants as well, and
    that's what i've always done
    I thought I had tried it the way you show it and it didn't work
    But if it's working for you it must have been something else.
    I'll stop doing that double work now!
     
    MP, Aug 5, 2004
    #5
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.