helix BVBA

Discussion in 'AutoCAD' started by Bruce Minty, Nov 2, 2003.

  1. Bruce Minty

    Bruce Minty Guest

    This is little VBA code to create a helix and I am hoping that someone out
    there has more skill than me can help get this to work.
    Thanks
    Bruce
    b*** remove the *'s to contact directly by email but I
    would rather see any response posted to this group

    Option Explicit
    Public Sub calc1()
    Dim points(200) As Integer
    ' ReDim points(1 To 10) As Integer
    Dim x, y, z, h, t As Integer
    Dim counter
    t = 5
    h = 24
    For z = 1 To 36
    Select Case t
    Case t <= 90
    x = 1 / Cos(t) * h
    z = z + 1
    t = t + 5
    Case 90 <= t <= 180
    t = 180 - t
    x = 1 / Cos(t) * h
    z = z + 1
    t = t + 5
    Case 180 <= t <= 270
    t = 270 - t
    t = 90 - t
    x = 1 / Cos(t) * h
    z = z + 1
    t = t + 5
    Case 270 <= t <= 360
    t = 360 - t
    t = 90 - t
    x = 1 / Cos(t) * h
    z = z + 1
    t = t + 5
    End Select
    x = points(counter)
    y = points(counter + 1)
    'z = points(counter + 2)
    Next
    End
    End Sub

    Public Sub calc2()
    Dim points()
    Dim counter
    For counter = 0 To 200 Step 1
    Print points("+ Str(counter)+")
    Next
    End Sub
     
    Bruce Minty, Nov 2, 2003
    #1
  2. Bruce Minty

    designer Guest

    I do VB to create DXF files so they can be loaded into either full ACAD or
    LT.
    I think the following code gives a passable helix based on straight lines in
    3D space.
    You may find it helpful.

    Regards

    The form has three inputs "number of rotations", "radius" and "pitch" and
    two buttons "Create helix" and "EXIT"

    Private Sub Command1_Click()
    End
    End Sub

    Private Sub Command2_Click()
    Nr = Val(Text1.Text) 'number of rotations
    Rad = Val(Text2.Text) 'radius of helix
    Pt = Val(Text3.Text) 'pitch of helix
    'use 5 deg increments
    Inc = 360 / 5 'number if increments in a pitch
    Zi = Pt / Inc 'position in Z axis
    Itot = Nr * Inc ' total number of increments
    X1 = Rad 'initial x
    Y1 = 0 'initial y
    Z1 = 0 'initial z
    I = 1

    dxfTempFile = "C:\tempHelix.dxf"
    'dxfTempFile = GetTempFileName
    FileNo = FreeFile
    newCreateDXF.FileNo = FileNo 'passes FileNo to DXF module
    Open dxfTempFile For Output As #FileNo
    'Open dxfTempFile For Output As #1

    Lay = "Helix"
    Ltype = "Continuous"
    Call dxfHeader(-Val(Text2.Text) - 1, -Val(Text2.Text) - 1, Val(Text2.Text) +
    1, Val(Text2.Text) + 1)
    Call dxfStartTables
    Call dxfAddLayer(Lay, 1)
    Call dxfEndLayerTable
    Call dxfEndTables
    Call dxfStartEntity
    While I < (Itot + 1)
    X2 = Val(Text2.Text) * Cos(I * 0.087266)
    Y2 = Val(Text2.Text) * Sin(I * 0.087266)
    Z2 = I * Zi
    Call dxfAddLine(X1, Y1, Z1, X2, Y2, Z2, Lay, Ltype, 1)
    X1 = X2
    Y1 = Y2
    Z1 = Z2
    I = I + 1
    Wend
    Call dxfClose
    Close #FileNo

    End Sub

    Private Sub Form_Load()
    Text1.Text = "1"
    Text2.Text = "1"
    Text3.Text = "1"
    End Sub
     
    designer, Nov 2, 2003
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.