Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Request for help on a thread creation LISP

5 REPLIES 5
Reply
Message 1 of 6
paulstapelberg
397 Views, 5 Replies

Request for help on a thread creation LISP

Good day all.

 

I need help with my LISP code. I have only started to learn LISP programming 2 days ago, So I am new to all this.

 

Here is my code:

 

[code]

(defun c:circ ( / bp rad height height1 turns)
(setq bp (getpoint "pick basepoint:"))
(setq rad (getdist "\nenter radius:"))
(setq height (getdist "specify height:"))
(setq height1 (getdist "specify height:"))
(setq turns (getint "specify number of turns:"))

(command "_cylinder" bp rad height)
(setq cyl (entlast))
(command "_helix" bp rad rad height1 turns)
(setq hel (entlast))


)

[/code]

 

I need theLISP to do the following:

1. create a circle and extrude to user specifications

2. create a helix around the cylinder to user specifications, including number of turns.

3. Sweep a user defined shope/profile along the helix.

4. subtract the two shapes to get the final thread pattern on the cylinder.

 

Any help would be much appreciated

 

 

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: paulstapelberg

Hello Paul and welcome to the Autodesk Community!

 

To automate this task using AutoLISP, you'll need to test all entered values before provide the command with those values, (e.g. to the cylinder command the height must be nonzero...)

 

One way to ensure this is using the initget function and the if function. Note that I use the not function with the initget function just to force a return T from the initget function whose return is always nil and would make fail the if function

 

(if (and (setq bp (getpoint "\nPick basepoint: "))
  (setq rad (getdist "\nEnter cylinder radius: "))
  (not (initget 2))
  (setq height (getdist "\nEnter cylinder height: "))
  (setq height1 (getdist "\nEnter helix height: "))
  (not (initget 2))
  (setq turns (getint "\nSpecify number of turns: "))
    );; and (progn

 

For the helix command you'll need to change the order to use the 'number of turns...

 

(command "_helix" bp rad rad "_T" turns height1)

 For the sweep command, you'll have to explain better what kind of objects and what kind of option you want to use with the command...

 

HTH

Henrique

EESignature

Message 3 of 6
paulstapelberg
in reply to: hmsilva

Thanks for the help.

 

I have added a file for you to have a look at.

my idea is as follows:

once the cylinder and helix has been created, i would like to give the user the option to insert a profile (eg. circle or square)that will be swept along the helix. this will create the thread on the cylender.

Message 4 of 6
hmsilva
in reply to: paulstapelberg

Something like this perhaps.

 

(defun c:circ (/ ans bp cyl height height1 hel obj obj1 pt1 rad rad1 turns width)

  (defun MK_CIRCLE (pt rad)
    (entmake
      (list
	'(0 . "CIRCLE")
	(cons 10 pt)
	(cons 40 rad)
      )
    )
  )

  (defun MK_RECTANGLE (pt len / PT1)
    (entmake
      (list (cons 0 "LWPOLYLINE")
	    (cons 100 "AcDbEntity")
	    (cons 100 "AcDbPolyline")
	    (cons 90 5)
	    (cons 70 1)
	    (cons 10 pt)
	    (cons 10 (setq pt1 (polar pt 0 len)))
	    (cons 10 (polar pt1 (/ pi 2.0) len))
	    (cons 10 (polar pt (/ pi 2.0) len))
	    (cons 10 pt)
      )
    )
  )

  (if
    (and (setq bp (getpoint "\nPick basepoint: "))
	 (not (initget 6));; non zero and positive
	 (setq rad (getdist "\nEnter cylinder radius: "))
	 (not (initget 2));; non zero
	 (setq height (getdist "\nEnter cylinder height: "))
	 (setq height1 (getdist "\nEnter helix height: "))
	 (not (initget 6));; non zero and positive
	 (setq turns (getint "\nSpecify number of turns: "))
	 (not (initget 1 "Circle Rectangle"))
	 (setq ans (getkword "\nSelect shape to sweep [Circle/Rectangle]: "))
	 (cond ((wcmatch ans "Circle")
		(not (initget 6));; non zero and positive
		(setq rad1 (getdist "\nEnter circle radius: "))
	       )
	       (T
		(not (initget 6));; non zero and positive
		(setq width (getdist "\nEnter rectangle width: "))
	       )
	 );; cond
    );; and
     (progn
       (command "_.cylinder" bp rad height)
       (setq cyl (entlast))
       (command "_.helix" bp rad rad "_T" turns height1)
       (setq hel (entlast))
       (if (wcmatch ans "Circle")
	 (MK_CIRCLE bp rad1)
	 (MK_RECTANGLE bp width)
       )
       (setq obj (entlast))
       (command "_.sweep" obj "" hel)
       (if (not (eq obj (setq obj1 (entlast))))
	 (command "_.subtract" cyl "" obj1 "")
	 (prompt "\nUnable to sweep the selected object!")
	 );; if
     );; progn
  );; if
  (princ)
);; circ

 

HTH

Henrique

EESignature

Message 5 of 6
paulstapelberg
in reply to: hmsilva

Thank you so much for all that help. I am learning a massive amount today. Really appreciate everything.
Message 6 of 6
hmsilva
in reply to: paulstapelberg

You're welcome, Paul
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost