Newhere
New member
- Dec 20, 2012
- 2
Hello!
handleman posted a macro on thread thread559-160366
This macro is supposed to write the coordinates of sketch points to an excel file, and I desperately need to get it to work
I copy/paste the macro here again:
I select a 3d-sketch-point, run the macro, but it doesnt seem to do anything! If I dont select a sketchpoint and run the macro, it even doesnt come up the message box which should tell me "Select a sketch point of a 3D sketch and run macro again". What am I doing wrong? Where would I find the excel-file if it was created?
I would be very, very happy if you can help me!
P.S. I appologize for any grammar mistakes, English is not my home language
handleman posted a macro on thread thread559-160366
This macro is supposed to write the coordinates of sketch points to an excel file, and I desperately need to get it to work
I copy/paste the macro here again:
Code:
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Public Pfx As String
Dim myNote As SldWorks.Note
Dim SelMgr As SldWorks.SelectionMgr
Dim mySketchPoint As SldWorks.SketchPoint
Dim mySketch As SldWorks.Sketch
Dim AllSketchPoints As Variant
Const FMAT As String = "0.00"
Const SF As Double = 1000
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Const FirstRow As Long = 4
Const FirstCol As Long = 2
Dim CurRow As Long
Dim IDCol As Long
Dim Xcol As Long
Dim Ycol As Long
Dim Zcol As Long
Dim PtID As Variant
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
If (SelMgr.GetSelectedObjectType3(1, -1) <> 11) And (SelMgr.GetSelectedObjectType3(1, -1) <> 25) Then
MsgBox "Select a sketch point of a 3D sketch and run macro again"
Exit Sub
End If
Set mySketchPoint = SelMgr.GetSelectedObject6(1, -1)
Set mySketch = mySketchPoint.GetSketch
AllSketchPoints = mySketch.GetSketchPoints2
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets("Sheet1")
CurRow = FirstRow
IDCol = FirstCol
Xcol = FirstCol + 1
Ycol = FirstCol + 2
Zcol = FirstCol + 3
xlSheet.Cells(CurRow, IDCol).Value = "'Point ID"
xlSheet.Cells(CurRow, Xcol).Value = "'X Coord"
xlSheet.Cells(CurRow, Ycol).Value = "'Y Coord"
xlSheet.Cells(CurRow, Zcol).Value = "'Z Coord"
CurRow = CurRow + 1
For i = 0 To UBound(AllSketchPoints)
PtID = AllSketchPoints(i).GetID
xlSheet.Cells(CurRow, IDCol).Value = PtID(0) & "," & PtID(1)
xlSheet.Cells(CurRow, Xcol).Value = Format(AllSketchPoints(i).X * SF, FMAT)
xlSheet.Cells(CurRow, Ycol).Value = Format(AllSketchPoints(i).Y * SF, FMAT)
xlSheet.Cells(CurRow, Zcol).Value = Format(AllSketchPoints(i).Z * SF, FMAT)
CurRow = CurRow + 1
Next i
Part.ClearSelection Part.WindowRedraw
End Sub
I select a 3d-sketch-point, run the macro, but it doesnt seem to do anything! If I dont select a sketchpoint and run the macro, it even doesnt come up the message box which should tell me "Select a sketch point of a 3D sketch and run macro again". What am I doing wrong? Where would I find the excel-file if it was created?
I would be very, very happy if you can help me!
P.S. I appologize for any grammar mistakes, English is not my home language