Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: Anonymous

Yes. When I tested with your excel file, it worked.

After a very brief comparison, it clicked, and I finally realized why mine wasn't creating the spline.

I had changed my excel files values several times, including how many rows had data in them.

The number of loops I was telling it to do in the code didn't match the number of rows of filled in data available within my Excel file.  This wasn't a problem for creating the points, or sketch points, or collections, but was a problem for the spline creation.

Once I updated my code to match the number of rows of data available within my Excel file, it worked like a charm.

I knew it was going to be something really simple like that.

So I dug around to find the code I used to use to find the last row on a sheet that contained data, and I found it.

You have to access the Excel app the hard way (not so bad, just no intellisence type feedback) to use this though.

See below:

 

Dim oExcelApp = CreateObject("Excel.Application")
oExcelApp.DisplayAlerts = False
Dim oXLFile As String = "S:\Engineering\SHARED\Tests\Points To Import.xlsx"
Dim oSheet As String = "Sheet1"
Dim oWB = oExcelApp.Workbooks.Open(oXLFile)
Dim oWS = oWB.Sheets.Item(oSheet)
Dim oLastRowUsed As Integer = oExcelApp.ActiveSheet.UsedRange.Rows.Count
MsgBox("Last row being used is Row#:  " & oLastRowUsed)
oWB.Close
oExcelApp = Nothing

 

So, I adapted this technique into my current code to make it 'smarter', and prevent that error.

Now my code looks like this...and it works great.

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oCoords(2) As Double
Dim oPoint As Point
Dim oSkPt3d As SketchPoint3D
Dim oSketch3d As Sketch3D = oPDef.Sketches3D.Add()

Dim oExcelApp = CreateObject("Excel.Application")
oExcelApp.DisplayAlerts = False
Dim oXLFile As String = "S:\Engineering\SHARED\Tests\Points To Import.xlsx"
Dim oSheet As String = "Sheet1"
Dim oWB = oExcelApp.Workbooks.Open(oXLFile)
Dim oWS = oWB.Sheets.Item(oSheet)
Dim oLastRowUsed As Integer = oExcelApp.ActiveSheet.UsedRange.Rows.Count
'MsgBox("Last row being used is Row#:  " & oLastRowUsed)
Dim oTitleRow As Integer = 2
Dim oFirstDataRow As Integer = 3

For i As Integer = oFirstDataRow To oLastRowUsed
	oCoords(0) = oWS.Range("A" & i).Value
	oCoords(1) = oWS.Range("B" & i).Value
	oCoords(2) = oWS.Range("C" & i).Value
	oPoint = oTG.CreatePoint(oCoords(0), oCoords(1), oCoords(2))
'	oPoints.Add(oPoint)
	oSkPt3d = oSketch3d.SketchPoints3D.Add(oPoint, True)
Next
Dim oSkPoints As ObjectCollection = oTO.CreateObjectCollection(oSketch3d.SketchPoints3D)
System.Threading.Thread.Sleep(1000)
Dim oSpline As SketchSpline3D = oSketch3d.SketchSplines3D.Add(oSkPoints,SplineFitMethodEnum.kSmoothSplineFit)
oWB.Close
oExcelApp = Nothing

Wesley Crihfield

EESignature

(Not an Autodesk Employee)