Jump to content

Recommended Posts

Posted

As a self taught coder, I'm fairly proud of this minor accomplishment... I submit this for your review / scrutiny / amusment..... Im just waiting for someone to say, "You could have done this in 5 lines!!" :shock:

 

It makes a standard part that we use daily.

Typically diameter = 6 and length = 15

 

Eventually I would like to add an error trap and some conditionials... length cant be less than 4 and diameter cant be less than 2.25, and apply an IF.... But this is a good start... for me any ways...

;                     ;
;; SIMPLE BAR EJECTOR;;
;                     ;
;      JPLANERA       ;
(defun C:EJ ()
 (setq dia(getreal "\nEnter bar diameter: ")
lg (getreal "\nEnter ejector height: ")
IP (getpoint "\nSelect insertion point:")
OLDORTHO (GETVAR "ORTHOMODE")
rad (/ dia 2)
;ALL POS X VALUES
X1 (+(car ip) 0.75)
X2 (+(car ip) 1)
X3 (+(car ip) 1.125)
X4 (-(+(car ip) rad) 0.125)
X5 (+(car ip) rad)
;ALL POS Y VALUES
Y1 (cadr ip) 
Y2 (+(cadr ip) 0.25)
Y3 (+(cadr ip) 8.875)
Y4 (+(cadr ip) 9)
Y5 (+(cadr ip) 9.125)
Y6 (+(cadr ip) 11)
Y7 (+(cadr ip) 11.7089)
Y8 (-(+(cadr ip) lg 9) 2.7089)
Y9 (-(+(cadr ip) lg 9) 2)
Y10(-(+(cadr ip) lg 9) 0.125)
Y11(+(cadr ip) lg 9)
;LIST GENERATOR
       p1 (list X1 Y1)
p2 (list X2 Y2)
p3 (list X2 Y3)
p4 (list X3 Y4)
p5 (list X4 Y4)
p6 (list X5 Y5)
p7 (list X5 Y6)
p8 (list X4 Y7)
p9 (list X4 Y8)
p10 (list X5 Y9)
p11 (list X5 Y10)
p12 (list X4 Y11)
)
 (SETVAR "ORTHOMODE" 1)
 (entmake (list '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  '(100 . "AcDbPolyline")
  '(90 . 14)
  '(8 . "EJECTORS")
  (cons 10 ip)
  (cons 10 p1)
  (cons 42  0.414214)
  (cons 10 p2)
  (cons 10 p3)
  (cons 42  -0.414214)
  (cons 10 p4)
  (cons 10 p5)
  (cons 42  0.414214)
  (cons 10 p6)
  (cons 10 p7)
  (cons 10 p8)
  (cons 10 p9)
  (cons 10 p10)
  (cons 10 p11)
  (cons 42  0.414214)
  (cons 10 p12)
  (list 10 (car ip) (+(cadr ip) lg 9))
  '(70 . 0)))
 (command "mirror" "l" "[email="" ip "@0,1"]" ip "@0,1[/email]" "")
 (SETVAR "ORTHOMODE" OLDORTHO)
 )

Posted
As a self taught coder, I'm fairly proud of this minor accomplishment... I submit this for your review / scrutiny / amusment..... Im just waiting for someone to say, "You could have done this in 5 lines!!" :shock:

 

It makes a standard part that we use daily.

Typically diameter = 6 and length = 15

 

Eventually I would like to add an error trap and some conditionials... length cant be less than 4 and diameter cant be less than 2.25, and apply an IF.... But this is a good start... for me any ways...

; ;
;; SIMPLE BAR EJECTOR;;
; ;
; JPLANERA ;
(defun C:EJ ()
(setq dia(getreal "\nEnter bar diameter: ")
lg (getreal "\nEnter ejector height: ")
IP (getpoint "\nSelect insertion point:")
OLDORTHO (GETVAR "ORTHOMODE")
rad (/ dia 2)
;ALL POS X VALUES
X1 (+(car ip) 0.75)
X2 (+(car ip) 1)
X3 (+(car ip) 1.125)
X4 (-(+(car ip) rad) 0.125)
X5 (+(car ip) rad)
;ALL POS Y VALUES
Y1 (cadr ip) 
Y2 (+(cadr ip) 0.25)
Y3 (+(cadr ip) 8.875)
Y4 (+(cadr ip) 9)
Y5 (+(cadr ip) 9.125)
Y6 (+(cadr ip) 11)
Y7 (+(cadr ip) 11.7089)
Y8 (-(+(cadr ip) lg 9) 2.7089)
Y9 (-(+(cadr ip) lg 9) 2)
Y10(-(+(cadr ip) lg 9) 0.125)
Y11(+(cadr ip) lg 9)
;LIST GENERATOR
p1 (list X1 Y1)
p2 (list X2 Y2)
p3 (list X2 Y3)
p4 (list X3 Y4)
p5 (list X4 Y4)
p6 (list X5 Y5)
p7 (list X5 Y6)
p8 (list X4 Y7)
p9 (list X4 Y8)
p10 (list X5 Y9)
p11 (list X5 Y10)
p12 (list X4 Y11)
)
(SETVAR "ORTHOMODE" 1)
(entmake (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 14)
'(8 . "EJECTORS")
(cons 10 ip)
(cons 10 p1)
(cons 42 0.414214)
(cons 10 p2)
(cons 10 p3)
(cons 42 -0.414214)
(cons 10 p4)
(cons 10 p5)
(cons 42 0.414214)
(cons 10 p6)
(cons 10 p7)
(cons 10 p8)
(cons 10 p9)
(cons 10 p10)
(cons 10 p11)
(cons 42 0.414214)
(cons 10 p12)
(list 10 (car ip) (+(cadr ip) lg 9))
'(70 . 0)))
(command "mirror" "l" "" ip "@0,1" "")
(SETVAR "ORTHOMODE" OLDORTHO)
)

 

Great Job!

 

It looks like one of those paddles where you whack somebody and they reply: "Thank You Sir, May I have another?"

 

I hope there is a big demand for these?

Posted

Just a couple of suggestions its just the way I do things its not right or wrong if your code works don't change it

 

Y1 (cadr ip) then y2 (+ y1 0.25) rather than cadr every time same for X

 

Its a good habit to set "osmode" to 0 Autocad has a nasty of sometimes snapping to a close by object also cmdecho to 1 stops the command line showing what your doing its just distracting good while debugging

 

 

say (setq OLDORTHO (GETVAR "ORTHOMODE") oldsnap (getvar "osmode")) (setvar "cmdecho" 1) reset when finished

 

maybe

(setq dia 3.9)

(while (

(setq dia(getreal "\nEnter bar diameter: "))

)

Posted

Thanks AL,

 

After I posted the original code, I went back and added all the necessary variable settings. I also broke the program into two subroutines for different situations. Im going to tweak a little more, and try your suggestions to streamline the code. What is the purpose of the WHILE statement? Is this saying, "only GETREAL while diameter is greater than 4?"

Posted

'while' makes a loop

 

congrats on your first coding!

Posted

You said the length can not be less than 4 above so the idea of the while is it will keep asking for input till you answer 4 or above also a change to it

 

(while (

(setq dia(getreal "\nEnter bar diameter : ")) ; press enter key = 4.0 as answer just a short cut for standard answers

(if (= dia nil)(setq dia 4.0))

)

Posted (edited)

Ah i see... I have refined the program to contain 2 sub routines, so my main program has all the input info. Because i have added the second routine, i have no need for the while loop, i can just run the second routine which has the adjustments to accomodate the size.. would this be a correct procedure/format??

 

(defun C:EJ ()
 (initget 7)
 (setq dia(getreal "\nEnter bar diameter: "))
 (if (<= 2.5 dia)
   (progn
     (initget 7)
     (setq lg (getreal "\nEnter ejector height: "))
     (initget 7)
     (setq IP (getpoint "\nSelect insertion point: "))
     (if (>= lg 5.5)(EJSTANDARD)(EJFLAT))
   )
   (progn
     (alert "BAR DIAMETER MUST BE\nGREATER THAN 2.500\"")
     (PRINC)
   );End progn
  );End if
 );End defun

 

Thank you for all the input.

 

 

Edit: now that i think of it.. instead of the alert, i can put the while loop there for the 2.500! duh

Edited by JPlanera
lightbulb!!
Posted

Hi JPlanera,

 

I personally don't like forcing a user to hit Esc to exit a program, as this is considered an error. I prefer to allow the program to exit should the user not supply the goods.

 

This is how I might approach the prompts:

 

(defun c:EJ ( / dia lg ip )

 (while (and (setq dia (getdist "\nSpecify Bar Diameter: ")) (< dia 2.5))
   (princ "\n** Bar Diameter must be greater than or equal to 2.5 **")
 )

 (if
   (and dia
     (progn
       (initget 6)
       (setq lg (getdist "\nSpecify Ejector Height: " ))
     )
     (setq ip (getpoint "\nSelect Insertion Point: "))
   )
   (if (<= lg 5.5)
     (EJFLAT)
     (EJSTANDARD)
   )
 )

 (princ)
)

Or, you could also combine the WHILE loop into the AND statement thus:

 

(defun c:EJ ( / dia lg ip )

 (if
   (and
     (progn
       (while (and (setq dia (getdist "\nSpecify Bar Diameter: ")) (< dia 2.5))
         (princ "\n** Bar Diameter must be greater than or equal to 2.5 **")
       )
       dia
     )
     (progn
       (initget 6)
       (setq lg (getdist "\nSpecify Ejector Height: " ))
     )
     (setq ip (getpoint "\nSelect Insertion Point: "))
   )
   (if (<= lg 5.5)
     (EJFLAT)
     (EJSTANDARD)
   )
 )

 (princ)
)

Some more food for thought may be found here :)

 

Good luck!

 

Lee

Posted

Thanks Lee. One thing that my experience lacks is good error management, or input protection if you will. Ive been trying to get my company to foot the bill on some formal classes, but honestly between your and jeff sanders website, i am slowly not needing these classes!! haha oh btw, have you been to the CHAT section lately?8)

Posted
Thanks Lee. One thing that my experience lacks is good error management, or input protection if you will. Ive been trying to get my company to foot the bill on some formal classes, but honestly between your and jeff sanders website, i am slowly not needing these classes!!

 

To be honest, your code wasn't bad - the initget statement provides the error trapping to prevent null user input - this is a valid approach. I only offered my alternative as I don't particularly like cases in which the only exit is to punch the Esc key - and my alternative is most likely a little verbose anyway.

 

haha oh btw, have you been to the CHAT section lately?8)

 

Come out of my cave... you must be joking :lol: Will take a look now :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...