Does anyone know the best method to import XYZ Coordinate data into MDT5?
I have an Excel Spreadsheet with point data for an impellor. I wish to create a spline through these points.
The following VBA code reads data from EXCEL and draws an spline in autocad.
You should keep open the excel document containing the data while running the macro. All data must start from address A1 in excel active sheet and X, Y, and Z coordinates for each fitpoint is read respectively from columns A, B, and C.
Copy and paste the following code into a module in AutoCAD VBA editor and save it under an arbitrary name. Then run the "Main" macro using the "VBARUN" command.
Option Explicit
Option Base 0
Sub Main()
Dim ex As Object
Dim tt As Worksheet
Dim I As Integer
Dim J As Integer
Set ex = GetObject(, "EXCEL.Application"
Set tt = ex.ActiveSheet
I = 0
tt.Cells(1, 1).Activate
Do While Not IsEmpty(ex.ActiveCell.Offset(I, 0))
I = I + 1
Loop
I = I * 3 - 1
Dim FitPoints() As Double
ReDim FitPoints(I)
I = (I - 1) / 3
J = 0
Do While J <= I
FitPoints(0 + J * 3) = ex.ActiveCell.Offset(J, 0)
FitPoints(1 + J * 3) = ex.ActiveCell.Offset(J, 1)
FitPoints(2 + J * 3) = ex.ActiveCell.Offset(J, 2)
J = J + 1
Loop
Dim startTan(2) As Double
Dim endTan(2) As Double
Dim SPLObj As AcadSpline
startTan(0) = 1: startTan(1) = 0: startTan(2) = 0
endTan(0) = 0: endTan(1) = -1: endTan(2) = 0
Set SPLObj = ThisDrawing.ModelSpace.AddSpline(FitPoints, startTan, endTan)
ZoomAll
End Sub