(изменено: Cheb09, 2 июня 2012г. 04:31:29)

Тема: Lisp. Фильтр текста (числа) по условию.

Здравствуйте.
Исходные данные:
1) Autocad 64 bit.
2) Text/Mtext в виде цифр, координата z может отличаться (например,  1.17 125.00 0.01 2.01, смотрим пример).
3) Число, задаваемое пользователем (например  25.6).
4) Арифметическое условие  = (равно), <> (меньше больше), <= (меньше равно), >= (больше равно).
5) Текст, содержащий буквы (abc123, %%с12) обрабатываться не должен.
Варианты задач:
Задача 1: Число, не удовлетворяющее условиям, удаляется.
Задача 2: Число удовлетворяющее условиям, заменяется текстом, введенным пользователем (например %%с12).
Спасибо заранее.
Здесь пример.dwg
Скачать Пример.dwg с WebFile.RU

(изменено: Cheb09, 26 августа 2011г. 20:10:37)

Re: Lisp. Фильтр текста (числа) по условию.

Вот нашел как вариант аналог attin/attout, но для текстов от Кулик Алексей aka kpblc, правим в excel и полученные значения импортируем обратно. На AutoCAD 2012 64, не работает  :cry: , на выходе пустой файл.

(vl-load-com)

(defun c:textout (/ *error* selset file lst handle _kpblc-string-clear-format)

  (defun *error* (msg)
    (vl-catch-all-apply (function (lambda () (close handle))))
    (princ msg)
    (princ)
    ) ;_ end of defun

  (defun _kpblc-string-clear-format (mtext / text str pos)
    (setq text "")
    (while (/= mtext "")
      (cond
        ((= (strcase (substr mtext 1 3)) "%<\\")
         (setq text  (strcat text (substr mtext 1 (setq pos (vl-string-search ">%" mtext))))
               mtext (substr mtext pos)
               ) ;_ end of setq
         )
        ((wcmatch (strcase (setq str (substr mtext 1 2))) "\\[\\{}]")
         (setq mtext (substr mtext 3)
               text  (strcat text str)
               ) ;_ end of setq
         )
        ((wcmatch (substr mtext 1 1) "[{}]")
         (setq mtext (substr mtext 2))
         )
        ((wcmatch (strcase (setq str (substr mtext 1 2))) "\\[LO`~]")
         (setq mtext (substr mtext 3))
         )
        ((wcmatch (strcase (substr mtext 1 2)) "\\[ACFHQTW]")
         (setq mtext (substr mtext (+ 2 (vl-string-search ";" mtext))))
         )
        ((wcmatch (strcase (substr mtext 1 4)) "\\PQ[CRJD],\\PXQ")
;;;Add by KPblC
         (setq mtext (substr mtext (+ 2 (vl-string-search ";" mtext))))
         )
        ((and (wcmatch (strcase (substr mtext 1 2)) "\\P")
              (/= text "")
              ) ;_ end of and
         (if (or (= " " (substr text (strlen text)))
                 (= " " (substr mtext 3 1))
                 ) ;_ end of or
           (setq mtext (substr mtext 3))
           (setq mtext (substr mtext 3)
                 text  (strcat text " ")
                 ) ;_ end of setq
           ) ;_ end of if
         )
        ((wcmatch (strcase (substr mtext 1 2)) "\\P")
         (setq mtext (substr mtext 3))
         )
        ((wcmatch (strcase (substr mtext 1 2)) "\\S")
         (setq str   (substr mtext 3 (- (vl-string-search ";" mtext) 2))
               text  (strcat text (vl-string-translate "#^\\" "/^\\" str))
               mtext (substr mtext (+ 4 (strlen str)))
               ) ;_ end of setq
         )
        (t
         (setq text  (strcat text (substr mtext 1 1))
               mtext (substr mtext 2)
               ) ;_ end of setq
         )
        ) ;_ end of cond
      ) ;_ end of while
    text
    ) ;_ end of defun

  (if (and (= (type (setq selset (vl-catch-all-apply
                                   (function
                                     (lambda ()
                                       (ssget '((0 . "*TEXT")))
                                       ) ;_ end of lambda
                                     ) ;_ end of function
                                   ) ;_ end of vl-catch-all-apply
                          ) ;_ end of setq
                    ) ;_ end of type
              'pickset
              ) ;_ end of =
           (/= (setq file (getfiled "Имя файла экспорта" (vl-filename-base (getvar "dwgname")) "csv" 1)) "")
           ) ;_ end of and
    (progn
      (setq handle (open file "w"))
      (foreach item (vl-sort
                      (mapcar
                        (function
                          (lambda (x)
                            (setq x (vlax-ename->vla-object x))
                            (cons (vla-get-handle x)
                                  (_kpblc-string-clear-format (vla-get-textstring x))
                                  ) ;_ end of list
                            ) ;_ end of lambda
                          ) ;_ end of function
                        ((lambda (/ tab item)
                           (repeat (setq tab  nil
                                         item (sslength selset)
                                         ) ;_ end setq
                             (setq tab (cons (ssname selset (setq item (1- item))) tab))
                             ) ;_ end of repeat
                           ) ;_ end of lambda
                         )
                        ) ;_ end of mapcar
                      (function
                        (lambda (a b)
                          (< (car a) (car b))
                          ) ;_ end of lambda
                        ) ;_ end of function
                      ) ;_ end of vl-sort
        (write-line (strcat "\"" (car item) "\";\"" (cdr item) "\"") handle)
        ) ;_ end of foreach
      (close handle)
      (princ (strcat "\nДанные сохранены в файле " file))
      ) ;_ end of progn
    ) ;_ end of if
  (princ)
  ) ;_ end of defun

(defun c:textin (/ *error* adoc file layer_status handle str file_lst fun_layer-restore obj)

  (defun *error* (msg)
    (fun_layer-restore)
    (vla-endundomark adoc)
    (princ msg)
    (princ)
    ) ;_ end of defun

  (defun fun_layer-restore ()
    (foreach item layer_status
      (foreach prop (cdr item)
        (vl-catch-all-apply
          (function
            (lambda ()
              (vlax-put-property (car item) (car prop) (cdr prop))
              ) ;_ end of lambda
            ) ;_ end of function
          ) ;_ end of vl-catch-all-apply
        ) ;_ end of foreach
      ) ;_ end of foreach
    ) ;_ end of defun

  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (if (/= (setq file (getfiled "Имя файла экспорта" (vl-filename-base (getvar "dwgname")) "csv" 4)) "")
    (progn
      (setq handle (open file "r"))
      (while (setq str (read-line handle))
        (setq file_lst (cons
                         ((lambda (/ pos)
                            (if (setq pos (vl-string-search ";" str))
                              (cons (substr str 1 pos)
                                    (substr str (+ 2 pos))
                                    ) ;_ end of cons
                              ) ;_ end of if
                            ) ;_ end of lambda
                          )
                         file_lst
                         ) ;_ end of cons
              ) ;_ end of setq
        ) ;_ end of while
      (close handle)
      (vlax-for item (vla-get-layers adoc)
        (setq layer_status (cons (list item
                                       (mapcar
                                         (function
                                           (lambda (x / res)
                                             (setq res (cons x (vlax-get-property item x)))
                                             (vl-catch-all-apply (function
                                                                   (lambda ()
                                                                     (vlax-put-property item :vlax-false)
                                                                     ) ;_ end of lambda
                                                                   ) ;_ end of function
                                                                 ) ;_ end of vl-catch-all-apply
                                             res
                                             ) ;_ end of lambda
                                           ) ;_ end of function
                                         '("lock" "freeze")
                                         ) ;_ end of mapcar
                                       ) ;_ end of list
                                 layer_status
                                 ) ;_ end of cons
              ) ;_ end of setq
        ) ;_ end of vlax-for
      (foreach item file_lst
        (if (and (setq obj (handent (car item)))
                 (setq obj (vlax-ename->vla-object obj))
                 (not (vlax-erased-p obj))
                 ) ;_ end of and
          (vl-catch-all-apply
            (function
              (lambda ()
                (vla-put-textstring obj (cdr item))
                ) ;_ end of lambda
              ) ;_ end of function
            ) ;_ end of vl-catch-all-apply
          ) ;_ end of if
        ) ;_ end of foreach
      ) ;_ end of progn
    ) ;_ end of if
  (fun_layer-restore)
  (vla-endundomark adoc)
  (princ)
  ) ;_ end of defun

Как сделать без экспорта и импорта текста?

(изменено: gomer, 1 сентября 2011г. 16:04:34)

Re: Lisp. Фильтр текста (числа) по условию.

(if (/= (setq file (getfiled "Имя файла экспорта" (vl-filename-base (getvar "dwgname")) "csv" 4)) "")
    (progn
и далее... убери...

Re: Lisp. Фильтр текста (числа) по условию.

Дополнительно : http://autolisp.ru/2011/07/07/x32x64objectid/

Re: Lisp. Фильтр текста (числа) по условию.

Спасибо, ушел изучать лисп  :D .

Re: Lisp. Фильтр текста (числа) по условию.

Изучение лиспа пока не дало никаких результатов, поэтому пока изменил первый пост в виде задачки, может кому интересно станет.
Здесь пример.dwg Скачать Пример.dwg с WebFile.RU

Re: Lisp. Фильтр текста (числа) по условию.

Писал немного похожее, выбор чисел в указанном диапазоне.
http://forum.dwg.ru/showthread.php?p=660353#post660353

(изменено: Cheb09, 14 июня 2012г. 16:27:00)

Re: Lisp. Фильтр текста (числа) по условию.

Disney спасибо, твой вариант самый близкий к конечному варианту.
Теперь осталось из условия:

From >= Содержимое >= To
одно можно не вводить

с запросом:

Команда: Выберите объекты:
Команда: Введите From или Пробел-нет:
Команда: Введите To или Пробел-нет:
Команда: Введите Заменяющий текст или Пробел-нет:

получить конечный вариант :o

(изменено: Cheb09, 30 мая 2013г. 16:34:56)

Re: Lisp. Фильтр текста (числа) по условию.

Как не странно «аналог attin/attout, но для текстов» в AutoCAD 2014 x64 прекрасно работает?!
http://forum.dwg.ru/showpost.php?p=6427 … stcount=25