Newbie help with AutoCAD/Excel link

Newbie help with AutoCAD/Excel link

Anonymous
Not applicable
1,080 Views
2 Replies
Message 1 of 3

Newbie help with AutoCAD/Excel link

Anonymous
Not applicable

Hello, 

 

I need to make a routine to batch change data in DWG files. 

The idea would be to receive several drawings from a client. I would open each drawing and place a rectangle with a set dimension inside the DWG. This can't be made with code because there's not a set position for the rectangle. It has to be user defined for each drawing. 

Then I'd like to have Excel place something like a Title block inside that rectangle. 

In the Excel file I'd choose from 3 or 4 styles of Title blocks, that can be drawn in separate DWG files, and change some fields inside the title blocks, like user, data, version, state of approval, etc. 

I'd like to have a table in excel, this table would have in the first column the filename each line and columns for title block type, date, revision number, user, state of approval. I'd fill in the table first, put all the files in a set folder and press a button for the macro to go to each individual file, go to the set rectangle, place the chosen title block and write the text that's in the table in the defined fields. 

 

Thanks in advance. 

 

Best regards 

1,081 Views
2 Replies
Replies (2)
Message 2 of 3

grobnik
Collaborator
Collaborator

Hi @Anonymous what you are asking it's not impossible to do, but you should have at least a sample drawing where to apply the code for test, Autocad blocks with related  attributes to be changed already defined, and an Excel file with rows and columns structured according the Autocad blocks attributes ("...In the Excel file I'd choose from 3 or 4 styles of Title blocks ??...") .

In any case here below an example how to have access to Autocad from Excel development area, it's depending where do you need to developing your code: if drawing part to manage it's higher than Excel part could be useful developing the procedure inside Autocad on the opposite inside Excel as below example:

 

Sub Excel_to_dwg()
 
    Dim acadApp As Object
    Dim AcadDoc As Object
    Dim MyCenter(0 To 2) As Double
    Dim MyMag As Double
    On Error Resume Next

 'Check if AutoCAD application is open. If is not opened create a new instance and make it visible.
    Set acadApp = GetObject(, "AutoCAD.Application")
    Set AcadDoc = acadApp.ActiveDocument
   If acadApp Is Nothing Then
       Set acadApp = CreateObject("AutoCAD.Application")
        acadApp.Visible = True
   End If
   
   CellsX = ActiveCell.Value
   YCol = ActiveCell.Column + 1
   CellsY = Cells(ActiveCell.Row, YCol).Value
   ZCol = ActiveCell.Column + 2
   CellsZ = Cells(ActiveCell.Row, ZCol).Value
   
   MyCenter(0) = CellsX
   MyCenter(1) = CellsY
   MyCenter(2) = CellsZ
    
    MyMag = 5
    AcadDoc.Application.ZoomCenter MyCenter, MyMag

End Sub

 

main trick concern the Autocad object creation inside Excel procedure, then you can do more or less anything.

I hope this will help you a bit.

Bye

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi,

 

Thank you for your quick reply. 

I'm going to prepare an example for the main DWG, for each DWG "tag" and for the XLS table and place it here for better understanding.

Later this week, I'll try to play a little bit with the code that you've sent me to understand what it does.

 

Thanks for your time.

0 Likes