VB? VBA? Visual Studio (.net) (2005) Waht App should I use?

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

  1. Dan

    Dan Guest

    I am looking to purchse a new softwar package to start learning to write
    VB(A) for AutoCAD.
    If my understanding is correct, there are resources that are needed for more
    complicated coding that requires more than just the VBA that can be written
    with the Visual Basic editor that comes with AutoCAD 2005.

    Any suggestions would be appreciated. Thanks.
     
    Dan, Jul 30, 2004
    #1
  2. First off you don't need to buy anyhing to write vba - AutoCAD, Word,
    Excel, Access all have their own editing environment built in. Since you're
    learning, I'd stick to them before you try anything else. Go to your
    library and pickup VBA for Dummies to get started. Once you decide to
    branch out into the non-vba world, you can use SharpDevelop to write VB.NET
    and C#.NET - and its FREE TOO! You just need to download the Microsoft .NET
    SDK and the .NET Framework - both free as well.

    -- 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
    #2
  3. Dan

    JavaAndC# Guest

    Mike,

    Do you know of any references for AutoCAD apps written in C#? I just need some basic info. I used to work with VBA and would prefer not to go back to it.

    Thank you
    Tom
     
    JavaAndC#, Aug 20, 2004
    #3
  4. Dan

    bcoward Guest

    I don't know of many samples for C# other than what AutoDesk put out in the last event. If you would be specific I would share some of my C# code if it fits.

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Aug 21, 2004
    #4
  5. Bob, Any c# samples you could share would be helpful...Tks.
    the last event. If you would be specific I would share some of my C# code
    if it fits.
     
    Paul Richardson, Aug 21, 2004
    #5
  6. Dan

    bcoward Guest

    Paul,

    I'm making a little snippet post because I'd like Anne to suggest where and how we apply this type of information exchange.

    I'm posting the following C# snippet to support that request I made to find Dot Net a home on the discussion list. The following snippet doesn't have a home in this discussion area. It not ObjectA specific, VBA, or VB(Classic) and will probably make some scream OT, OT. Others might also feel this is completely confusing and again OT.

    Comments Anne? I think there is at this time a relatively small handfull of people who really want to focus on this area but could escalate quickly as companies upgrade.


    static void Main()
    {
    Application.Run(new Form1());
    }

    private void AddLine_Click(object sender, System.EventArgs e)
    {
    //' COMMENTS : Every time you press the button "AddLine" a new line is
    //' added to your Drawing.
    //' All these lines are drawn one over the other so you see
    //' only one line in your screen.
    //' If you like, you can make your code more clever
    //' e.g. changing the StartPoint or EndPoint
    //' every time this Click event is called.
    //'
    //' Define a new object as Line
    CITestLib.CILINE Entity;
    //'
    //' Call method AddCircle to add a circle to the
    //' entities collection of the Document.
    //' The parameters you pass are center coordinates and radius
    //'
    Entity = CITestLib.ActiveDocument.Entities.AddLine(new object[] {-5, -5}, new object[] {5, 5});
    Entity.PenColor = CITestLib.Constants.CIColorGreen;
    Entity.Invalidate();

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Aug 21, 2004
    #6
  7. If you are looking for anything specific, let me know. I don't know of
    anything on the market yet except for ADN. I'm working on a compilation at
    the moment that I hope to get published.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 21, 2004
    #7
  8. While its written in C#, it's not really the focus of the group you are
    asking for because its just suped up VB. If we're going to have a C#
    specific area it should be geared toward using the managed .net not the
    com. If its com, this is still the right location.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 21, 2004
    #8
  9. Bob, Thanks so much...There have started to be some c# posts in "objectarx"
    group...Not much though...
    and how we apply this type of information exchange.
    find Dot Net a home on the discussion list. The following snippet doesn't
    have a home in this discussion area. It not ObjectA specific, VBA, or
    VB(Classic) and will probably make some scream OT, OT. Others might also
    feel this is completely confusing and again OT.
    of people who really want to focus on this area but could escalate quickly
    as companies upgrade.
    {-5, -5}, new object[] {5, 5});
     
    Paul Richardson, Aug 21, 2004
    #9
  10. I have figured out how to make COM calls...It's managed code I am still
    learning..(alright haven't learned yet...:)) Knew it was off subject for
    this group... but sometimes ya just gotta take a chance..ha...

    Maybe we could adopt managed c# as a pet sub_group for this one...With all
    the off topic bs we all put up with anyway... something constructivly off
    subject couldn't clog things up too much.... ;) Maybe just on the weekends
    when were all avoiding work anyway...ha..

    Thanks All..Have a grand weekend...Paul
     
    Paul Richardson, Aug 21, 2004
    #10
  11. Mike,

    Still too in the dark to actually know what it is I need to learn...Got
    VS.Net for Dummies last night...Good book bad name...Figured I should learn
    something about c# before I start wasting peoples time with CAD
    questions....

    Using 05 c# Express doesn't help any...Bit buggy(laggy). Going to bite the
    bullet and purchase VS03 this week..

    Thank You,

    Paul
     
    Paul Richardson, Aug 21, 2004
    #11
  12. Dan

    bcoward Guest

    Paul,

    Have you looked at the ObjectARX SDK that accompanies ACAD 2005? The samples contain the following that might get you moving forward with Dot Fred (Bill Vaughn Reference) and ACAD. The ObjectARX SDK provides several basic VB .NET samples in the \samples\dotNet directory.

    We too are preparing code reference for Dot Net and ACAD and will be available on our site via pdf sometime soon. If you want something specific let the list know, it could be a question away.

    This sample demonstrates some extra basics of using the .NET API with AutoCAD. It defines three commands:

    COMINTEROP - Demonstrates the basics of accessing objects exposed in the ActiveX COM object model. In this case it is the AcadApplication, AcadDocuments and AcadDocument objects. The function then goes on to modify the description of each layer listed in the layer table.

    HYPER - Demonstrates how to add a HyperLink object to a Line added to Model Space.


    XRECORD - Demonstrates how to create an XRecord, and populate it using the .NET equivalent of resbufs, called 'ResultBuffer'.

    If you don't have access to this the class is as follows:

    Imports System
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports Autodesk.AutoCAD.Geometry
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports System.Reflection
    Imports System.IO
    Imports System.Collections
    Imports System.Runtime.InteropServices
    Imports Autodesk.AutoCAD.Interop
    Imports System.Diagnostics
    Imports Autodesk.AutoCAD.PlottingServices
    Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

    'to test:
    '1. use the NETLOAD command to load mgdarx.dll
    '2. issue one of the supported commands (XREC, HYPER, COMINTEROP)
    Namespace MgdArx
    _

    Public Class MyCommands

    'this method will be automatically hooked into the AutoCAD command interpreter
    'type "cominterop" on the command line after loading this application with
    'the NETLOAD command
    <CommandMethod("COMINTEROP", CommandFlags.Session)> _
    Public Shared Sub ComInteropCommand()
    'use AcadApplication property to the to the COM object model
    Dim acadApp As AcadApplication = CType(Application.AcadApplication, AcadApplication)
    'use the COM object model to iterate through the docs
    Dim acadDoc As AcadDocument
    For Each acadDoc In acadApp.Documents
    'use the static FromAcadDocument method to convert a COM
    'document to a mnaged document
    Dim doc As Document = Document.FromAcadDocument(acadDoc)

    'Declare a document manager object
    Dim docMgr As DocumentManager = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
    ' use the document manager to lock the document...note: disposal of the lock (below) unlocks the document!
    Dim docLock As DocumentLock = docMgr.LockDocument(doc)

    Try
    'use ObjectId to convert between COM wrappers for database
    'objects and their managed wrappers.
    Dim id As New ObjectId()
    id.OldId = acadDoc.ActiveLayer.ObjectID
    Dim ltr As LayerTableRecord = CType(id.Open(OpenMode.ForWrite), LayerTableRecord)
    Try
    ltr.Description = "Changed by the cominterop command"
    Finally
    ltr.Dispose()
    End Try
    Finally
    docLock.Dispose() ' unlock the document
    End Try
    Next acadDoc
    End Sub 'ComInteropCommand

    'this method will be automatically hooked into the AutoCAD command interpreter
    <CommandMethod("HYPER")> _
    Public Shared Sub HyperCommand()
    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)
    'add some hyperlinks
    Dim hyper As New HyperLink()
    hyper.Name = "www.autodesk.com"
    line.Hyperlinks.Add(hyper)
    If line.Hyperlinks.Contains(hyper) Then
    hyper.Name = "www.gotdotnet.com"
    End If
    line.Hyperlinks.Add(hyper)
    Dim i As Integer
    For i = 0 To line.Hyperlinks.Count - 1
    Debug.WriteLine(line.Hyperlinks(i).ToString())
    Next i 'commit transaction
    myT.Commit()
    Finally
    myT.Dispose()
    End Try
    End Sub 'HyperCommand

    <CommandMethod("XRECORD")> _
    Public Shared Sub XRecCommand()
    Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
    Dim tm As DBTransMan = db.TransactionManager
    'start a transaction
    Dim myT As Transaction = tm.StartTransaction()
    Try
    Dim rec As New Xrecord()
    rec.Data = New ResultBuffer( _
    New TypedValue(CInt(DxfCode.Text), "This is a test"), _
    New TypedValue(CInt(DxfCode.Int8), 0), _
    New TypedValue(CInt(DxfCode.Int16), 1), _
    New TypedValue(CInt(DxfCode.Int32), 2), _
    New TypedValue(CInt(DxfCode.HardPointerId), db.BlockTableId), _
    New TypedValue(CInt(DxfCode.BinaryChunk), New Byte() {0, 1, 2, 3, 4}), _
    New TypedValue(CInt(DxfCode.ArbitraryHandle), db.BlockTableId.Handle), _
    New TypedValue(CInt(DxfCode.UcsOrg), New Point3d(0, 0, 0)))

    Dim dict As DBDictionary = CType(myT.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, False), DBDictionary)
    dict.SetAt("test", rec)
    tm.AddNewlyCreatedDBObject(rec, True)
    'list the entries we just added
    CommandLinePrompts.Message("Xrecord items:" + ControlChars.Lf)
    Dim rb As TypedValue
    For Each rb In rec.Data
    CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" + ControlChars.Lf, rb.TypeCode, rb.Value))
    Next rb
    'add some xdata on the xrecord (silly but this is just a test)
    'first have to register an app
    Dim tbl As RegAppTable = CType(myT.GetObject(db.RegAppTableId, OpenMode.ForWrite, False), RegAppTable)
    Dim app As New RegAppTableRecord()
    app.Name = "MyApp"
    tbl.Add(app)
    tm.AddNewlyCreatedDBObject(app, True)

    rec.XData = New ResultBuffer(New TypedValue(CInt(DxfCode.ExtendedDataRegAppName), "MyApp"), New TypedValue(CInt(DxfCode.ExtendedDataAsciiString), "This is some xdata string"))
    'list them
    CommandLinePrompts.Message("Xdata items:" + ControlChars.Lf)
    For Each rb In rec.XData
    CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" + ControlChars.Lf, rb.TypeCode, rb.Value))
    Next rb
    'commit transaction
    myT.Commit()
    Finally
    myT.Dispose()
    End Try
    End Sub 'XRecCommand
    End Class 'MyCommands
    End Namespace 'MgdArx

    Hope this helps.

    Regards,

    Bob Coward
    CADS, Inc.

    800-366-0946
     
    bcoward, Aug 21, 2004
    #12
  13. Dan

    clintonG Guest

    Bob et. al.

    Its been 15 years since the use of the Internet has been commercialized
    and during that period of time AutoDesk has sold 27 releases of
    AutoCAD.

    Creating a hyperlink in the editor has been subverted and sabotaged
    by AutoDesk who I content does not want customers or developers
    to be able to use the products with HTTP and web enabled applications.

    --
    <%= Clinton Gallagher, "Twice the Results -- Half the Cost"
    Architectural & e-Business Consulting -- Software Development
    NET
    URL http://www.metromilwaukee.com/clintongallagher/











    samples contain the following that might get you moving forward with Dot
    Fred (Bill Vaughn Reference) and ACAD. The ObjectARX SDK provides several
    basic VB .NET samples in the \samples\dotNet directory.
    available on our site via pdf sometime soon. If you want something specific
    let the list know, it could be a question away.
    AutoCAD. It defines three commands:
    ActiveX COM object model. In this case it is the AcadApplication,
    AcadDocuments and AcadDocument objects. The function then goes on to modify
    the description of each layer listed in the layer table.
    ..NET equivalent of resbufs, called 'ResultBuffer'.
    CType(Application.AcadApplication, AcadApplication)
    disposal of the lock (below) unlocks the document!
    CType(id.Open(OpenMode.ForWrite), LayerTableRecord)
    OpenMode.ForRead, False), BlockTable)
    CType(tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite,
    False), BlockTableRecord)
    CType(myT.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite, False),
    DBDictionary)
    CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" +
    ControlChars.Lf, rb.TypeCode, rb.Value))
    CType(myT.GetObject(db.RegAppTableId, OpenMode.ForWrite, False),
    RegAppTable)
    TypedValue(CInt(DxfCode.ExtendedDataRegAppName), "MyApp"), New
    TypedValue(CInt(DxfCode.ExtendedDataAsciiString), "This is some xdata
    string"))
    CommandLinePrompts.Message(String.Format("TypeCode={0}, Value={1}" +
    ControlChars.Lf, rb.TypeCode, rb.Value))
     
    clintonG, Aug 22, 2004
    #13
  14. Why? Seems strange...
     
    Paul Richardson, Aug 22, 2004
    #14
  15. Hi Clinton,

    A number of other users of this group have already commented on your
    irrelevant and unintelligible comments.

    Why not go away and enjoy yourself somewhere else and stop wasting our
    bandwidth ?

    The fact that Autodesk have released 27 versions of their software would
    seem to me that they are actively improving it. I think that is a good
    thing for their customers.
    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Aug 22, 2004
    #15
  16. Hi guys...Broke down and got some serious C# books..Been a while since I've
    used C++ but syntax seems familiar..

    The vb app I am writting is limited in it's ability to extract 3d Data..I
    don't have solids that are complex...just long boxes in most cases...Logs
    that make up a log home...I was hopeing that c# might give more control over
    analyzing this data...All that is availible in VB for solid is it's centriod
    and volume...Tough to get a picture of what kind of solid I'm looking at
    with such limited info...(ie length, profile,points...)

    Any sample on extracting solid data would be helpful if either of you have
    anyting...or anyone else for that matter... Thanks as usual....

    TFYT!

    Paul
     
    Paul Richardson, Aug 22, 2004
    #16
  17. Dan

    Anne Brown Guest

    Clinton -

    PLEASE just make code comments and leave out the conspiracy
    theories. Doing so would prevent the discussion group moderators
    from removing most of your messages.
     
    Anne Brown, Aug 22, 2004
    #17
  18. I'd have to look into it for you, Paul. You might have to wait till the
    next release as this one mostly exposes the COM equivalents thru the
    managed API.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 22, 2004
    #18
  19. How has creating a hyperlink in the editor been 'subverted and
    sabotaged' ? Feel free to expound on this.

    Also, what motive is there for Autodesk to not want customers or
    developers to be able to use [AutoCAD] with HTTP or web-enabled
    applications?
     
    Tony Tanzillo, Aug 23, 2004
    #19
  20. Dan

    clintonG Guest

    I really wouldn't know why and have to guess as I don't think like
    corporate slimesters but if I tried real hard my guess would be
    Autodesk cheats its customers because they have been trying
    to force them to pay to use Buzzsaw.

    --
    <%= Clinton Gallagher, "Twice the Results -- Half the Cost"
    Architectural & e-Business Consulting -- Software Development
    NET
    URL http://www.metromilwaukee.com/clintongallagher/
     
    clintonG, Aug 23, 2004
    #20
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.