ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MNMuhammad Nuri06/02/2012

Hi,

I need help. I have a macro that runs and archimedes spiral sketch points on a plane. However, I would like the sketch points to either be sketched on a surface, or for the sketch points to be brought to the surface. This is because I want to find the z-coordinates of the points on the surface.

Thank you for your help!

_________________________________________________________________________________________________________________________

Dim swApp As SldWorks.SldWorks
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Rad As Double, f As Double
    Dim N As Double, Nt As Double
    Dim dR As Double, R As Double
    Dim i As Double, ang As Double
    Private Const Pi As Double = 3.14159265358979

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

'Create a projection plane
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
Dim myRefPlane As Object
Set myRefPlane = Part.FeatureManager.InsertRefPlane(8, 0.005, 0, 0, 0, 0)
Part.ClearSelection2 True

Rad = 20     'Radius mm
    f = 0.5     'Feedrate mm/rev
   
    N = 72          'No. of points/rev
    Nt = Rad / f * N + 1 'Total No. of points
    dR = f / N       'Feed/point

Dim X As Double, Y As Double

' create a point on projected plane
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", _
    0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Dim skPoint As Object
   

    For i = 0 To Nt
        R = Rad - dR * i
        ang = (360 / N * i) 'Mod 360
        X = R * Cos(ang * Pi / 180) / 1000

        Y = R * Sin(ang * Pi / 180) / 1000

Set skPoint = Part.SketchManager.CreatePoint(X, Y, 0) '0.0012, 0.000077, 0)
    Next i


Part.ClearSelection2 True
Part.SketchManager.InsertSketch True

End Sub