Marek-M Posted March 11, 2021 Report Posted March 11, 2021 (edited) Cześć, Po imporcie tabeli z Excela posiada ona formatowanie tekstu, które chciałbym usunąć. Z tego co zauważyłem, to jest ono zapisywane w formacie {\fCalibri|b0|i0|c1|p0;Jakiś tekst} Chciałbym móc oczyszczać tabele z formatowania aby tekst w tabeli po oczyszczeniu wyglądał tak: Jakiś tekst Znalazłem skrypt Lee Maca ale nie rozwiązuje on moich problemów. Może to być kwestia jakiegoś regexa do skonfigurowania, ale na tym się nie znam za bardzo. Może ktoś da radę prześledzić kod i zrobić jakąś poprawkę, żeby skrypt oczyszczał tekst w tabelach? Poniżej kod (również w stripFormT-usun_formatowanie_tekstu_w_tabeli.lsp), który znalazłem na forum https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/remove-character-formatting-from-tables/m-p/7988214#M368495 (defun c:stripFormT ( / LM:UnFormat table col row) (defun LM:UnFormat ( str mtx / _Replace regex ) (vl-load-com) ;; © Lee Mac 2010 (defun _Replace ( new old str ) (vlax-put-property regex 'pattern old) (vlax-invoke regex 'replace str new) ) (setq regex (vlax-get-or-create-object "VBScript.RegExp")) (mapcar (function (lambda ( x ) (vlax-put-property regex (car x) (cdr x))) ) (list (cons 'global actrue) (cons 'ignorecase acfalse) (cons 'multiline actrue)) ) (mapcar (function (lambda ( x ) (setq str (_Replace (car x) (cdr x) str))) ) '( ("Ð" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) ) (setq str (if mtx (_Replace "\\\\" "Ð" (_Replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_Replace "\\" "Ð" str) ) ) (vlax-release-object regex) str ) (if (setq table (ssget "_:S:E:L" '((0 . "ACAD_TABLE" )))) (progn (vla-put-regeneratetablesuppressed (setq table (vlax-ename->vla-object (ssname table 0))) :vlax-true) (setq row (1- (vlax-get table 'Rows))) (setq col (vlax-get table 'Columns)) (repeat row ((lambda (n) (repeat n (setq n (1- n)) (if (/= (setq f (vlax-invoke table 'GetText row n)) "") (progn (setq unformatted (LM:UnFormat f nil)) (vlax-invoke table 'SetText row n unformatted))) ) ) col ) (setq row (1- row)) ) (vla-put-regeneratetablesuppressed table :vlax-false) ) ) (princ) ) Edited March 11, 2021 by Marek-M Quote
Marek-M Posted March 11, 2021 Author Report Posted March 11, 2021 Dosyłam jeszcze pliki źródłowe Excela i DWG z zaimportowaną tabelką, może komuś będzie pomocne. Program, na którym działam: ZWCAD 2019, vernum = "2019.03.15(43299)_x64" stripFormT-usun_formatowanie_tekstu_w_tabeli.lsp Table_remove_formating_CAD.dwg Data_source_Excel.xlsx Quote
dmatusz3 Posted March 11, 2021 Report Posted March 11, 2021 Dziękuję za wiadomość. Sprawdzimy co da się zrobić. Quote
Marek-M Posted March 11, 2021 Author Report Posted March 11, 2021 Dzięki, Zauważyłem, że chyba źle to miałem wpisane w pierwszym poście - tekst w tabeli posiada klamrę zamykającą tylko jeśli w środku pojawia się jakieś specjalne formatowanie np. pogrubienie i pokolorowanie - przykład poniżej: (1 . "{\\fCalibri|b0|i0|c1|p0;Simple text 1\n\\fCalibri|b1|i0|c1|p0;\\C3;\nSimple text 2\\fCalibri|b0|i0|c1|p0;\\C0;\n\nSimple text 3}") Jeśli tekst nie zawiera formatowania w środku, to nie ma klamry zamykającej: (1 . "{\\fCalibri|b0|i0;Simple text 1\n\nSimple text 2\n\nSimple text 3") Nowy plik DWG ze zmienionym formatowaniem jak na obrazkach powyżej: Table_remove_formating_CAD.dwg Quote
kruszynski Posted March 11, 2021 Report Posted March 11, 2021 W załączniku takie na szybko uklecone w C#. Wczytać można poleceniem netload Nowe polecenie nazywa się: TableRemoveFormatting TableFormatting.zip Quote
Marek-M Posted March 11, 2021 Author Report Posted March 11, 2021 Dzięki! Nie wiem jak to robi ale robi to bardzo dobrze Przydałoby się tej aplikacji wybór kilku tabel do zaznaczenia za jednym razem. Teraz trzeba każdą tabelkę przeklikać a przydałoby się je załatwić parametrem np. "_all" Quote
Marek-M Posted March 11, 2021 Author Report Posted March 11, 2021 Dobra, na tym forum AutoCADa ktoś mi pomógł i poprawił kod Lee Maca i teraz robi dokładnie to co trzeba. Zostawiam tutaj kod dla potomnych (również jako plik) Dzięki za pomoc! Plik zawiera dodatkowy parametr, który pozwala wybrać, czy znaczniki nowych linii mają być usuwane w komórkach tabeli (domyślna opcja, to 'zachowaj nowe linie'). (defun c:stripFormT ( / LM:UnFormat table col row mode) (defun LM:UnFormat ( str mtx / _Replace regex ) (vl-load-com) ;; © Lee Mac 2010 (defun _Replace ( new old str ) (vlax-put-property regex 'pattern old) (vlax-invoke regex 'replace str new) ) (setq regex (vlax-get-or-create-object "VBScript.RegExp")) (mapcar (function (lambda ( x ) (vlax-put-property regex (car x) (cdr x))) ) (list (cons 'global actrue) (cons 'ignorecase acfalse) (cons 'multiline actrue)) ) (mapcar (function (lambda ( x ) (setq str (_Replace (car x) (cdr x) str))) ) '( ("Đ" . "\\\\\\\\") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) ) (setq str (if mtx (_Replace "\\" "Đ" str) (last (mapcar '(lambda (fr) (_Replace (Car fr)(cdr fr) str)) '(("\\$1$2$3" . "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})") ("\\\\" . "Đ")("\\$1$2$3" . "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})")(" " . "\\\\P|\\n|\\t"))) ) ) ) (vlax-release-object regex) str ) (if (setq table (ssget "_:S:E:L" '((0 . "ACAD_TABLE" )))) (progn (vla-put-regeneratetablesuppressed (setq table (vlax-ename->vla-object (ssname table 0))) :vlax-true) (setq row (vlax-get table 'Rows)) (setq col (vlax-get table 'Columns)) (initget "Y N") (setq mode (getkword "\nKeep new line format [Yes/No]: ")) (setq mode (or (null mode)(eq "Y" mode))) (repeat row (setq row (1- row)) ((lambda (n) (repeat n (setq n (1- n)) (if (/= (setq f (vlax-invoke table 'GetText row n)) "") (progn (setq unformatted (LM:UnFormat f mode)) (vlax-invoke table 'SetText row n unformatted))) ) ) col ) ) (vla-put-regeneratetablesuppressed table :vlax-false) ) ) (princ) ) stripFormT-usun_formatowanie_tekstu_w_tabeli.lsp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.