+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 34
  1. #1
    Junior Member
    Computer Details
    JGupte's Computer Details
    Operating System:
    Windows 7
    Discipline
    Construction
    JGupte's Discipline Details
    Occupation
    Document Controller/Report Writer
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Aug 2017
    Location
    Sydney, Australia
    Posts
    15

    Default AutoCAD Title Block from EXCEL VBA

    Registered forum members do not see this ad.

    Hi All,

    I am trying to write a VBA script that will run from inside an Excel spread sheet to update the title block fields from values in the spreadsheet.

    I have been able to use ATTOUT to export the existing values to a TXT file and ATTIN to import the changed values. But I need to drive this from Excel VBA.
    In plain English, what I need to do is:

    Loop through all dwg files in a list
    for each dwg file,
    find the Title block values in my spread sheet and export them to a txt file (in the correct format)
    open the dwg file
    import the txt file (ATTIN)
    save and close the dwg file
    Delete the txt file
    Loop

    I am fairly proficient in Excel VBA, but not in AutoCAD.
    So far, I can create a link to AutoCAD and open the dwg file, then save and close it.

    But I can't figure out how to automate the ATTIN function.

    As I am not a Administrator on my PC (company policy) I can not install any programs of tools.

    Any help would be appreciated.

    JG

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,821

    Default

    1st up search here lots of examples that do title block update. You may be better going the other way and drive excel from Autocad this can be a simple get cell and put atribute. Likewise I am sure you can drive Autocad from excel. I have posted a vba block attribute updating code that may be usefull as I am not sure about driving from excel. There is basicly two ways to find the correct attribute to change either use its tag name or use its position order, the second method is the example here with the 1st attribute starting at 0 see attrib(0)

    Most of the excel/Autocad examples use lisp in particular code written in Vlisp is very similar method.

    getexcel.lsp is what I use there are others, it does have methods that may enable excel to control I have never had to do it that way.

    Code:
    Public Sub ModifyPitSchedule1()
    ' adds single pt
    
    Dim SS As AcadSelectionSet
    Dim objENT As AcadEntity
    Dim Count, Cntr As Integer
    Dim Newpitname As String
    Dim pitname As String
    Dim FilterDXFCode(0) As Integer
    Dim FilterDXFVal(0) As Variant
    Dim PitNameSelect As AcadObject
    Dim basepnt, pt1, pt2, pt3 As Variant
    Dim attribs As Variant
    
    'On Error Resume Next
    
    Newpitname = "1"   'dummy to pass then return changed
    BLOCK_NAME = "SCHEDTEXT"
    
    pitname = Getpitname(Newpitname)
    
    MsgBox "pitname selected is " & pitname
    
    FilterDXFCode(0) = 0
    FilterDXFVal(0) = "INSERT"
    'FilterDXFCode(1) = 2
    'FilterDXFVal(1) = "SCHEDTEXT"
    
    Set SS = ThisDrawing.SelectionSets.Add("pit1sel")
    SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal
    
    
    For Cntr = 0 To SS.Count - 1
    
    If SS.Item(Cntr).Name = BLOCK_NAME Then
    
      
       attribs = SS.Item(Cntr).GetAttributes
            
         If attribs(0).TextString = pitname Then
           pt1 = ThisDrawing.Utility.GetPoint(, " pick first point")
    
           txtx1 = CStr(FormatNumber(pt1(0), 3))
           TXTY1 = CStr(FormatNumber(pt1(1), 3))
            
            attribs(1).TextString = txtx1
            attribs(2).TextString = TXTY1
            
            attribs(1).Update
            attribs(2).Update
    '        ThisDrawing.Application.Update
    ' try this
            Cntr = SS.Count
         
         Else: End If
          
     Else: End If
    
    Next Cntr
    ThisDrawing.SelectionSets.Item("pit1sel").Delete
    End Sub
    Attached Files
    Last edited by BIGAL; 22nd Aug 2017 at 08:14 am.
    A man who never made mistakes never made anything

  3. #3
    Junior Member
    Computer Details
    JGupte's Computer Details
    Operating System:
    Windows 7
    Discipline
    Construction
    JGupte's Discipline Details
    Occupation
    Document Controller/Report Writer
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Aug 2017
    Location
    Sydney, Australia
    Posts
    15

    Default

    Hi BIGAL,
    Thanks for the reply.


    The reason for driving this from Excel instead of AutoCAD is that we need to update several thousand drawings with data in one Excel spread sheet.


    I would like to use the tag name method, and update an existing tag with a value from the spread sheet.


    E.G.
    Tag Name = "TPDDRAWINGNO"
    Current value = "TPDDRAWINGNO" (from template"
    Desired value = "SLR-ALS-D50-CSR-DWG-063201"


    These will all be in the title block.


    The procedure will loop through the spread sheet and update each drawing appropriately.
    I have my data in one line per drawing with the tags as the column headings.


    JG

  4. #4
    Forum Deity steven-g's Avatar
    Computer Details
    steven-g's Computer Details
    Operating System:
    Win 7
    Discipline
    Construction
    steven-g's Discipline Details
    Occupation
    Draughtsman
    Discipline
    Construction
    Details
    I work in the estimating department of a large building contractor.
    Using
    AutoCAD 2017
    Join Date
    May 2013
    Location
    An Englishman in Belgium
    Posts
    2,055

    Default

    Can you post the code that you have up to now. It would be easier for someone to help if they have a starting point to work from.
    I've just been down graded from 2012LT to full Autocad 2017. I WANT LT BACK

  5. #5
    Junior Member
    Computer Details
    JGupte's Computer Details
    Operating System:
    Windows 7
    Discipline
    Construction
    JGupte's Discipline Details
    Occupation
    Document Controller/Report Writer
    Discipline
    Construction
    Using
    AutoCAD 2016
    Join Date
    Aug 2017
    Location
    Sydney, Australia
    Posts
    15

    Default

    I don't really have much code yet. Just the basic to start AutoCAD and open the drawing.


    Sub Open_DWG()
    On Error Resume Next
    Dim strDrawing As String
    On Error Resume Next
    Set ACAD = GetObject(, "AutoCAD.Application")
    If Err.Description > vbNullString Then
    Err.Clear
    Set ACAD = CreateObject("AutoCAD.Application")
    End If
    ACAD.Visible = True
    xDWGPath = "C:\Users\297560\Documents\Development\AutoCAD Update\"
    Range("A2").Select
    xDWGFile = ActiveCell & ".dwg"
    xDWGFull = xDWGPath & xDWGFile
    ACAD.Documents.Open (xDWGPath & xDWGFile)


    End Sub


    I am trying to create the project from scratch, and trying various bits of code I am finding on the web.


    When creating Excel macros, I usually start by recording a macro to do the basic stuff I want, then modifying the code to add loops, error checking, etc.


    But in AutoCAD I can't figure out how to record the macro (I tried Action Recorder, but could not find how to edit the code generated).


    JG

  6. #6
    Forum Newbie
    Using
    AutoCAD 2014
    Join Date
    Feb 2016
    Posts
    2

    Default

    I want to autocad text command apply from excel cell- like "-text "&Crossing!B3&",-4.5 0 Distance"
    but i can only one text write from one cell, how can i do multi text write from one excell text to autocad from different position

  7. #7
    Forum Newbie
    Using
    AutoCAD 2014
    Join Date
    Feb 2016
    Posts
    2

    Default

    I want to autocad text command apply from excel cell- like "-text "&Crossing!B3&",-4.5 0 Distance"
    but i can only one text write from one cell, how can i do multi text write from one excell text to autocad from different position..

    Like:
    Distance (Position 4,5)
    Elevation (Position 4,7)

    Please help any body

  8. #8
    Forum Deity steven-g's Avatar
    Computer Details
    steven-g's Computer Details
    Operating System:
    Win 7
    Discipline
    Construction
    steven-g's Discipline Details
    Occupation
    Draughtsman
    Discipline
    Construction
    Details
    I work in the estimating department of a large building contractor.
    Using
    AutoCAD 2017
    Join Date
    May 2013
    Location
    An Englishman in Belgium
    Posts
    2,055

    Default

    I can't comment on the merits of working this way, I'm new to full Autocad but was interested to find out how to issue commands from Excel, so building on what you posted, this code will update the attributes in all the drawings in a list.


    I used the -attedit command as this doesn't require you to write multiple txt files and so just a simple loop will suffice, I had drawing names in column A (starting at A2) then old attribute values in column B and new values in column C, I only ran this on 3 simple drawings and each one only had a single layout and attributed block, so there is no error checking or changing to the correct layout, but it worked. I would advise making a complete backup of any folders you use before running any Code, and take a look in the help files about the -attedit command for possible changes in the layout of how you can use it.


    Code:
    Sub Open_DWG()
     On Error Resume Next
     Dim strDrawing As String
     Dim acadCmd As String
     On Error Resume Next
     Set ACAD = GetObject(, "AutoCAD.Application")
     If Err.Description > vbNullString Then
     Err.Clear
     Set ACAD = CreateObject("AutoCAD.Application")
     End If
     ACAD.Visible = True
     xDWGPath = "D:\Autodesk support\Drawings\"
    'xDWGPath = "C:\Users\297560\Documents\Development\AutoCAD Update\"
     For x = 2 To 4
     Cells(x, 1).Select
     xDWGFile = ActiveCell & ".dwg"
     xDWGFull = xDWGPath & xDWGFile
     ACAD.Documents.Open (xDWGPath & xDWGFile)
     acadCmd = "-attedit n n " & vbCr & "TPDRAWINGNO" & vbCr & Cells(x, 2).Value & vbCr & Cells(x, 2).Value & vbCr & Cells(x, 3).Value
     ACAD.ActiveDocument.SendCommand acadCmd & vbCr
     ACAD.ActiveDocument.SendCommand "qsave close" & vbCr
     Next
    End Sub
    I've just been down graded from 2012LT to full Autocad 2017. I WANT LT BACK

  9. #9
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,799

    Default

    Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  10. #10
    Forum Deity steven-g's Avatar
    Computer Details
    steven-g's Computer Details
    Operating System:
    Win 7
    Discipline
    Construction
    steven-g's Discipline Details
    Occupation
    Draughtsman
    Discipline
    Construction
    Details
    I work in the estimating department of a large building contractor.
    Using
    AutoCAD 2017
    Join Date
    May 2013
    Location
    An Englishman in Belgium
    Posts
    2,055

    Default

    Registered forum members do not see this ad.

    I have to add here the code posting tags icon doesn't do anything for me, not sure if it's a browser problem (IE) or just broken on the site, but I have to manually type in the CODE tags
    I've just been down graded from 2012LT to full Autocad 2017. I WANT LT BACK

Similar Threads

  1. Insert a title Block from excel into a opened dwt with excel vba
    By alex140590 in forum .NET, ObjectARX & VBA
    Replies: 2
    Last Post: 15th Jul 2016, 11:43 am
  2. Replies: 9
    Last Post: 19th Apr 2016, 03:43 pm
  3. Title block to excel spreadsheet
    By keiths in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 3rd Dec 2013, 07:26 am
  4. Excel spreadsheet to update autocad drawing title block
    By Jasenc in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 11th Feb 2013, 12:47 pm
  5. EXCEL Drawing register using Autocad Title Block Attributes
    By SimonC in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 25th Aug 2010, 03:40 am

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