(defun _wyczyscLaout ()
  (_mnil '(layout_findFiles layout_folder layout_do_wstaw _dialogArkusze _tworzArkusz msg_dialogA1 _dlgAtrArk _wstawOpisA1 _getViewPort _odczytajRzutnie _psFolder set_scaleViewport
           set_styleSheet _wykonajArkusz grdraw_formatka _tworzNowyArkusz CanonicalMediaNames->list PlotDeviceNames->list SetPlotDevice SetMediaName _dialogWyrys _dialogKartaZ
           _dialogWyrys1 RamkaObrocona _wskazArkusze UtworzArkusze)))

(defun _ustawModel ()
(if (= (getvar #tilemode) 0)
             (progn
               (if !command-s
                 (command-s "_PSPACE")
                 (vl-cmdf "_PSPACE"))
               (setvar #tilemode 1)
               )))
(defun C:ARKPL  (/ arkusze)
  (_ustawModel)
  (if (and (loadif "_#layout") (tryb T0))
    (progn 
      
           (if (setq arkusze (_dialogArkusze))
             (_wykonajArkusz arkusze))
           (_wyczyscLaout)     
           (lovar)))
  (princ))

(defun C:WYRYS  (/ arkusz skala params wierz item point size w viewport ss godloA)
  (_ustawModel)
  (if (and (loadif "_#layout") (tryb T0))
    (progn (setq arkusz "Wyrys"
                 skala  (dwg_skala))
           (if (and (_tworzNowyArkusz arkusz) (setq params (_dialogWyrys arkusz)))
             (progn
               (if (setq wierz (_odczytajRzutnie (car params) arkusz))
                 (progn (setq w '())
                        (foreach & wierz (setq w (append w (list (car &)))))
                        (setq size (vertex_minmax w)
                              size (list (- (car (cadr size)) (car (car size))) (- (cadr (cadr size)) (cadr (car size)))))
                        (if (setq point (grdraw_formatka 'size nil))
                          (progn (setvar #tilemode 0)
                                 (setq godloA (_godloArkusza point (dwg_uklad) (dwg_skala) nil T))
                                 (vl-cmdf "_PSPACE")
                                 (setq ss (ssget "_X" '((67 . 1))))
                                 (if ss
                                   (vl-cmdf "_ERASE" ss ""))
                                 (setq item (_createPolylineLuki "PARRZ" 1 wierz))
                                 (if #LTVer
                                   (vl-cmdf "-$VPORTS" "_O" item)
                                   (vl-cmdf "_VPORTS" "_O" item))
                                 (setq viewport (entlast))
                                 (set_scaleViewPort viewport (_: 1E3 skala))
                                 (vla-put-plotTable
                                   (vlax->Layer "PARRZ")
                                   (if (nth 1 params)
                                     :vlax-true
                                     :vlax-false))
                                 (set_styleSheet (not (nth 2 params)))
                                 (vl-cmdf "_MSPACE")
                                 (vl-cmdf "_ZOOM" "_L" point "")
                                 (vl-cmdf "_PSPACE")
                                 (if (car params)
                                   (progn (_wstawOpisA1 (_dlgAtrArk (car params) skala (if godloA (car godloA) "") point size) '(0 0))))
                                 (wstawBlok nil "Strzałka" "pln" '(0 0) #obrot nil nil nil nil)))))))
           (_wyczyscLaout)
           (lovar)))
  (princ))

(defun C:PLN () (wstawBlok T0 "Strzałka" "pln" (getvar "VIEWCTR") #obrot nil nil nil nil))

;;;; Dokonczyc wstawianie bloku (wpierw insert dalej MOVE)
(defun wstawBlok  (tr layer nazwa pk katObrotu prop typ code fnOp / latr okbl)
  (if (or (and tr (start_tryb tr)) (null tr))
    (progn (CodeMessage code)
           (arxMakeLayer layer)
      (if (definiuj_blok nazwa T)
        (progn
           (setLay layer)
           (setq latr (read_attdef->block nazwa 'okbl))
           (cond ((null okbl))
                 (T (command #c_INSERT nazwa pk 1 1 0.0)
                    (command "_.MOVE" (entlast) "" pk PAUSE)))))
           (if tr
             (lovar))
    )))

(defun C:KARTAZ  (/ szablon rodzaj params arkusz wierz ss item layout w1 w2 pkt dy dx z1 z2)

  (if (and (loadif "_#layout") (Tryb T0))
    (progn (setq szablon (strcat #msg_arkusze_path "MsgKartaZ.dwg"))
           (if (findfile szablon)
             (if (setq params (_dialogKartaZ))
               (progn (setq arkusz (strcat "ZAS-" (nth 0 params))
                            pkt    (nth 1 params)
                            rodzaj (nth 2 params))
                      (if (_tworzNowyArkusz arkusz)
                        (progn
                          (if (setq wierz (_odczytajRzutnie szablon nil))
                            (progn (setq w1 (car (nth 0 wierz))
                                         w2 (car (nth 2 wierz))
                                         dy (/ (- (car w2) (car w1)) 2.0)
                                         dx (/ (- (cadr w2) (cadr w1)) 2.0)
                                         z1 (list (- (car pkt) dy) (- (cadr pkt) dx))
                                         z2 (list (+ (car pkt) dy) (+ (cadr pkt) dx)))
                                   (if !command-s
                                     (command-s "_LAYOUT" "_Set" arkusz)
                                     (vl-cmdf "_LAYOUT" "_Set" arkusz))
                                   (setvar "TILEMODE" 0)
                                   (setq layout (vla-get-activeLayout #acadDoc))
                                   (SetMediaName layout "A4")
                                   (setq ss (ssget "_X" '((67 . 1))))
                                   (if ss
                                     (if !command-s
                                       (command-s "_.ERASE" ss "")
                                       (vl-cmdf "_.ERASE" ss "")))
                                   (arxMakeLayer "PARRZ") 
                                   (setq item (vla-InsertBlock (vla-get-PaperSpace #acadDoc) (vlax-3d-point (list 0 0 0)) szablon 1.0 1.0 1.0 0.0))

                                   (foreach & (nth 3 params)
                                     (SetAttByName  item (car &) (cadr &))
                                   )
                                   (setvar "TILEMODE" 1)
                                   (setvar "TILEMODE" 0)
                              
                                   (if (or #GSTAR #GSTAR2016 #BRICS)
                                     (progn (vl-cmdf "_MVIEW" w1 w2) (setq viewport (entlast)))
                                     (setq viewport (arxAddViewport w1 w2 (_: 1E3 (dwg_skala)))))
                              
                                   (if !command-s
                                     (command-s "_MSPACE")
                                     (vl-cmdf "_MSPACE"))
                                   (if !command-s
                                     (command-s "_ZOOM" "_W" z1 z2)
                                     (command "_ZOOM" "_W" z1 z2))
                                   (if !command-s
                                     (command-s "_PSPACE")
                                     (vl-cmdf "_PSPACE"))
                                   (if (null #GSTAR2016)                                     
                                     (_MsgBurst (vlax-vla-object->ename item)))
                                   (cond ((= rodzaj "0")
                                          (setq z1 nil))
                                         ((= rodzaj "1")
                                          (setq z1 (list 231.588 131.374)
                                                z2 (list 252.505 137.605)
                                                w1 (list 252.505 131.374)
                                                w2 (list 282.534 137.605)))
                                         ((= rodzaj "2")
                                          (setq z1 (list 199.6 131.374)
                                                z2 (list 231.588 137.605)
                                                w1 (list 252.505 131.374)
                                                w2 (list 282.534 137.605)))
                                         (T
                                          (setq z1 (list 199.6 131.374)
                                                z2 (list 231.588 137.605)
                                                w1 (list 231.588 131.374)
                                                w2 (list 252.505 137.605))))
                                   (if z1
                                     (progn
                                   (vla-addLine (vla-get-PaperSpace #acadDoc) (vlax-3D-point z1) (vlax-3D-point z2))
                                   (vla-addLine (vla-get-PaperSpace #acadDoc) (vlax-3D-point (list (car z1) (cadr z2))) (vlax-3D-point (list (car z2) (cadr z1))))

                                   (vla-addLine (vla-get-PaperSpace #acadDoc) (vlax-3D-point w1) (vlax-3D-point w2))
                                   (vla-addLine (vla-get-PaperSpace #acadDoc) (vlax-3D-point (list (car w1) (cadr w2))) (vlax-3D-point (list (car w2) (cadr w1))))
                                     ))
                              (if #GSTAR2016
                                (prompt "\nUżyj polecenia _BURST aby rozbić blok oraz poleceń _MSPACE i _PSPACE aby ustawić prezentację...")
                                (prompt "\nUżywaj poleceń _MSPACE i _PSPACE aby ustawić prezentację..."))
                            )
                            (arx_message_box #tile_msg2000 (strcat "Nie odnaleziona rzutnia w szablonie\n" szablon) 7 2 0 1))))))
             (arx_message_box #tile_msg2000 (strcat "Nie odnaleziony szablon\n" szablon) 7 2 0 1))
           (_wyczyscLaout)
           (lovar)))
  (princ))

(defun C:WYRYSN  (/ arkusz wierz params blok ramka kolor cols rows obrot LWyrys pp _vPorts pt atrybuty &&)
  (if (loadif "_#layout")
    (progn (Tryb T0)
           (setq arkusz "Wyrys")
           (if (and (_tworzNowyArkusz arkusz) (setq params (_dialogWyrys1 arkusz)))
             (if (and (setq wierz (_odczytajRzutnie (car params) arkusz)) (> (length wierz) 3))
               (progn (setq blok   (nth 0 params)
                            ramka  (nth 1 params)
                            kolor  (nth 2 params)
                            cols   (nth 3 params)
                            rows   (nth 4 params)
                            obrot  (nth 5 params)
                            LWyrys (nth 6 params))
                      (if (setq pp (_wskazArkusze wierz cols rows obrot LWyrys))
                        (progn (setq _vPorts (UtworzArkusze (nth 0 pp) (nth 1 pp) (nth 2 pp) (nth 3 pp) (nth 4 pp) LWyrys wierz))
                               (if blok
                                 (progn (if !command-s
                                          (command-s "_MSPACE")
                                          (command "_MSPACE"))
                                        (setq pt (getvar "VIEWCTR"))
                                        (if !command-s
                                          (command-s "_PSPACE")
                                          (command "_PSPACE"))
                                        (if (setq atrybuty (_dlgAtrArk blok (dwg_skala) "" pt (list 100 200)))
                                          (progn (foreach &&  _vPorts
                                                   (vla-put-ActiveLayout #acadDoc &&)
                                                   (_createBlockWhen
                                                     (vla-get-PaperSpace #acadDoc)
                                                     (vl-filename-base (car atrybuty))
                                                     (list 0 0 0)
                                                     0
                                                     (cadr atrybuty)))))))
                               (setvar #tilemode 1)
                               (if (and (nth 3 pp) (dialog->yes_no "Czy wymazać arkusze z obszaru modelu?"))
                                 (if !command-s
                                   (command-s "_ERASE" (nth 3 pp) "")
                                   (command "_ERASE" (nth 3 pp) ""))))))))
           (lovar)
           (_wyczyscLaout)))
  (princ))