Presentation is loading. Please wait.

Presentation is loading. Please wait.

AUTOLISP Prof.Dr. Demir Bayka. AUTOLISP 1.Declare and set values to variables 2.Pick the elements of lists 3.Implement AutoCad commands 4.Select Entities.

Similar presentations


Presentation on theme: "AUTOLISP Prof.Dr. Demir Bayka. AUTOLISP 1.Declare and set values to variables 2.Pick the elements of lists 3.Implement AutoCad commands 4.Select Entities."— Presentation transcript:

1 AUTOLISP Prof.Dr. Demir Bayka

2 AUTOLISP 1.Declare and set values to variables 2.Pick the elements of lists 3.Implement AutoCad commands 4.Select Entities IT IS POSSIBLE TO CREATE CAD DRAWINGS IN AUTOCAD THROUGH AUTOLISP TEXT FILES FROM WITHIN A DELPHI 4.0 EXECUTABLE PROGRAM NECESSARY TOPICS

3 All autolisp commands are written in parenthesis > Comment lines begin with > Autolisp files have > extensions Autolisp files can be loaded into Autocad by command line or > in the menu. AUTOLISP

4 Declare and set values to variables The Autolisp command is > (setq x 10)................................x = 10 (setq y x)..................................y = 10 (setq y (* x 2))..........................y = 20 (setq y (+ x 15)).......................y = 25 (set y (list 5 67 12 56 “Black” x 12)) y is set to the array the 4th element of the y-array is 67 the 5th element of the y-array is “Black” the 6th element is 10 (assuming x=10)

5 In autolisp the arithmetic operations are performed as ; (setq ( )) This can be interpreted as ; Variable = value1 (operator) value2 Examples: (setq x (+ 10 5))x = 15 (setq x (- 10 5))x = 5 (setq x (* 10 5))x = 50 (setq x (/ 10 5))x = 2 (setq a 10) (setq b 5) (setq x (* a b))x = 50

6 In autolisp arrays can also be assigned to variables. Then ofcourse that variable will have a first, second,third... and so on values. Arrays may be expressed by preceeding with e.g. An array (1,5,67,99.5,3) may be represented as ; (list 1 5 67 99.5 3) If this array is asigned to a variable (say x) then; (setq x (list 1 5 67 99.5 3)) QUESTION : How do we pick out the first or third element of x ?

7 There are two functions that can be used for this purpose: 1.car(picks the first element of the list) 2.cdr(picks all elements EXCEPT the first) If you want to pick out the third element then you can call once (now you have a list starting with the second element) call again (now you have a list starting with the third element) call and pick out the first element which is the third element of the original list. EXAMPLES (setq x (car (list 1 5 67 99.5 3)))x=1 (setq x (car (cdr (cdr (list 1 5 67 99.5 3)))))x=67 (list 5 67 99.5 3) (list 67 99.5 3) 67

8 The way you interpret a nested combination is FROM RIGHT TO LEFT. Example caddr means (car (cdr (cdr First operation Second operation Third operation Therefore : (setq p3D (list 50 4 205)) (setq x (car p3D))x = 50 (setq x (cadr p3D))x= 4 (setq x (caddr p3D))x = 205 JUST REMEMBER car cadr caddr (x)(y)(z)

9 Implement AutoCad commands AUTOCAD COMMANDS ARE IMPLEMENTED BY THE........ > FUNCTION OF AUTOLISP EXAMPLE (command “line” p1 p2 “”) Draws a line from point p1 to point p2 (command “zoom” “extent”) Zooms to the extent of whatever entities are on the screen (command "pedit" L1 "Y" "join" L2 L3 "" "") Joins L1 L2 L3 lines into a polyline

10 We have learned; 1.How to declare and set values to variables 2.How to pick the elements of lists with (car, cadr, caddr) 3.How to implement AutoCad commands Now we will look at another feature ; SELECTION OF ENTITIES The “entities” could be “a point”, “a line”, “a set of lines”, “a polyline”,“a set of polylines”, “a profile”, “a circle”, “a rectangle”, “a solid”.....etc. There are various methods. We will look into 2 of these. Namely (ssget “L”) and (ssget “X”) functions.

11 (ssget “L”) method is used to select the LAST entity that was created. For example lets draw half of a circle. You may do this by drawing an ARC that has a center point, starting point and an angle (180). The points should be 2D (polylines and arcs are drawn on the XY plane) (setq p0 (list (+ (car cen) R2) (cadr cen) (caddr cen)))p0=(R2,0,0) (setq arccen (list (car cen) (cadr cen)))arccen=(0,0) (setq arc1 (list (car p0) (cadr p0)))arc1=(R2,0) (command "arc" "c" arccen arc1 "a" "180") You have to check from AutoCad Help about the use of the ARC command Now that the arc is drawn you can assign it (the whole list of properties of an arc) to a variable say. In order to do this you must first select it and then use the function. (setq PLarc1 (ssget "L"))

12 Draw a profile for extrusion. Assume this profile has 2 arcs (<PLarc1> and <PLarc2>) and two polylines (<PL1> and <PL2>). We can combine them all into a single polyline <Profile> by the <pedit> Autocad command. (command "pedit" (ssget "X") "Y" "join" (ssget "X") "" "exit") (setq Profile (ssget "L")) As you have noticed in the <pedit> command we have selected all the entities <PLarc1>, <PL1>, <PLarc2>, <PL2> by (ssget “X”). However after the single polyline was formed we selected only that polyline and assigned it to <Profile>. (ssget “X”) method is used to select the ALL SELECTABLE ENTITIES that were created. EXAMPLE


Download ppt "AUTOLISP Prof.Dr. Demir Bayka. AUTOLISP 1.Declare and set values to variables 2.Pick the elements of lists 3.Implement AutoCad commands 4.Select Entities."

Similar presentations


Ads by Google