Autolisp to Visual lisp: Design Solutions for Autocad instructor’s Guide Chapter One


Note: the underscores in the following Answers represent spaces



Download 210.39 Kb.
Page3/8
Date05.05.2018
Size210.39 Kb.
#47999
1   2   3   4   5   6   7   8

Note: the underscores in the following Answers represent spaces


16. Thi

17. 57


18. of_he

19. anguage_t

20._resistor tow is 500.00 volts
21. (IF (< answer 10)

(SETQ variable 11)

)
22. (IF (AND (< answer 6)(> answer 5))

(PROGN


(SETQ VariableOne 7)

(SETQ VariableTwo 20)

)

)
23. (IF (AND (< answer 6)(> answer 2))



(PROGN

(SETQ VariableOne 15)

(SETQ VariableTwo 50)

)

(PROGN



(SETQ VariableOne 1)

(SETQ VariableTwo 2)

)

)
24. (IF (OR (< answer 6)(> answer 2))



(PROGN

(SETQ VariableOne 15)

(SETQ VariableTwo 50)

)

(PROGN



(SETQ VariableOne 1)

(SETQ VariableTwo 2)

)

)
25. ("this is an" "example list" "1" 3 4 5 T)



26. "this is an"

27. "example list"



  1. ("example list" "1" 3 4 5 T)

  2. "1"

  3. (nth exampleList 4)

  4. 4

  5. ; error: bad argument type: consp nil

  6. nil

  7. T

  8. "example list"

  9. (setq two (list 'A 'B 'C 'D))

  10. (append one two)

  11. (list one two)

  12. (append (list one two) three)

  13. (append (append (list one two three) three)one)

  14. (length (append (append (list one two three) three)one))

  15. (CADDR (append (append (list one two three) three)one))

  16. (list (append (append (list (list one two three) three (append one two) two three) three) two) three one)



Chapter Four




Definitions

Association List - is a list in which the elements that are contained within are linked by an index.


Dotted Pair – A special type of sub-list contained within an association list in which the two elements are separated by a period.
Extended Entity Data – Provides the programmer with a means of storing and managing information in an object’s association list using DXF codes. The attached information can be relevant or non-relevant to the particular entity.
Graphic Entity – is a visible object used to create a drawing (Lines, polylines, etc.).
Loop – is the continuous execution of a program or a portion of a program as long as a predefined test condition holds true.
Non-Graphic Entities is any object that is not visible to the AutoCAD user (Layer, Linetype, Dimension Styles, Text Styles, Etc.).

Answers to Review Questions

2. In an association list the elements are linked to an index, where as elements in a list are not.


3. In a dotted pair only one element is association with a unique index where as an association list can have multiple elements associated with an index.
4. When an entity is created using ENTMAKEX an owner is not assigned.
5. A loop can be created in an AutoLISP program by using either the WHILE or REPEATE functions.
6. The NENTSEL function allows a program to directly access a nested entity contained within a complex object.
7. CONS (CONS 8 “Example Layer Name”)
8. SUBST (SUBST NewListItem OldListItem EntityList)
9. ENTDEL
10. True
11. False, an AutoLISP association list can be modified by using the ENTMOD function.
12. The AutoLISP WHILE function will continue executing a sequence of functions as long as the predefined test conditions holds true, where as the REPEAT function will execute a sequence of functions a predetermined number of times.
13. False, In AutoLISP there is no limit to the number of loops that can be contained (nested) inside another or even one another.
14. False, AutoLISP allows for loops to be placed within either an IF expression or a COND expression.
15. False, The number of expressions that can be evaluated by a WHILE loop or REPEAT function is determined only by the placement of the closing parenthesis.
16. (3 . "The value is 4")
17. ; error: misplaced dot on input
18. ((4 . 0.65) (5 . 0.08))
19. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 8.17993 5.83581 0.0) (11 4.18605 3.58163 0.0) (210 0.0 0.0 1.0))
20.
21. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2F") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 1.98023 6.95455 0.0) (11 3.3338 4.83395 0.0) (210 0.0 0.0 1.0))
22.
23. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 8.17993 5.83581 0.0) (11 4.18605 3.58163 0.0) (210 0.0 0.0 1.0))
24.
25. ("this is an example" "list")
26. ("this is an example" "list")
27.
28. 5
29. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2B") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 9.84791 5.59698 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0))
30. (10 9.84791 5.59698 0.0)
31. ; error: too many arguments
32. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2C") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine(10 9.9 8.8 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0))
33. ; error: bad argument type: ((-1 . ) (0 . "LINE") (330 . ) (5 . "2C") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine(10 9.9 8.8 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0))
34.
35.

