See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: The Visual Basic Editor in ACAD2006

  1. #1
    Member
    Join Date
    2006-04
    Posts
    24
    Login to Give a bone
    0

    Default The Visual Basic Editor in ACAD2006

    Autocad 2006 was recently put on our machine and I was wondering if the Visual Basic editor interfaces directly with Autocad. I have some experience programming with VB and I was wondering if there were special calls designed to issue commands to autocad. I was wanting to make a macro with a GUI.

    Thanks!!!
    Justin

  2. #2
    100 Club intergrupocr's Avatar
    Join Date
    2006-02
    Posts
    116
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    Type VBAIDE and you will go!!!!
    In the Help File are a lot of resources about ActiveX Automation!!

    Have a nice trip!!!!

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,453
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    Since this is strictly a vba topic, I moved it here.
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member
    Join Date
    2006-04
    Posts
    24
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    My bad, I'm pretty new here and didn't realize there was a forum dedicated to this.

    Thanks for sharing all these fantastic resources!

    However, the help file doesn't ever really help much.

  5. #5
    100 Club intergrupocr's Avatar
    Join Date
    2006-02
    Posts
    116
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    Quote Originally Posted by justinxxvii
    My bad, I'm pretty new here and didn't realize there was a forum dedicated to this.

    Thanks for sharing all these fantastic resources!

    However, the help file doesn't ever really help much.
    You have to follow the link at the bottom of the help index

    ActiveX Automaion and VBA

    Then you will find this...
    Attached Images Attached Images

  6. #6
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    FORM THE HELP IN AUTOCAD 2002 IT THE SAME FOR 2006

    To update the coding examples for use with VB, you must first reference the AutoCAD type library. To do this in VB, select the References option from the Project menu to launch the Reference dialog box. From the References dialog box, choose AutoCAD Type Library, and then press OK.
    Next, in the code example replace all references to ThisDrawing with a user-specified variable referencing the active document. To do this, define a variable for the AutoCAD application (acadApp) and for the current document (acadDoc). Then, set the application variable to the current AutoCAD application.

    If AutoCAD is running, the VB GetObject function retrieves the AutoCAD Application object. If AutoCAD is not running, an error occurs that (in this example) is trapped, then cleared. The CreateObject function then attempts to create an AutoCAD Application object. If it succeeds, AutoCAD is started; if it fails, a message box displays a description of the error.

    Note: When running multiple sessions of AutoCAD, the GetObject function will return the first instance of AutoCAD in the Windows Running Object Table. See the Microsoft Visual Basic documentation on the Running Object Table (ROT) and the GetObject function for more information on verifying the session returned by GetObject.

    You must set the AutoCAD application's Visible property to TRUE in order to display the AutoCAD drawing window.

    Note: If GetObject creates a new instance of AutoCAD (that is, AutoCAD was not already running when you issued GetObject), failure to set Visible to TRUE results in an invisible AutoCAD application; AutoCAD will not even appear on the Windows taskbar.

  7. #7
    Member
    Join Date
    2006-04
    Posts
    24
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    Thank you.

    I started fiddling around with some of the functions but this visual basic isn't behaving like one I'm used to.

    I wanted to make a little app that would draw a line by clicking a button. The line would have properties that were defined in two text boxes:

    1. Distance
    2. Bearing

    and would use the command format

    @distance<nXXdXX'XX"e

    So I created variables in the module

    Dim distance as Integer
    Dim bearing as String

    And then I wanted to create the routine

    Sub bearingline (distance, bearing)

    and this is where I got hung up. There is a line routine here called "AcadLine" but I can't figure out how to use it. I would like to call up the line command, and then use some programming to make the line go for the specified bearing and distance.

    how does AcadLine work? I'll start checking help files and websites but I just want to see if anyone can help me here.

    Thanks ladies and gentlemen
    Justin
    EDIT:

    nevermind I've found out more information, there are properties for acadline called "length" and "angle"

    So I will fiddle with it some more

  8. #8
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,809
    Login to Give a bone
    1

    Default Re: The Visual Basic Editor in ACAD2006

    Quote Originally Posted by justinxxvii
    how does AcadLine work? I'll start checking help files and websites but I just want to see if anyone can help me here.
    Calculate the endpoints of the line, then create it.

    Here is a small example

    Code:
    Sub myLine(brg As Double, leng As Double, pt1 As Variant)
    Dim pt2 As Variant, newline As AcadLine
    pt2 = ThisDrawing.Utility.PolarPoint(pt1, brg, leng)
    Set newline = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
    End Sub
    
    Sub foo()
    pt1 = ThisDrawing.Utility.GetPoint(, "Pick Start Point")
    Call myLine(1.3, 3.5, pt1)
    End Sub
    The Angle and Length properties of an existing line are read-only.
    R.K. McSwain | CAD Panacea |

  9. #9
    Member
    Join Date
    2006-04
    Posts
    24
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    Wow thanks! I was wanting to take a shot at coding this but I didn't know how all those properties worked.

    You pretty much did all the work for me, thanks, this is exactly what I was looking for.

    I will fumble around with your code to ty to customize it

  10. #10
    Member
    Join Date
    2006-04
    Posts
    24
    Login to Give a bone
    0

    Default Re: The Visual Basic Editor in ACAD2006

    I'm not understanding the code here.

    This part:

    Sub myLine(brg As Double, leng As Double, pt1 As Variant)

    I'm sending the bearing information and the length information into the sub.

    Then this:

    pt2 = ThisDrawing.Utility.PolarPoint(pt1, brg, leng)

    So ThisDrawing.utility.polarpoint (Starting Point, Bearing information, length information) will calculate the endpoint?

    So now I can

    Set newline = ThisDrawing.ModelSpace.AddLine(pt1, pt2)

    Why did you write this code in:

    Call myLine(1.3, 3.5, pt1)

    What do the 1.3, and 3.5 represent? Are they arbitrary figures or do they mean something else? Shouldn't it be Call myline (brg, length, pt1)

    Or will this not work?

    I can't get the code to work correctly, first I copied the sub information into the bas, then the foo routine into a command button, and sent textbox1.text and textbox2.text into it for brg and length

    EDIT

    Ok I see something now, when I type

    set newline = ThisDrawing.modelspace.addline (

    an info box pops up and says "Start Point, End Point"

    What is an easy way to calculate the endpoint with a bearing and distance?

    EDIT:

    I guess there is another function in here called PolarPoint which is supposed to calculate my endpoint. I will have to convert my bearing into an angle by using another feature called deg2rad or something, but I will continue working

    I'll post again if I figure it out
    Last edited by justinxxvii; 2006-08-25 at 11:57 PM.

Page 1 of 3 123 LastLast

Similar Threads

  1. visual lisp editor should be like visual studio
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2011-11-17, 05:33 PM
  2. Autocad LT vs Visual Basic 6
    By hibbe.wiersma172517 in forum ARX
    Replies: 2
    Last Post: 2008-08-21, 08:16 AM
  3. The future of Visual Basic
    By MikeJarosz in forum VBA/COM Interop
    Replies: 4
    Last Post: 2006-08-04, 06:29 PM
  4. Microsoft Visual Basic
    By jcronburg in forum VBA/COM Interop
    Replies: 1
    Last Post: 2004-06-16, 07:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •