Results 1 to 5 of 5

Thread: Need Help with 3D Bolt Creating Lisp

  1. #1
    Member
    Join Date
    2013-08
    Posts
    2
    Login to Give a bone
    0

    Default Need Help with 3D Bolt Creating Lisp

    Hi Everyone,

    So I'm creating a 3d bolt creating lisp and I'm almost there but am hitting a wall. I want to create the thread on a bolt using a helix and triangular profile. I want to create it using a 3dpoly starting at the end of the shank of the bolt. I want to define pt10 and pt11 in the program (which I started but am stuck) below the shank. I think my biggest problem is the helix. I was told the command is defined by base point, base radius, top radius, height of individual threads, distance between coils, and height of the helix. I think that the height of the individual coils needed to be larger than the triangle because of round off errors (which makes sense but I am not sure if this value is what is giving me trouble). When I go to run the program, its stops at the creation of the triangle and the helix. the triangle appears to be the correct size but the helix spacing seems too small.

    If you could help me find any errors in my program, I would greatly appreciate it.

    I attached the lsp file
    Attached Files Attached Files

  2. #2
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: Need Help with 3D Bolt Creating Lisp

    My first thought - is it *really* necessary to have physically accurate threads? Unless this is for 3D printing (and even then, it could still be tapped or threaded afterwards), a simple clearance/engagement solid would still work and be much faster.

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Need Help with 3D Bolt Creating Lisp

    Something like this.

    I wrote this to be a general function for creating threads based on length of shaft, pitch of threads (height), inside radius and outside radius of threads.

    Hope that helps

    P=

    Code:
    (defun C:Threads (/ sngLength sngPitch sngInsideRadius sngOutsideRadius)
     (if (and (setq sngInsideRadius     (getdist "\nEnter Inside Radius: "))
              (setq sngOutsideRadius    (getdist "\nEnter Outside Radius: "))
              (setq sngPitch            (getdist "\nEnter Pitch (height of each thread): "))
              (setq sngLength           (getdist "\nEnter Shaft Length: "))
              (/= sngOutsideRadius sngInsideRadius)
              (> sngOutsideRadius sngInsideRadius)
         )
      (Threads sngLength sngPitch sngInsideRadius sngOutsideRadius)
      (princ "\nError")
     )
    )
    
    (defun Threads (sngLength sngPitch sngInsideRadius sngOutsideRadius / 
                   intTurns  entHelix entRegion)
     (if (and (setq intTurns            (fix (+ 0.01 (/ sngLength sngPitch))))
              (vl-cmdf "3dface"
                       (list sngInsideRadius 0.0 0.0)
                       (list sngInsideRadius 0.0 (/ sngPitch 2.01))
                       (list sngOutsideRadius 0.0 0.0)  
                       (list sngInsideRadius 0.0 (/ sngPitch -2.01))    
              )
              (vl-cmdf "region" (entlast) "")
              (setq entRegion (entlast))
              (vl-cmdf "helix" "0,0" (list sngInsideRadius 0.0 0.0) "" "T" intTurns sngLength)
              (setq entHelix  (entlast))
          )
      (vl-cmdf "sweep" entRegion "" "a" "n" entHelix)
      (princ "\nError")
     )
    )
    
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2016-10-20 at 07:28 PM.
    AutomateCAD

  4. #4
    Member Jim_Fisher's Avatar
    Join Date
    2015-12
    Location
    Texas
    Posts
    31
    Login to Give a bone
    0

    Default Re: Need Help with 3D Bolt Creating Lisp

    I tweaked your code a little (see below) and got this:
    Untitled.png

    ... and here's the modified code.

    Code:
    ; Bolt3D1.LSP
    ;Kateri Kaminski 
    ; call function 
    (defun c:bolt3d1 ()
      ; set props
      (setq sblip (getvar "blipmode"))
      (setq scmde (getvar "cmdecho"))
      (setq snp (getvar "osmode"))
      (setq 3dosmd (getvar "3dosmode"))
      (setq dyucs (getvar "ucsdetect"))
      (setvar "blipmode" 0)
      (setvar "cmdecho" 0)
      (setvar "osmode" 0)
      (setvar "3dosmode" 0)
      (setvar "ucsdetect" 0)
      ;start loop
      (setq A "y")
      (while (= A "y")
        ;get variables
        (setq D1 (getreal "\nInput Diameter of Bolt Head"))
        (setq L1 (getreal "\nInput Length of Bolt Head"))
        (setq pt1 (getpoint "\nEnter Location of Bolt Head"))
        (setq D2 (getreal "\nInput Diameter of Shank"))
        (setq L2 (getreal "\nInput Length of Shank"))
        (setq L3 (getreal "\nInput Length of Thread"))
        ;calc dims
        (setq R1 (/ D1 2))
        (setq R2 (/ D2 2))
        (setq R3 (/ (* 1.09 R1) 0.6))
        (setq L4 (+ L1 R1))
        (setq pt2 (list (+ (car pt1) R1) (cadr pt1) (caddr pt1)))
        (setq pt3 (list (car pt1) (cadr pt1) (-(+ L1 (* D1 0.15)) R3)))
        (setq pt4 (list (car pt1) (cadr pt1) (- L3 L2)))
        (setq pt5 (list (- (car pt1) (/ (* D1 0.1) 2)) (- (cadr pt1) R1) (- (+ (caddr pt1) L1) (* L1 0.1))))
        (setq pt6 (list (+ (car pt1) (/ (* D1 0.1) 2)) (+ (cadr pt1) R1) (+ (+ (caddr pt1) L1) (* D1 0.15))))
        ;create bolt head
        (command "CYLINDER" pt1 pt2 L4)
        (setq e1 (entlast))
        (command "SPHERE" pt3 R3)
        (command "INTERSECT" e1 "l" "")
        (setq e2 (entlast))
        (command "CYLINDER" pt1 pt2 L1)
        (command "UNION" e2 "l" "")
        (setq e3 (entlast))
        (command "BOX" pt5 pt6)
        (command "SUBTRACT" e3 "" "l" "")
        (setq e4 (entlast))
        ;create shank
        ;create non-threaded portion
        (if (> L2 L3) (progn
          (command "CYLINDER" pt1 R2 (- L3 L2))
          (command "UNION" e4 "l" "")
          (setq e4 (entlast))
          )
         )
        ;create cylinder inside the threaded portion
        (command "CYLINDER" pt4 (* R2 0.8) (- L3))
        (command "UNION" e4 "l" "")
        (setq e5 (entlast))
        ; calc thread triangle
        ; calc pt7,8,9
        (setq pt7 (list (+ (car pt1) (* R2 0.8)) (cadr pt1) (- (- (caddr pt1) L2) (* 0.2 D2))))
        (setq pt8 (list (+ (car pt1) R2) (cadr pt1) (+ (caddr pt7) (* D2 0.1))))
        (setq pt9 (list (car pt7) (cadr pt1) (+ (caddr pt7) (* D2 0.2))))
        (setq pt10 (list (car pt1) (cadr pt1) (caddr pt8)))
        (setq pt11 (list (car pt1) (cadr pt1) (caddr pt7)))
        (command "3DPOLY" pt7 pt8 pt9 "c")
        (setq e6 (entlast))
        ;changed this line ...
        ;(command "HELIX" pt10 (* 0.8 R2) (* 0.8 R2) (* 0.201 D2) (* 0.41 R2) (+ L3 (* 0.2 D2)))
        ;to this ...
        (command "helix" pt10 (* 0.8 R2) (* 0.8 R2) "H" (+ (distance pt7 pt9) 0.005) (list (car pt10) (cadr pt10) (+ (caddr pt10) L3)))
        (setq e7 (entlast))
        (command "SWEEP" e6 "" e7)  ; <-- and changed this line
        (setq e8 (entlast))
        (command "union" e5 e8 "")
        (setq e9 (entlast))
        (command "CYLINDER" pt11 R2 (* 0.2 D2))
        (setq e10 (entlast))
        (command "SUBTRACT" e9 "" e10 "")    
       (setq A (getstring "\nDo you want to create another bolt (y or n)?"))
        )
    ; go to iso view
      (command "ucs" "w")
      (command "vpoint" (list 1 -1 1))  
    ; hide hidden lines
      (command "hide")
    ; set back to starting state
      (setvar "blipmode" sblip)
      (setvar "cmdecho" scmde)
      (setvar "osmode" snp)
      (setvar "3dosmode" 3dosmd)
      (setvar "ucsdetect" dyucs)
        )
    Although I would tend to agree with the observation that you probably don't really need threating that's so accurate.

    Jim
    Attached Images Attached Images
    ~ Hamburgers! The cornerstone of any nutritious breakfast. ~

    ~ Mind if I try one of yours? This is yours here, right? ~

    ~ Mmm-mmmm. That is a tasty burger. ~

  5. #5
    Member
    Join Date
    2014-01
    Location
    Winter Park, FL.
    Posts
    8
    Login to Give a bone
    0

    Default Re: Need Help with 3D Bolt Creating Lisp

    That is very cool! Inspiring....

Similar Threads

  1. Dynamic Blocks - Creating dynamic bolt blocks
    By jake1889 in forum Dynamic Blocks - Technical
    Replies: 3
    Last Post: 2014-08-08, 12:56 PM
  2. Creating Fields Using LISP
    By cwade.109269 in forum AutoCAD Customization
    Replies: 3
    Last Post: 2009-03-23, 04:54 PM
  3. CREATING MENU BAR FOR LISP FILE
    By drsvsmani in forum AutoLISP
    Replies: 1
    Last Post: 2008-05-12, 12:06 PM
  4. Creating leader with lisp routine
    By VBOYAJI in forum AutoLISP
    Replies: 4
    Last Post: 2006-12-20, 10:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •