The sketch file macro
The sketch file macro
(OP)
Hey guys,
I use MS Excel to keep my crucial points of a 3d sketch in spreadsheet format. To get the points info I have to click on each point and then copy paste it in excel and I feel really annoyed about doing that(since there's a lot of points). Is there any macro out there that can help store all the points coordinated of a 3d sketch in an Excel file?
I use MS Excel to keep my crucial points of a 3d sketch in spreadsheet format. To get the points info I have to click on each point and then copy paste it in excel and I feel really annoyed about doing that(since there's a lot of points). Is there any macro out there that can help store all the points coordinated of a 3d sketch in an Excel file?






RE: The sketch file macro
Brian
RE: The sketch file macro
3D sketches and point entities in general are a bit lacking still. You could add dimensions from the points to the standard planes and do a design table (maybe an auto-create) then the dims would reflect the points' coordinates and would update. If you use an external DT instead of an embedded one you could then link the values to you spreadsheet and it would all update automatically. That would avoid macros, API's etc.
John Richards Sr. Mech. Engr.
Rockwell Collins Flight Dynamics
There are only 10 types of people in the world - those who understand binary and those who don't.
RE: The sketch file macro
I tried your way first JNR however there's really a lot of points in the 3d sketch and I need a dimension for each coordinate (x, y and z) so 3 times the total number of points is the number of the dimensions. Also I don't know where the auto design table generator is, one that put each dim variable in a spread sheet so I try to look into that first, if you figure it out please let me know how.
Creigbm, you suggested an approach that certainly works at the end, but I have not touched VB yet (I am experienced in C++ and Java) so if I can't figure out any easier method-especially the one mentioned by JNR- I'll have to learn bunch of API functions for both excel and solid works. If you have any other tips I’ll be grateful if you post them.
I really appreciate your help guys.
RE: The sketch file macro
Ken
Sketch Points to Data File Macro
Instructions:
Select the sketch that you wish to "read" and run the macro.
The macro will bring up excel and start filling the sheet with xyz point data.
Sub main()
Dim swApp As SldWorks.SldWorks
Dim doc As SldWorks.ModelDoc2
Dim part As SldWorks.PartDoc
Dim sm As SldWorks.SelectionMgr
Dim feat As SldWorks.feature
Dim sketch As SldWorks.sketch
Dim v As Variant
Dim i As Long
Dim sseg As SldWorks.SketchSegment
Dim sline As SldWorks.SketchLine
Dim sp As SldWorks.SketchPoint
Dim ep As SldWorks.SketchPoint
Dim s As String
Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet
Set exApp = New Excel.Application
If Not exApp Is Nothing Then
exApp.Visible = True
If Not exApp Is Nothing Then
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
If Not sheet Is Nothing Then
sheet.Cells(1, 2).Value = "X"
sheet.Cells(1, 3).Value = "Y"
sheet.Cells(1, 4).Value = "Z"
End If
End If
End If
Set swApp = GetObject(, "sldworks.application")
If Not swApp Is Nothing Then
Set doc = swApp.ActiveDoc
If Not doc Is Nothing Then
If doc.GetType = swDocPART Then
Set part = doc
Set sm = doc.SelectionManager
If Not part Is Nothing And Not sm Is Nothing Then
If sm.GetSelectedObjectType2(1) = swSelSKETCHES Then
Set feat = sm.GetSelectedObject4(1)
Set sketch = feat.GetSpecificFeature
If Not sketch Is Nothing Then
v = sketch.GetSketchPoints
For i = LBound(v) To UBound(v)
Set sp = v(i)
If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
'sheet.Cells(2 + i, 1).Value = "Normal Vector " & i + 1
sheet.Cells(2 + i, 2).Value = Round(sp.x * 1000 / 25.4, DEC)
sheet.Cells(2 + i, 3).Value = Round(sp.y * 1000 / 25.4, DEC)
sheet.Cells(2 + i, 4).Value = Round(sp.z * 1000 / 25.4, DEC)
exApp.Columns.AutoFit
End If
Next i
End If
End If
End If
End If
End If
End If
End Sub
RE: The sketch file macro
Thanks alot for the help.
Pooyan
RE: The sketch file macro
Hi Brad,
We no longer support swconst.bas. Instead, please use swconst.tlb, which you can add to your C++, VB6, or VB.NET project as a type library reference. swconst.tlb is in the same location as sldworks.tlb and sldworks.exe
Bradley
RE: The sketch file macro
I guess you guys are using a newer version of SW because mine is 2002-2003 version and I couldn't find the swconst.tlb. In case I’m wrong and the file is somewhere on hard-drive, can you tell me what do you mean by adding it as a type library reference? Is there a especial method to do this or is it just accomplished by importing the tbl to the project? Please explain.
Thank you.
Pooyan
RE: The sketch file macro
User defined type is not defined.
Object variable or with block variable not set
I tried the following code from the sample help:
Sub GetSketchPoints()
Dim swApp As Object
Dim Part As Object
so how come I get the errors?
Dim sketchPointArray As Variant
' Optional (see below)
Dim theSketchPoint As Object
Dim pointCount As Integer
Dim xValue As Double
Dim yValue As Double
Dim zValue As Double
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set theSketch = Part.GetActiveSketch2
sketchPointArray = theSketch.GetSketchPoints
pointCount = UBound(sketchPointArray) + 1
' For each SketchPoint
For i = 0 To (pointCount - 1)
' Set local SketchPoint object (optional)
' Set theSketchPoint = sketchPointArray(i)
' Get the coordinates
xValue = sketchPointArray(i).X
yValue = sketchPointArray(i).Y
zValue = sketchPointArray(i).Z
' <Do something useful with the data>
Next i
End Sub
RE: The sketch file macro
The swconst.tlb is linked in Visual Basic 6:
In main menu Project, References..., SolidWorks Constant type library.
Bradley
RE: The sketch file macro
Go to the macro page and scroll to the end of the page, there is a "macro" called mm_998.zip.
I made this for my own needs to copy/paste just the few constants I need, but maybe you find it also useful.
HTH,
Stefan
--
unofficial german SolidWorks helppage
http://solidworks.cad.de
Shareware, freeware, tools and macros
http://swtools.cad.de