See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: AutoCAD VBA Tips & Tricks

  1. #1
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    1

    Default AutoCAD VBA Tips & Tricks

    Looks like it too late to start one. I wonder why there is no tips & tricks forum under programming community. It would have been a great help for the people here, especially for the beginners. Anyway I don't want to wait until it get started ( Because I don't know whether it will be started or not). I am going to post VBA programming specific tips & tricks here. I request you VBA guys to contribute and share your knowledge here.

    Look very eagerly forward to see whether this thread can survive the moderator scissors .

    [Edit]

    As the thread has started growing, it would be nice to keep an index to quickly overview and access the tips. Thanks everybody for the contribution. Please do not post any copyrighted material here. Hope you leave a suitable title with each tip you submit.

    AutoCAD VBA Tips & Tricks Index
    1. ArcCos function in VBA
    2. Changing default lower bound of arrays to 1
    3. Retrieving an object's defenition data
    4. Renaming a drawing from the command prompt
    5. Distance between two points - Function
    6. Tips on handling Excel application from VBA
    7. Accessing nested block references
    8. Passing an array as function / procedure argument
    9. Clearing grips while using PickFirstSelectionSet
    10. Identifying between AutoCAD vertical products
    11. To erase/reset a static/dynamic array
    12. Converting an attribute definition to text.
    [/Edit]
    Last edited by zoomharis; 2007-09-09 at 08:46 AM. Reason: Added more links

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

    Default Re: AutoCAD VBA Tips & Tricks

    Why would we want to cut it out?

    I think one hasn't been started before, because every snippet of code is a tip (the ones that work, that is). Therfore the entire forum is a tips-and-tricks I do have some stickeys at the top of the forum though.
    C:> ED WORKING....

  3. #3
    Active Member rcrabb's Avatar
    Join Date
    2007-02
    Posts
    99
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    maybe this is a little too "common" for this section, but I want to try to contribute!

    I do a lot of automated shape drawing programs, based on user input and so forth. often in my calculations, I need to use ArcCos - which to my knowledge is unavailable (unlike ArcTan which can be used as "atan()" ... so I found this little function searching through some forums, and its been worth its weight in gold, so to speak

    Code:
    Function Arccos(X) As Double
       Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
    End Function
    If this post sucks, feel free to mod it out

  4. #4
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    Quote Originally Posted by rcrabb
    Function Arccos(X) As Double
    Arccos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
    End Function
    [/code]
    I have yet to use trigonometric functions in programs. Still I will keep this one for future use. Here is another tip for VBA

    Changing Default Lower Bound of Arrays to 1

    Using Option Base statement, you can change the default lower bound of arrays from 0 t0 1. Declare the statement in the module level. You can have only one Option Base statement inside a module. If you want to override the Option Base statement, then use 'To' clause. The following sample program will give you some clear idea of it.
    Option Base 1 ' Declare on top of the module

    Sub CheckBound()
    Dim Array1(5)
    Dim Array2(0 To 4)
    MsgBox "Array1 : Lbound - " & LBound(Array1) & ", Ubound - " & UBound(Array1) & vbCrLf & _
    "Array2 : Lbound - " & LBound(Array2) & ", Ubound - " & UBound(Array2)
    End Sub

  5. #5
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    Retrieving an Object's Defenition Data

    Sometimes we may want to use DXF code/value pairs inside VBA coding. Here is an easy way to check it out using a small bit of lisp.

    Code:
      (entget (car (entsel)))
    Simply enter that line in your command prompt and select the object when asked to do so. A familiar routine for the AutoLISP people. Very handy for all kind of AutoCAD programmers.

  6. #6
    Member
    Join Date
    2004-05
    Posts
    22
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    I never needed trig functions until recently when I needed to find the centrepoint and radius for an arc in a polyline. AutoCAD provides a Bulge factor, but you need some trig to resolve this into radius and centrepoint data.
    A few clever guys helped me out, and their ideas may be useful for others.
    See my thread in this section "Polylines and Mathematics" for more detail.

  7. #7
    Active Member rcrabb's Avatar
    Join Date
    2007-02
    Posts
    99
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    i've also done automated shape drawing programs based on user input, i have over 17 different shapes that i'm not too comfortable posting in its entirety online, but would be more than willing to help anyone who needs it!

    just drop me a PM

  8. #8
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    Quote Originally Posted by zoomharis
    Changing Default Lower Bound of Arrays to 1
    This is a poor tip, IMHO, because most modern languages use 0 as their base for their structured data. To go "backwards" to a base of 1 only serves to prolong the transition to modern techniques.

  9. #9
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    Quote Originally Posted by RobertB
    This is a poor tip, IMHO, because most modern languages use 0 as their base for their structured data. To go "backwards" to a base of 1 only serves to prolong the transition to modern techniques.
    Thanks for the input, Robert. As far as you people are around here, we are not worried about making mistakes . Could you please explain us the history of using a confusing 0 as base instead of a straight forward 1? It would be really a nice piece of info to grab.

    TIA
    Last edited by zoomharis; 2007-03-29 at 09:25 AM.

  10. #10
    All AUGI, all the time zoomharis's Avatar
    Join Date
    2005-02
    Location
    Abu Dhabi (Native-India)
    Posts
    506
    Login to Give a bone
    0

    Default Re: AutoCAD VBA Tips & Tricks

    Renaming Active Drawings

    Normally we can not rename a file when it is open. Here is a tricky way using VBA to rename currently active drawing from the command prompt. Please note that I have used a seperate function for validating filenames. If you know regular expressions, you can make the code compact by replacing the function with a regular experssion. See the attached DVB file.
    Attached Files Attached Files
    Last edited by zoomharis; 2007-05-06 at 12:17 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. CV314-4: AutoCAD Civil 3D Tips and Tricks
    By Autodesk University in forum Civil Infrastructure
    Replies: 0
    Last Post: 2014-12-01, 05:01 AM
  2. MP104-1: New Tips and Tricks for Piping in AutoCAD MEP
    By Autodesk University in forum MEP Design and Engineering
    Replies: 0
    Last Post: 2014-12-01, 03:25 AM
  3. GD315-1: AUGI Tips and Tricks: For AutoCAD
    By Autodesk University in forum General Design
    Replies: 0
    Last Post: 2013-05-06, 01:35 AM
  4. GD311-4: DWF Publishing from AutoCAD: Tips and Tricks
    By Autodesk University in forum General Design
    Replies: 0
    Last Post: 2013-05-06, 01:34 AM
  5. info about Tips And Tricks For AutoCad
    By sharjeel_faiz in forum AutoCAD General
    Replies: 1
    Last Post: 2005-06-08, 04:39 AM

Posting Permissions

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