Jump to content

Data From Excel to Block Attributes


Recommended Posts

Posted

I have some soil boring data captured, in the field, to an Excel spreadsheet; basically, a bore site ID and coordinates.

 

I'd like to be able to have the coordinate attributes of blocks inserted into my bore site plans populate automatically, perhaps based off of the value of a bore site ID attribute which is manually entered for each bore site.

 

Alternatively, if there were a way to insert the bore site blocks based off the actual Excel records, populating all attribues and locating the block by the actual X,Y,Z coordinate, that might be even better.

 

Is there an easy way? Is there any lisp to be shared?

 

Newbie

Posted

This is some VBA code you can use from Excel to insert blocks into AutoCAD. You should have a block already created into AutoCAD. If the block has attributes, you can use the data from Excel to populate the attributes.

 

If you know how VBA and the VBE works, you should have no problem with this.

 

Just make sure to set the 'reference' to AutoCAD. In the VBE - Tools / References - with AutoCAD 2010 it is called AutoCAD 2012 Type Library.

 

 

Sub InsertBlockWithData()

Dim objApp As AcadApplication: Dim objDoc As AcadDocument
Dim blockRefObj As AcadBlockReference: Dim varAttributes As Variant
Dim InPt(2) As Double
   
' Excel worksheet name with data to insert into AutoCAD
' X / Y / Z / Layer Name / Block Name / Boring ID / Block Size / Block Rotation
   DataSheet = "WorksheetWithData"
   
' Create the link to AutoCAD - the currently open drawing
   Set objApp = GetObject(, "AutoCAD.Application"): Set objDoc = objApp.ActiveDocument

' Loop through the data - set StartRow (usually 2) and EndRow (last row of data)
   For Row = StartRow To EndRow

' get coordinates and layer name for text insertion
       InPt(0) = Worksheets(DataSheet).Cells(Row, 1)
       InPt(1) = Worksheets(DataSheet).Cells(Row, 2)
       InPt(2) = Worksheets(DataSheet).Cells(Row, 3)
       Layer = Worksheets(DataSheet).Cells(Row, 4)
       BlockName = Worksheets(DataSheet).Cells(Row, 5)
       BoringName = Worksheets(DataSheet).Cells(Row, 6)
       Size = Worksheets(DataSheet).Cells(Row, 7)
       Rotation = Worksheets(DataSheet).Cells(Row,  ' in radians
       
' Insert Borings Block object and change attributes
       Set blockRefObj = objDoc.ModelSpace.InsertBlock(InPt, BlockName, Size, Size, Size, 0)
       blockRefObj.Layer = Layer
       blockRefObj.Color = acByLayer
' set attributes - you can have more than one...
       varAttributes = blockRefObj.GetAttributes
           varAttributes(0).TextString = BoringName

   Next Row

End Sub

  • 10 months later...
Posted

I think I'm doing something wrong I get a run error when I try this on Inpt(0).

I changed out "w2orksheetwithdata" to "Creek" which is the tab name.

What alse do I need to do?

I can send the file or post it somewhere if I need to.

Posted
I have some soil boring data captured, in the field, to an Excel spreadsheet; basically, a bore site ID and coordinates.

 

I'd like to be able to have the coordinate attributes of blocks inserted into my bore site plans populate automatically, perhaps based off of the value of a bore site ID attribute which is manually entered for each bore site.

 

Alternatively, if there were a way to insert the bore site blocks based off the actual Excel records, populating all attribues and locating the block by the actual X,Y,Z coordinate, that might be even better.

 

Is there an easy way? Is there any lisp to be shared?

 

Newbie

 

I also used to insert blocks from X Y Z coords, but just want to have a look how you want to insert blocks, can you attached example drawing and csv for that, So i can modify my lisp as per your requirement....:)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...