Presentation is loading. Please wait.

Presentation is loading. Please wait.

LESSON 5 PREPARING THE AUTOLISP CODE It is assumed that you have completed. Therefore the following lesson will show you what happens when you press the.

Similar presentations


Presentation on theme: "LESSON 5 PREPARING THE AUTOLISP CODE It is assumed that you have completed. Therefore the following lesson will show you what happens when you press the."— Presentation transcript:

1 LESSON 5 PREPARING THE AUTOLISP CODE It is assumed that you have completed. Therefore the following lesson will show you what happens when you press the and other buttons. In this project we will be using AutoCad R14 for creating the drawings. AutoCad can export drawings as bitmap images. Your program will activate AutoCad and after AutoCad has finished its task, you will be able to display the different drawing views as bitmap images.

2 is a call to this procedure with the parameters (obtained from and (number of screenshots of the animated view)

3 The directory path that is imported is known as in this procedure. Don’t mix it with the local variable used for establising the directory path of the autolisp file.

4 Some local variables are defined. However, some variables such as “Diameter” may also be used. The file is created and opened. A set of initial instructions to AutoCad are written automatically

5 is in unit and has REPLACED the function and the array. I forgot to, but you can delete array.

6 You don’t have to write any new code. However you have to change ; Statement[1] := ’(arxload “geom3d”)’; To Writeln(F,’(arxload “geom3d”)’);

7 ALL AUTOLISP COMMANDS ARE IN PARENTHESES (....) In AutoLisp there is a function which is used for assigning values to variables. Therefore when a variable is assigned a value by it is also being DECLARED as well. Delphi can also EXPORT variables to autolisp. The “string values” of string variables can be writen by WRITELN procedure. e.g. x : string; (declaration) x := ’10.5’; (assigned value) Writeln(F,‘+x+’); Output : 10.5 This feature will allow our drawings to be parametric.

8 You may put comments in autolisp code. Comments are preceeded by (;). Eg. ;SET LINER PARAMETRES

9 First we will change the numerical value of the global variable (divided by 2) to a string variable (local to our code) str(Diameter*1000/2:5:2,R1) Then we will declare a numerical variable (local to the autolisp code) and assign it the value corresponding to the string representation of in this code. Writeln(F,’(setq R1 ‘+R1+’)’); If R1 := ’10.5’ (by str) then autolisp program will have the line (setq R1 10.5) this declares R1 and sets its value to 10.5

10 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

11 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 ?

12 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

13 This looks very cumbersome but that’s how it is. However, there is a SHORTCUT ! It is possible to NEST and possible nests are : caaaar cadaar cdaaar cddaar caaadr cadadr cdaadr cddadr caaar cadar cdaar cddar caadar caddar cdadar cdddar caaddr cadddr cdaddr cddddr caadr caddr cdadr cdddr caar cadr cdar cddr However for our purposes picking out the first (x coordinate), second (y coordinate) and third (z coordinate) elements of a variable that represents the 3D position of a point is enough.

14 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)

15 These are the parametric variables that are obtained as a result of calculation in your program. Their values have been assigned in autolisp as : (calculated as R1+t in autolisp)

16 AutoCad commands can be given in AutoLisp commands. The syntax is : (command “CommandName” parameters) For example when you start the drawing you would probably want to set one of the the layers that you already defined (in WriteInitialLines). Now you need to know the syntax of the command in AutoCad. So start there and open AutoCad Help and look up the Command.

17 You will use the option. So try it out in Autocad R14 and see what prompts you get and note how you respond. Simulate your actions in AutoLisp.

18 The code will be as follows ; writeln(F,'(command "Layer" "Set" "0_centerline" "")'); This is the name of the command This is the option Of that is selected This is the name of the layer The interaction with can continue. However it is good policy to give your commands in steps. So to end dialog send empty return “”.

19 Now set the end points of the x and y axis and join them by a line (the linetype for layer was __ _ __ _ __ For the x axis define and and for the y axis define and All of the points are in 3D space. Therefore they have x,y,z values. In the a center point was defined and the origin of the universal coordinate system (UCS) was set at which had the coordinate values of (0,0,0). Therefore is in fact a variable representing a list of elements. is (1.5xR1) to the left of the origin is (1.5xR1) to the right of the origin is (1.5xR1) to the top of the origin is (R1+H) to the bottom of the origin

20 The corresponding autolisp commands are : (setq cenx1 (list (- (car cen) (* R1 1.5)) 0 0)) First element of second element third element A = 1.5 x R1 since (car cen) = 0  0 – A = - A cenx1 = (-A,0,0) After and are set a line is drawn between them Code for drawing the centerlines

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

22 (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"))

23 Code for the top view of the liner profile (half of the liner)

24 Now we have drawn the profile of the top view of the liner. This profile has 2 arcs ( and ) and two polylines ( and ). We can combine them all into a single polyline by the Autocad command. (command "pedit" (ssget "X") "Y" "join" (ssget "X") "" "exit") (setq TopProfile (ssget "L")) As you have noticed in the command we have selected all the entities,,, by (ssget “X”). However after the single polyline was formed we selected only that polyline and assigned it to.

25 Finally the drawing is zoomed out to the extents of the display (command “z” “e”) and the path and name of the bitmap image is set. Everything is selected and assigned to and finally the the AutoCad command is used to send the display as a bitmap image.


Download ppt "LESSON 5 PREPARING THE AUTOLISP CODE It is assumed that you have completed. Therefore the following lesson will show you what happens when you press the."

Similar presentations


Ads by Google