problem with vb.net getobject

Discussion in 'AutoCAD' started by GPaolo, Mar 5, 2004.

  1. GPaolo

    GPaolo Guest

    i am beginner in vb.net and i converting my vb6 programm in vb.net.
    The first problem is that the operation getobject make always a new instance
    of autocad also if i have already open on.
    This example work but when i make cadobj.applivation.visible=true i see the
    new autocad windows with may line
    Thank's
    GPaolo

    Public Sub Main()

    On Error Resume Next



    Dim CadObj As AutoCAD.AcadApplication

    CadObj = GetObject("", "AutoCAD.Application")

    If Err.Number Then

    Err.Clear()

    CadObj = CreateObject("AutoCAD.Application.16")

    If Err.Number Then

    MsgBox(Err.Description)

    CadObj = Nothing

    Exit Sub

    End If

    End If

    On Error GoTo 0

    Dim mib As String

    Dim p1(2) As Double

    Dim p2(2) As Double

    p1(0) = 0

    p1(1) = 0

    p2(0) = 50

    p2(1) = 50

    ' the next s my instruction to insert a line

    Acint.hmInsLine(mib, p1, p2, "-1", "0", "continuous")

    CadObj.Application.Visible = True

    end sub
     
    GPaolo, Mar 5, 2004
    #1
  2. That's because it always errors out. BTW, dump the Err object and switch to
    a Try/Catch block. It'll make this sort of error quite obvious. Just place a
    breakpoint inside the Catch block.
    The problem is the above line. Check the documentation and you'll see
    GetObject returns an Object, not an AcadApplication object. Take GetObject's
    return value, feed it to CType and convert it to an AcadApplication object
    before assigning it to CadObj.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Mar 5, 2004
    #2
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.