(Setq num 10)

(While (> num cnt)

(setq numberOne (getreal "\nEnter first number : ")

numberTwo (getreal Enter second number :)

)

;;;;;; Malformed List



(if (= numberOne numberTwo)

(Princ "\nThe two number entered are the same : ")

(setq answer (* numberOne numerTwo))

)

;;;;; Malformed List



(princ "The products of the two numbers are" (rtos answer))

)
36.

(while (<= loop_cnt list_cnt)

(setq resistor (nth loop_cnt resistor_list))

(if (/= resistor nil)

(setq equilivent_resistance

(+ equilivent_resistance resistor)

)

)



(setq loop_cnt (1- loop_cnt))

)
37.

(DEFUN c:CalculateBtu()

(SETQ Cnt 1

TotalRFactor 0

)

(REPEAT 10



(SETQ Prompt (STRCAT “\nEnter the R value for material # “

(Itoa Cnt)

)

TotalRFactor ( +



(GETREAL Prompt)

TotalRFactor

)

Cnt (1+ Cnt)



OutAirTemp (GETREAL “\nEnter outside Air Temp : “)

InAirTemp (GETREAL “\nEnter inside Air Temp : “)

WallLength (GETREAL “\nEnter wall length : “)

WallHeight (GETREAL “\nEnter wall height : “)

WallArea ( * WallLength WallHeight)

Ufactor (/ 1.0 TotalRFactor)

DeltaTemp (ABS (- OutAirTemp InAirTemp))

BtuPerHour (* WallArea Ufactor DeltaTemp)

)

)

)


38.

(DEFUN C:ChangeLine ()

(SETQ Entity (ENTSEL “\nSelect line to change”))

(If (/= Entity Nil)

(PROGN

(SETQ Ent (ENTGET (CAR Entity)))



(IF (= (CDR (ASSOC 0 Ent)) “LINE”)

(PROGN


(SETQ PointOne (GETPOINT “\nSelect first

point of Line”)

PointTwo (GETPOINT “\nSelect second

point of line”)

PointOne (CONS 10 PointOne)

PointTwo (CONS 11 PointTwo)

Ent (SUBST PointOne (Assoc 10 ent) ent)

Ent (SUBST PointTwo (Assoc 10 ent) ent)

)

(ENTMOD Ent)



(ENTUPD (CAR Ent))

)

(ALERT “A line must be selected”)



)

)

(ALERT “Nothing Selected”)



)

)

39.



(DEFUN c:CalculateBtu()

(SETQ Cnt 1

TotalRFactor 0

)

(REPEAT 10



(SETQ Prompt (STRCAT “\nEnter the R value for material # “

(Itoa Cnt)

)

TotalRFactor ( +



(GETREAL Prompt)

TotalRFactor

)

Cnt (1+ Cnt)



OutAirTemp (GETREAL “\nEnter outside Air Temp : “)

InAirTemp (GETREAL “\nEnter inside Air Temp : “)

WallLength (GETREAL “\nEnter wall length : “)

WallHeight (GETREAL “\nEnter wall height : “)

WallArea ( * WallLength WallHeight)

Ufactor (/ 1.0 TotalRFactor)

DeltaTemp (ABS (- OutAirTemp InAirTemp))

BtuPerHour (* WallArea Ufactor DeltaTemp)

)

)

;**********************************************



;

;

; New Section for writing Result to either the screen



; or an ASCII Text file.

;

;



;**********************************************

(SETQ Answer (GETSTRING “\nWrite results to either a ile or raphic

screen : “)

)

(IF (OR (= Answer “F”) (= Answer “f”)



(PROGN

(SETQ File1 (OPEN “OutPut.Txt” “w”))

(Write-Line BtuPerHour File1)

(Close file1)

)

(PROGN


(PRINC (STRCAT “\nThe total btu per hour heat loss is “

(RTOS BtuPerHour)

)

)

(PRINC)



)

)

Chapter Five






Download 210.39 Kb.

Share with your friends:
1   2   3   4   5   6   7   8




The database is protected by copyright ©ininet.org 2024
send message

    Main page