(defun c:dincamzone(/ dcl_id nub D H Hmax Hmin MG MV fok RAZ); parametry
	(defun Insert_addline
	       (D    H	 Hmax Hmin MG MV fok RAZ / block_adoc ins new_name_block old_block obj sf_obj MG2 KV
			  SQ1  SQ2  S	 G    V	  r1	r2 ang1	ang2 W R K E1    D1   KV2	 SQ3  S1   D2 D3 D4  SQ4 SQ5 SQ6 S2 S3 S4  p1	  p2   p3
			  p4   p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16  osm lay	blk_kub)
	  (vl-load-com)
	  (setq acad_object (vlax-get-acad-object))
	  (setq active_document (vla-get-activedocument acad_object))
	  (setq model_space (vla-get-modelspace active_document))
	  (vla-startundomark active_document)
	  (setq D (GETREAL "\nЗадайте расстояние до объекта, м :"))
	  (setq H (GETREAL "\nЗадайте высоту установки камеры, м : "))
	  (setq Hmax (getreal "\nМаксимальная высота объекта, м : "))
	  (setq Hmin (getreal "\nМинимальная высота объекта, м : "))
	  (setq MG (getreal "\nРазмер матрицы по горизонтали, мм : "))
	  (setq MV (getreal "\nРазмер матрицы по вертикали, мм : "))
	  (setq fok (getreal "\nФокусное расстояние, мм : "))
	  (setq RAZ (getreal "\nРазрешение у камеры по горизонтали, пиксели : "))
	  (setq MG2 (/ MG 2))
	  (setq KV (* (- H Hmax) (- H Hmax) 1000000))
	  (setq SQ1 (sqrt (+ KV (* D D 1000000))))
	  (setq SQ2 (sqrt (+ (* fok fok) (/ (* MG MG) 4))))
	  (setq S (/ (* MG2 SQ1) SQ2))
	  (setq G (* (- H Hmax) 1000))
	  (setq V (/ MV 2))
	  (setq r1 (list G (* D 1000) 0))
	  (setq r2 (list fok V 0))
	  (SETQ ang1 (angle '(0 0 0) r1))
	  (SETQ ang2 (angle '(0 0 0) r2))
	  (setq W (- ang1 (* ang2 2)))
	  (setq R (sin W))
	  (setq K (cos W))
	  (setq E1 (* (- H Hmin) R 1000))
	  (setq D1 (/ E1 K))
	  (setq KV2 (* (- H Hmin) (- H Hmin) 1000000))
	  (setq SQ3 (sqrt (+ KV2 (* D1 D1))))
	  (setq S1 (/ (* MG2 SQ3) SQ2))
	  (setq D2 (* 1000 (/ (* RAZ fok) (* 500 MG))))
	  (setq D3 (* 1000 (/ (* RAZ fok) (* 125 MG))))
	  (setq D4 (* 1000 (/ (* RAZ fok) (* 25 MG))))
	  (setq SQ4 (/ (* (- D2 D1) (- S S1)) (- (* D 1000) D1)))
	  (setq SQ5 (/ (* (- D3 D1) (- S S1)) (- (* D 1000) D1)))
	  (setq SQ6 (/ (* (- D4 D1) (- S S1)) (- (* D 1000) D1)))
	  (setq S2 (+ SQ4 S1))
	  (setq S3 (+ SQ5 S1))
	  (setq S4 (+ SQ6 S1))
	  (setq p1 '(0 0 0))
	  (setq p2 (polar p1 0 (* D 1000)))
	  (setq p3 (polar p2 (/ pi 2) S))
	  (setq p4 (polar p1 0 D1))
	  (setq p5 (polar p4 (/ pi 2) S1))
	  (setq p6 (polar p4 (* pi 1.5) S1))
	  (setq p7 (polar p2 (* pi 1.5) S))
	  (setq p8 (polar p1 0 D2))
	  (setq p9 (polar p1 0 D3))
	  (setq p10 (polar p1 0 D4))
	  (setq p11 (polar p8 (/ pi 2) S2))
	  (setq p12 (polar p8 (* pi 1.5) S2))
	  (setq p13 (polar p9 (/ pi 2) S3))
	  (setq p14 (polar p9 (* pi 1.5) S3))
	  (setq p15 (polar p10 (/ pi 2) S4))
	  (setq p16 (polar p10 (* pi 1.5) S4))
	  (setq	block_adoc
		 (vla-get-blocks
		   (vla-get-ActiveDocument (vlax-get-acad-object))
		 ) ;_  end of_vla-get-blocks
	  ) ;_  end of_setq
	  (if
	    (and
	      (setq ins (car (entsel "\n Select block:")))
	      (= (cdr (assoc 0 (entget ins))) "INSERT")
	      (setq new_name_block (strcat (cdr (assoc 2 (entget ins))) "_" (rtos D) "_" (rtos H) "_" (rtos Hmax) "_" (rtos Hmin) "_" (rtos MG) "_" (rtos MV) "_" (rtos fok) "_" (rtos RAZ)))
	      (snvalid new_name_block)
	    ) ;_  end of_and
	     (progn
	       (setq
		 old_block (vla-item block_adoc (cdr (assoc 2 (entget ins))))
	       ) ;_  end of_setq
	       (vlax-for item old_block
		 (setq obj (cons item obj))
	       ) ;_  end of_vlax-for
	       (setq sf_obj (vlax-make-safearray
			      vlax-vbobject
			      (cons 0 (1- (length obj)))
			    ) ;_  end of_vlax-make-safearray
	       ) ;_  end of_setq
	       (vlax-safearray-fill sf_obj obj)
	       (setq new_block
		      (vla-add block_adoc
			       (vlax-3d-point '(0 0 0))
			       new_name_block
		      ) ;_  end of_vla-add
	       ) ;_  end of_setq
	       (vla-CopyObjects
		 (vla-get-ActiveDocument (vlax-get-acad-object))
		 sf_obj
		 new_block
	       ) ;_  end of_vla-CopyObjects
	       (vla-put-name (vlax-ename->vla-object ins) new_name_block)
	     ) ;_  end of_progn
	  ) ;_  end of_if
	  (setq osm (getvar "osmode"))
	  (setvar "osmode" 0)
	      (command "_.-layer" "_n" "CCTVZONE" "")
	      (command "_.-layer" "_n" "CCTVZONEID" "")
	      (command "_.-layer" "_n" "CCTVZONERASP" "")
	      (command "_.-layer" "_n" "CCTVZONEOBN" "")
	      (command "_.-layer" "_c" "253" "CCTVZONE" "")  
	      (command "_.-layer" "_c" "50" "CCTVZONEID" "") 
	      (command "_.-layer" "_c" "70" "CCTVZONERASP" "")
	      (command "_.-layer" "_c" "130" "CCTVZONEOBN" "")
	      (setq lay (getvar "CLAYER"))
	      (setq blk_kub (vla-add (vla-get-blocks active_document) (vlax-3d-point p1) new_name_block))
	      (cond
		((and (> (* D 1000) D4) (< D1 D2))
		 (setvar "CLAYER" "CCTVZONE")
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p16))
		 (setvar "CLAYER" "CCTVZONEOBN")
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p15))
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p16))
		 (vla-addline blk_kub (vlax-3d-point p16) (vlax-3d-point p14))
		 (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p13))
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p14))
		 (vla-addline blk_kub (vlax-3d-point p14) (vlax-3d-point p12))
		 (setvar "CLAYER" "CCTVZONEID")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p11))
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p12))
		 (vla-addline blk_kub (vlax-3d-point p12) (vlax-3d-point p6))
		 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
	        ((and (> (* D 1000) D3) (< D1 D2) (< (* D 1000) D4))
		 (setvar "CLAYER" "CCTVZONEOBN")
	         (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p14))
	         (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p13))
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p14))
		 (vla-addline blk_kub (vlax-3d-point p14) (vlax-3d-point p12))
		 (setvar "CLAYER" "CCTVZONEID")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p11))
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p12))
		 (vla-addline blk_kub (vlax-3d-point p12) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
		((and (> D1 D2) (< D1 D3) (> (* D 1000) D4))
		 (setvar "CLAYER" "CCTVZONE")
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p16))
		 (setvar "CLAYER" "CCTVZONEOBN")
	         (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p15))
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p16))
		 (vla-addline blk_kub (vlax-3d-point p16) (vlax-3d-point p14))
	         (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p13))
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p14))
		 (vla-addline blk_kub (vlax-3d-point p14) (vlax-3d-point p6))
		 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
	        ((and (> (* D 1000) D2) (< D1 D2) (< (* D 1000) D3)) 
		 (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p12))
		 (setvar "CLAYER" "CCTVZONEID")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p11))
		 (vla-addline blk_kub (vlax-3d-point p11) (vlax-3d-point p12))
		 (vla-addline blk_kub (vlax-3d-point p12) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
		((and (> D1 D2) (< (* D 1000) D4) (> (* D 1000) D3)) 
		 (setvar "CLAYER" "CCTVZONEOBN")
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p14))
		 (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p13) (vlax-3d-point p14))
		 (vla-addline blk_kub (vlax-3d-point p14) (vlax-3d-point p6))
		 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
	  	 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p13))
		)
		((and (> D1 D3) (> (* D 1000) D4) (< D1 D4)) 
		 (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p16))
		 (setvar "CLAYER" "CCTVZONEOBN")
		 (vla-addline blk_kub (vlax-3d-point p15) (vlax-3d-point p16))
		 (vla-addline blk_kub (vlax-3d-point p16) (vlax-3d-point p6))
		 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
	  	 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p15))
		)
	        ((< (* D 1000) D2) 
		 (setvar "CLAYER" "CCTVZONEID")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
		((and (> D1 D2) (< (* D 1000) D3))
		 (setvar "CLAYER" "CCTVZONERASP")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
	        ((and (> D1 D3) (< (* D 1000) D4))
		 (setvar "CLAYER" "CCTVZONEOBN")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
		((> D1 D4)
		 (setvar "CLAYER" "CCTVZONE")
		 (vla-addline blk_kub (vlax-3d-point p5) (vlax-3d-point p3))
		 (vla-addline blk_kub (vlax-3d-point p3) (vlax-3d-point p7))
		 (vla-addline blk_kub (vlax-3d-point p7) (vlax-3d-point p6))
	  	 (vla-addline blk_kub (vlax-3d-point p6) (vlax-3d-point p5))
		)
	      )
	      (setvar "CLAYER" lay)
	  (setvar "osmode" osm)
	  (vla-endundomark active_document)
	) ;end func addline
)