+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Full Member Maxelkat's Avatar
    Using
    AutoCAD 2006
    Join Date
    Apr 2009
    Posts
    54

    Question Using Visual Basic with AutoCAD

    Registered forum members do not see this ad.

    I want to create a Visual Basic program that will open a particular AutoCAD file, replace a particular block with another one from a particular location (with position and scale of the new block matching the one being replaced), and save the altered file in a particular location.

    Is what I'm attempting remotely possible?

  2. #2
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    I have never been able to use VB to do this but I do use VB to build a script file that runs within AutoCAD to do so. As your tack sounds simple I would just write a script file without the VB bit unless you want to run this on a lot of drawings.

    Alternatively you can write a VBA routine with AutoCAD (or you could, it is an option on newer versions) to run within an open drawing. Certainly what you have described is easily achieved with VBA.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  3. #3
    Full Member Maxelkat's Avatar
    Using
    AutoCAD 2006
    Join Date
    Apr 2009
    Posts
    54

    Default

    Cheers Dave,
    Actually my colleague will be attacking the VB side of things. I think it'll be some sort of form that will lead the program to the right drawing, and make the right block replacement, hence the need for VB.
    I sort of know how to do the AutoCAD bit, but I'm not sure how they work together. Knowing that it should be possible helps.
    Elliott

  4. #4
    Luminous Being dbroada's Avatar
    Computer Details
    dbroada's Computer Details
    Operating System:
    XP Pro
    Computer:
    Dell
    CPU:
    Intel Xeon 2.13GHz
    RAM:
    2GB
    Graphics:
    NVIDA Quadro FX 580
    Monitor:
    DELL 23" & SAMSUNG 21"
    Discipline
    Electro/Mech
    dbroada's Discipline Details
    Occupation
    Design Engineer
    Discipline
    Electro/Mech
    Using
    Electrical 2013
    Join Date
    Nov 2005
    Location
    Sussex, UK
    Posts
    5,059

    Default

    Form driven from VB is the bit I couldn't get to work but I know others have done it so it is possible. I just took the easy route.
    "That's it. It's one thing for a ghost to terrorize my children, but quite another for him to play my Theremin." Homer Simpson

    Dave

  5. #5
    Senior Member Jeff H's Avatar
    Using
    MEP 2011
    Join Date
    Oct 2010
    Posts
    172

    Default

    If by 'Visual Basic' you mean VB.NET then yes, not enough knowledge to comment on VBA.
    You can also find your answers @ theswamp.org

  6. #6
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,948

    Default

    To the best of my limited understanding of Visual Basic for Applications (VBA), yes this is possible; just be aware that VBA is no longer supported by Microsoft, and is being killed off through attrition.

    While I know that VB.NET can also perform this task, IMO, the simplest solution (i.e., least amount of code), is to either write a Script (SCR), or to code yourself a small Visual LISP routine which employs ObjectDBX to programmatically perform the tasks stated in the OP.

    My $0.02
    "Potential has a shelf life." - Margaret Atwood

  7. #7
    Super Member Bill Tillman's Avatar
    Using
    AutoCAD 2013
    Join Date
    Oct 2008
    Location
    Miami, FL
    Posts
    870

    Default

    just be aware that VBA is no longer supported by Microsoft, and is being killed off through attrition.
    That's what I keep hearing yet just a few days ago I heard the M$ will be supporting VB6 through the lifecycle of Windows 8.

    I'm working on several projects using VB.NET and VBA in Excel. Today as I looked up some information on the MSDN site the article I read had a single paragraph written in italics which reminded the reader that the information enclosed would soon be obselete and that I should pursue a method in the .NET arena. So I did.

    The trouble is the docs for VB.NET are lacking, cryptic, and otherwise very difficult to digest.

    My 2ยข worth.
    It's deja vu, all over again.

  8. #8
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,948

    Default

    Quote Originally Posted by Bill Tillman View Post
    That's what I keep hearing yet just a few days ago I heard the M$ will be supporting VB6 through the lifecycle of Windows 8.
    ... You'll love this thread then: VBA7 and C# scripting?
    "Potential has a shelf life." - Margaret Atwood

  9. #9
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,948

    Default

    Also worthy of note... There is a difference between supporting VBA, and simply allowing it to live on.

    As I stated, it (VBA) is no longer supported (unless they come out with VBA7!), and _will_ die off through attrition one day (... it may take them 50 years, but by Golly they'll kill it off!).
    "Potential has a shelf life." - Margaret Atwood

  10. #10
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    Registered forum members do not see this ad.

    I threw this together from some stuff that i already have written. it may need some tweeking.

    Code:
    Sub your_BLK_name()
        Dim gpCode(1) As Integer
        Dim dataValue(1) As Variant
        Dim SS_your_BLK_name As AcadSelectionSet
        Dim i As Integer
        
        
        Set SS_your_BLK_name = ThisDrawing.SelectionSets.Add("SS_your_BLK_name")
            gpCode(0) = 0: dataValue(0) = "INSERT"
            gpCode(1) = 2: dataValue(1) = "name of old block"
            
        SS_your_BLK_name.Select acSelectionSetAll, , , gpCode, dataValue
        
        Dim BScale(2) As Double
        Dim BCoord() As Long
        Dim Cur_Blk as AcadBlockReference
            
            For i = 0 To SS_your_BLK_name.Count - 1
            Set Cur_Blk = SS_your_BLK_name.Item(i)
                
                If Cur_Blk.Name = "name of old block" Then
                    BScale(0) = Cur_Blk.XScaleFactor
                    BScale(1) = Cur_Blk.YScaleFactor
                    BScale(2) = Cur_Blk.ZScaleFactor
                    BCoord() = Cur_Blk.InsertionPoint
                End If
            
            Next i
        If SS_your_BLK_name.Count > 0 Then SS_your_BLK_name.Erase
        
        Dim BlockObj As AcadBlockReference
        Set BlockObj = ThisDrawing.ModelSpace.InsertBlock(BCoord, "new block name", BScale(0), BScale(1), BScale(2), 0)
        
    End Sub

Similar Threads

  1. visual basic editor in autocad?
    By mateen in forum .NET, ObjectARX & VBA
    Replies: 1
    Last Post: 12th Sep 2011, 06:13 pm
  2. visual basic using autocad
    By jayaram in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 21st Feb 2010, 03:33 pm
  3. how to use visual basic in autocad
    By mien in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 23rd Feb 2009, 04:37 pm
  4. help for AutoCAD using Visual Basic 6.0
    By kanyakumari_t in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 11th Nov 2005, 09:08 am
  5. AutoCAD and Visual Basic
    By TheRobster in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 12th Sep 2005, 02:00 pm

Bookmarks

Posting Permissions

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