api net 2005

Discussion in 'AutoCAD' started by GPaolo, Jul 30, 2004.

  1. GPaolo

    GPaolo Guest

    I want write an application using the new api 2005 for .net but don't
    understand in which mode i can try before compiling .
    in VS2003 when i make F8 the system say me :
    you cannot run a library project.You must create a new project with a sub
    main with a reference to the library but also in this mode the program stop
    when try to reference a api net acad2005 .
    Thank's
    GFranco
     
    GPaolo, Jul 30, 2004
    #1
  2. GPaolo,

    Create a quick mode in VB6 that opens autocad and draws a Circle. Now open
    this file in VB.NET following upgrade process. Everything will be created
    for you except...

    Dim circleObj As AcadCircle
    'Should be ....
    Dim circleObj As Autodesk.AutoCAD.Interop.Common.AcadCircle

    You will also need to add references...

    Also..... Don't use values without dimensioning them... 'NET will warn you
    but let you get away with it in VB. Good Pratice in any language anyway.

    Dim one As Integer : one = 1
    P(0) = one
    Not...
    P(0) = 1

    Good Luck,
    Paul

    If you need a vb6 mode, I'll send you one.
     
    Paul Richardson, Jul 30, 2004
    #2
  3. Whoa, wait a minute - you're making it extremely hard than it has to be :)
    Just add the proper IMPORTS statements and COM references and it can work
    just like vb6. Importing is so-so and I wouldn't recommend it.

    GPaolo's question is how to use managed code which is WAY different than
    vb6. Below are examples for both methods. Just create a Windows
    application, add 2 buttons to the form. Past the code below into different
    modules and have the buttons call them. Treat the code as a roadmap because
    I haven't tested them - just wrote them up real quick.

    'USING COMINTEROP - OLD VB6 METHODS
    'add reference to AutoCAD by using the COM
    'tab in the Reference dialog box just like
    'ini VB6
    Imports System.Runtime
    Imports System.Runtime.InterOpServices
    Imports System.Runtime.InterOpServices.Marshal
    'hooks to AutoCAD's COM interface - required at this time
    Imports Autodesk.AutoCAD
    Imports Autodesk.AutoCAD.Interop
    Imports Autodesk.AutoCAD.Interop.Common

    Module AutoCADCalls
    Public m_oMSpace As AcadModelSpace

    Public Sub DrawLine()
    If Connect2ACAD Then
    Dim oLine As AcadLine
    Dim dSPt(2) As Double
    Dim dEPt(2) As Double
    dSpt(0) = 10 : dSpt(1) = 10 : dSpt(2) = 0
    dEpt(0) = 10 : dEpt(1) = 10 : dEpt(2) = 0
    oLine = m_oMSpace.AddLine(dSpt, dEpt)
    End If
    End Sub

    Public Function Connect2ACAD() As Boolean
    '+-- establish link to AutoCAD - the graphical session
    Dim oApp As AcadApplication
    Dim oDoc As AcadDocument
    Try
    ''get existing
    oApp = GetActiveObject("AutoCAD.Application")
    Catch
    'no existing so create
    oApp = New AcadApplication
    Finally
    m_oMSpace = m_cadDoc.ModelSpace
    Connect2ACAD = true
    End Try
    End Function
    End Module

    'USING MANAGED API
    'add references to acmgd.dll and acdbmgd.dll files by BROWSING
    'to the install directory of AutoCAD 2005
    Imports System
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports System.Reflection

    Module AutoCAD_Line
    'this method will be automatically hooked
    'into the AutoCAD Command interpreter
    <CommandMethod("LLINE")> _
    Public Shared Sub LLineCommand()
    Dim db As Database =
    Application.DocumentManager.MdiActiveDocument.Database
    Dim tm As DBTransMan = db.TransactionManager
    'start a transaction
    Dim myT As Transaction = tm.StartTransaction()
    Try
    'create a line
    Dim line As New Line(New Point3d(0, 0, 0), New Point3d(1, 1, 0))
    Dim bt As BlockTable = CType(tm.GetObject(db.BlockTableId,
    OpenMode.ForRead, false), BlockTable)
    Dim btr As BlockTableRecord =
    CType(tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite,
    false), BlockTableRecord)
    'add it to the model space block table record
    btr.AppendEntity(line)
    'make sure that the transaction knows about this new object
    tm.AddNewlyCreatedDBObject(line, true)
    Finally
    myT.Dispose()
    End Try
    End Sub
    End Module

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jul 31, 2004
    #3
  4. Thanks, Mike. Looks like I figured it out the hard way.
     
    Paul Richardson, Jul 31, 2004
    #4
  5. GFranco,

    I didn't mean to say do this all the time. It's just how I started and
    seemed like the
    eaisest way to jump to NET, for me, and see the differences. Not to say I
    have figured them
    all out yet. I should have left this question to someone more
    experianced...Mike...Thanks.
     
    Paul Richardson, Jul 31, 2004
    #5
  6. Thanks, Mike. Looks like I figured it out the hard way.
    Leat you got there Paul =)

    One final word of note: I failed to mention that doing the com method and
    treating it like vb6 will work but you don't gain the benefits of .net -
    you need to learn inheritance, polymorphism, etc. to reap the benefits.
    Otherwise, its kinda like using vb6 with all sendcommands =(

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jul 31, 2004
    #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.