Jump to content

HELP ! Writing Code (AUTOLISP)


jayare

Recommended Posts

hello everyone I am a noob in autolisp and i need help to putting a code together, I am suppose to generate a rotated angle using a codes already generated and incorporating an IFAND statement. The codes just need to be placed in order but i cant piece it together. If anyone can help me that would be great, I would greatly appreciate it. thank you in advanced.

 

 

IFAND CODE-

 

 

; This part of a program sets limits on a 15 x 10

(Defun c: IFAND ( )

(Prompt "\n Please enter dimension for Rectangle, do not exceed 15 X 10 ")

(Setq num1 (getreal "\n Enter Width of rectangle between 1 and 15: "))

(IF (

(setq p1 num1)

)

(setq num2(getreal "\n Enter Heigth1 of rectangle between 1 and 10: "))

(IF (

(setq p2 num2)

)

(IF (and (

(command "rectangle" p1 p2)

(Prompt "Sorry! Wrong Entry, Please try again")

)

)

 

 

 

ROTATED RECTANGLE-

 

;This will draw a Circle at a use specified angle and distance from a center point

; Then array that circle around the center point a user specified number of times

 

(defun c:BC ( )

 

(setvar "cmdecho" 0)

(command "osmode" 0)

(graphscr)

 

 

 

(setq CR1 (getpoint "\n Pick center of unit circle: "))

 

(setq Dia1(getdist "\n Diameter of bolt unit circle: "))

(setq L1 (/ Dial 2)) ;This changes Dial to radius to draw a line at a given distance from center

 

(setq A1 (getangle "\n Enter angle: "))

 

(setq BH1 (getreal "\n Enter the diameter of the bolt hole: "))

(setq BH2 (/ BH1 2))

 

(setq A2 (polar CR1 A1 L1 ));2nd point of line

 

 

(command "Line" CR1 A2 "" )

(command "Circle" CR1 "D" Dia1 )

 

 

(command "Circle" A2 BH2)

 

(command "Array" "Last" "" "Polar" CR1 "6" "360" "No")

 

 

(princ)

 

)

 

 

and here are the instructions

 

aw22is.png

Link to comment
Share on other sites

Have a look at mypost http://www.cadtutor.net/forum/showthread.php?94680-AutoLisp-Loop-funtion-to-redefine-variable

 

Ps my version

 

; draw pits with 100mm walls aligned to line
; By Alan H 2011

(setq oldsnap (getvar "osmode"))
(setq oldlayer (getvar "clayer")) 
(command "_layer" "n" "Design-Drainage-Pits" "c" 4 "Design-Drainage-Pits" "")
(setvar "clayer" "Design-Drainage-Pits")
(if (not AH:getval) (load "getval"))
(ah:getval "Please enter PitL m eg 0.9: " "     edit_width = 8;" "     edit_limit = 6;")
(setq pitl (Atof item))

(ah:getval "Please enter PitW eg 0.6: " "     edit_width = 8;" "     edit_limit = 6;")
(setq pitw (Atof item))

(setq pt1 (getpoint "\npick 1st point to place pit : "))
(setq pt2 (getpoint "\nPick 2nd point for orientation"))
(setvar "osmode" 0)
(setq pt7 (getpoint "\Pick pt on pit side : "))

(setq ang (angle pt1 pt2))
(setq ang5 (angle pt2 pt7))
(setq diffang (- ang ang5))

(if (> diffang 1.5707) 
(setq ang2 (- ang 1.570796))
(setq ang2 (+ ang 1.570796))
)

(setq ang3 (+ ang 3.1415926))
(setq ang4 (- ang 1.570796))
(setq pt3 (polar pt1 ang PitL))
(setq pt4 (polar pt3 ang2 PitW))
(setq pt5 (polar pt4 ang3 PitL))


(command "pline" pt1 pt3 pt4 pt5 "c")

(setq pt6 (polar pt1 ang 50.0))
(command "offset" 0.1 pt4 pt6 "")

(setvar "osmode" oldsnap)
(setvar "clayer" oldlayer)
(princ)

 

;; Input  Dialog box with variable title
;; By Ah June 2012
;; code (ah:getval title)

(defun AH:getval (title width limit / fo)
(setq fname "C://acadtemp//getval.dcl")
(setq fo (open fname "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "key1" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
;(write-line "     edit_width = 18;" fo) 
;(write-line "     edit_limit = 15;" fo)
(write-line width fo) 
(write-line limit fo)
(write-line "   is_enabled = true;" fo)        
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_only;}" fo)
(close fo)

(setq dcl_id (load_dialog  "c:\\acadtemp\\getval"))
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "key1" "(setq item $value)(done_dialog)")
(mode_tile "key1" 2)
(start_dialog)
; returns the value of item
)

Link to comment
Share on other sites

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...