Работа с графическими объектами AutoCAD с использованием языка AutoLISP. Учебно-методическое пособие
.pdf
|
Задания к лабораторной работе № 4 |
|
|
№ |
Рисунок |
1 |
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
5
6
7
8
31
9
10
11
12
13
14
15
16
32
17
18
Использование цикла while
(command "_VSLIDE" "fas") |
|
||
(setq |
pt_ins (getpoint "\nУкажите точку вставки : ") |
||
a |
(getdist |
pt_ins "\na = |
: ") |
b |
(getdist |
pt_ins "\nb = |
: ") |
lf |
(getdist |
pt_ins "\nlf= |
: ") |
)
(while (>= lf a)
(alert Недопустимое значение параметра lf!\n Повторите ввод...")
(setq lf (getdist pt_ins "\nlf= : "))
) |
|
|
|
|
|
(setq hf |
(getdist pt_ins "\nhf= : ") |
|
|||
x_ins |
(car |
pt_ins) |
|
|
|
y_ins |
(cadr pt_ins) |
|
|
|
|
pt1 |
(list (+ x_ins |
a) |
y_ins) |
|
|
pt2 |
(list (+ x_ins |
a) |
(+ y_ins (- b hf)) ) |
||
pt3 |
(list (+ x_ins (- a lf)) (+ y_ins b) |
) |
|||
pt4 |
(list |
x_ins |
|
(+ y_ins b) |
) |
)
(command "_REDRAW")
(command "_PLINE" pt_ins pt1 pt2 pt3 pt4 "_C")
; размеры
(command "_DIMLINEAR"
33
pt_ins |
pt1 |
(list x_ins |
(- y_ins (* b 0.3))) |
) |
|
|
|
(command "_DIMLINEAR" |
|
||
pt_ins |
pt4 |
(list (- x_ins (* b 0.3)) y_ins ) |
|
) |
|
|
|
(princ) |
|
|
|
Рисование многоугольника
(setq pt_ins |
(getpoint |
"\nУкажите точку вставки : |
||
") |
|
|
|
|
r |
(getdist pt_ins |
"\nРадиус: ") |
||
n |
(getint |
"\nЗадайте число вершин: ") |
||
pi2 |
(* 2 pi) |
|
|
|
fi |
0.0 |
|
|
|
d_fi |
(/ |
(* pi 2) |
n) |
|
pt1 |
(polar pt_ins fi r) |
|||
)
(while (< fi pi2) (setq fi (+ fi d_fi)
pt2 (polar pt_ins fi r)
)
(command "_LINE" pt1 pt2 "") (setq pt1 pt2)
) ; end while (princ)
34
Лабораторная работа №5 Создание простой параметрической модели конструкции с использованием операций
циклического повторения.
Задание: На языке AutoLISP написать программу рисования конструкции (см. рис.) в соответствии с набором параметров (число панелей произвольное). Набор параметров, необходимых для отрисовки, определить самостоятельно. В программе предусмотреть простановку трёх произвольных размеров.
Пример: Рисование прямоугольной фермы c помощью циклических операций
; сохранение тек. режима объект. прив.
(setq osmode_old (getvar "OSMODE")
pt_ins (getpoint |
"\nУкажите точку вставки : ") |
|||
hf |
(getdist |
pt_ins "\nЗадайте высоту фермы : ") |
||
lf |
(getdist |
pt_ins "\nЗадайте пролёт фермы : ") |
||
n_ots |
(getint |
"\nЗадайте число отсеков: ") |
||
dx |
|
(/ lf n_ots) |
|
|
x_ins |
(car pt_ins) |
|
||
y_low |
(cadr pt_ins) |
|||
y_up |
(+ y_low hf) |
|
||
x_cur |
x_ins |
|
|
|
)
(setvar "OSMODE" 0) ; пояса
35
(repeat n_ots
(setq pt1_low (list x_cur y_low) pt1_up (list x_cur y_up) x_cur (+ x_cur dx) pt2_low (list x_cur y_low) pt2_up (list x_cur y_up)
)
(command "_LINE" pt1_low pt2_low "") (command "_LINE" pt1_up pt2_up "")
) ; end repeat ; стойки
(setq x_cur x_ins ) (repeat (+ n_ots 1)
(command "_LINE" (list x_cur y_low) (list x_cur y_up)
""
)
(setq x_cur (+ x_cur dx)) ) ;end repeat
(setvar "OSMODE" osmode_old ) (princ)
Рисование фермы c раскосами
; сохранение тек. режима объект. прив.
(setq osmode_old (getvar "OSMODE")
pt_ins (getpoint |
"\nУкажите точку вставки : ") |
h_ferm (getdist |
pt_ins "\nЗадайте высоту фермы : ") |
l_ferm (getdist |
pt_ins "\nЗадайте пролёт фермы : ") |
n_ots (getint |
"\nЗадайте число отсеков: ") |
|
36 |
n_pan |
(* n_ots 2) |
|
|
|
||
dx |
(/ l_ferm n_pan) |
|
|
|
||
x_ins |
(car pt_ins) |
|
|
|
||
y_low |
(cadr pt_ins) |
|
|
|
||
y_up |
(+ y_low h_ferm) |
|
|
|
||
) |
|
|
|
|
|
|
(setvar "OSMODE" 0) |
|
|
|
|||
; верхний пояс |
|
|
|
|||
(setq x_cur (+ x_ins dx) ) |
|
|
|
|||
(repeat (- n_pan 2) |
|
|
|
|||
(setq |
pt1 |
(list x_cur y_up ) |
|
|
||
x_cur (+ x_cur dx) |
|
|
|
|||
pt2 (list x_cur y_up) |
|
|
|
|||
) |
|
|
|
|
|
|
(command "_LINE" pt1 pt2 |
"") |
|
||||
) |
|
|
|
|
|
|
; Раскосы и нижний пояс |
|
|
|
|||
(setq x_cur (+ x_ins dx ) |
|
|
|
|||
ots_cur 0 |
|
|
|
|
||
) |
|
|
|
|
|
|
(repeat n_ots |
|
|
|
|
||
(setq |
pt1_up |
(list x_cur |
|
y_up ) |
||
pt1_low |
(list x_cur |
y_low ) |
||||
pt2 |
(list (- x_cur dx) y_low) |
|
||||
pt3 |
(list (+ x_cur dx) y_low) |
|
||||
x_cur |
(+ x_cur dx dx) |
|
|
|
||
ots_cur |
(+ ots_cur 1) |
|
|
|
||
) |
|
|
|
|
|
|
(command "_LINE" pt1_up pt2 |
"") ; раскос-1 |
|||||
(command "_LINE" pt1_up |
|
pt3 |
"") ; раскос-2 |
|||
(command "_LINE" pt2 pt1_low |
"") ; нижний пояс-1 |
|||||
(command "_LINE" pt3 pt1_low |
"") ; нижний пояс-2 |
|||||
) |
|
|
|
|
|
|
; Стойки |
|
|
|
|
|
|
|
|
|
37 |
|
||
(setq x_cur |
(+ x_ins dx ) |
) |
(repeat (- n_pan 1) |
|
|
(setq pt1_up (list x_cur |
y_up ) |
|
pt1_low |
(list x_cur |
y_low ) |
x_cur |
(+ x_cur dx) |
|
)
(command "_LINE" pt1_up pt1_low "")
) |
|
|
; размеры |
|
|
(setq pt2 |
(list (+ x_ins |
l_ferm) y_low) |
ptr2 |
(list x_ins |
(- y_low h_ferm)) |
)
(command "_DIMLINEAR" pt_ins pt2 ptr2 ) (setvar "OSMODE" osmode_old )
(princ)
|
Задания к лабораторной работе № 5 |
№ |
Конструкция |
1 |
|
2
38
3 |
4 |
5 |
6 |
7 |
39 |
8 |
9 |
10 |
11 |
12 |
13 |
40 |
