lucky9 Posted July 1, 2018 Share Posted July 1, 2018 I need a lisp routine that can fill cell ranges when clicking text on drawing For example please have a look at the following drawing. If any text/levels is selected/clicked it should be extracted as following excel sheet thanks Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 1, 2018 Share Posted July 1, 2018 (edited) I need a lisp routine that can fill cell ranges when clicking text on drawing If any text/levels is selected/clicked it should be extracted as following excel sheet thanks hi try search similar thread at bottom left many examples out there it's been asked don't reinvent wheel. my $0.05 it's very simple task just ssget output *.csv faster, unless nested nentsel but slow if your pc *.csv file extension default opened by excel, simply (command "start" "c:\\temp\\test.csv" ) [color="green"]; i prefer notepad [/color] ([color="blue"]startapp[/color] "notepad" "c:\\temp\\test.csv") [color="green"]; faster[/color] 2. If the there are attributed blocks, don't need lisp command : ATTOUT or EATTEXT newer than v2007 - DATAEXTRACTION? spelling ok? Edited July 1, 2018 by hanhphuc Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 1, 2018 Author Share Posted July 1, 2018 hi try search similar thread at bottom left many examples out there it's been asked don't reinvent wheel. my $0.05 it's very simple task just ssget output *.csv faster, unless nested nentsel but slow if your pc *.csv file extension default opened by excel, simply (command "start" "c:\\temp\\test.csv" ) [color="green"]; i prefer notepad [/color] ([color="blue"]startapp[/color] "notepad" "c:\\temp\\test.csv") [color="green"]; faster[/color] 2. If the there are attributed blocks, don't need lisp command : ATTOUT or EATTEXT newer than v2007 - DATAEXTRACTION? spelling ok? The problem with EATTEXT is that its not exporting the data as my selection order For example if I selected J-108 ,J-02, J=105 then its shows correct order in preview screen but after exporting it to excel/csv its order changes J-105, J-102, J-108 .... Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 1, 2018 Author Share Posted July 1, 2018 Basically, I want to extract all the levels associated with Node in excel sheet. Like : J-102 106.2 J-103 108.5 J-108 105.2 thanks Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 1, 2018 Share Posted July 1, 2018 The problem with EATTEXT is that its not exporting the data as my selection order For example if I selected J-108 ,J-02, J=105 then its shows correct order in preview screen but after exporting it to excel/csv its order changes J-105, J-102, J-108 .... it can be done via EXCEL, check the tab or space delimited, move entire column to first column, select all columns, then sort by ascending or descending order. the problem sometimes to make sure numerical or alphabetical. e.g: string = J1, J11, J12... J100, J101.. etc it should be in numerical sequence. BTW, have a look lisp function vl-sort , acad_strlsort It's sunday, try it learn it first be happy coding Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 1, 2018 Share Posted July 1, 2018 Need a dwg to double check what it is your picking a block or text, if its two stacked text you can pick top and find other or pick both and as hanphuc has said sort the data. If the data is backwards that is easy to fix. Quote Link to comment Share on other sites More sharing options...
KESHAR Posted July 5, 2018 Share Posted July 5, 2018 not sure, but this might be able to be adapted to suit your needs: ;---------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Created by Karl E. Sharp ; Date: 6/27/2018 ; ; This Program was designed to copy mtext from a dwg ; to csv file for use in excel ; ; Code Modified by: Chris Wade - 06/28/2018 ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:MTO (/ elist en fn fname i ss mtxt Filter Ct Obj txt) ;Supporting Functions ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "[url="file://\\$1$2$3"]\\$1$2$3[/url]" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) ;;--------------------=={ Get TextString }==------------------;; ;; ;; ;; Returns the TexString associated with an object, ;; ;; retaining all special symbols. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; object - VLA-Object/ename for which to return TextString ;; ;;------------------------------------------------------------;; ;; Returns: TextString associated with object, else nil ;; ;;------------------------------------------------------------;; (defun LM:GetTextString ( object ) ;; © Lee Mac 2010 ( (lambda ( entity / _type elist ) (cond ( (wcmatch (setq _type (cdr (assoc 0 (setq elist (entget entity) ) ) ) ) "TEXT,*DIMENSION" ) (cdr (assoc 1 elist)) ) ( (eq "MULTILEADER" _type) (cdr (assoc 304 elist)) ) ( (wcmatch _type "ATTRIB,MTEXT") ( (lambda ( string ) (mapcar (function (lambda ( pair ) (if (member (car pair) '(1 3)) (setq string (strcat string (cdr pair))) ) ) ) elist ) string ) "" ) ) ) ) (if (eq 'VLA-OBJECT (type object)) (vlax-vla-object->ename object) object ) ) ) ;End of Supporting Functions (princ "\nSelect text to export:") (setq Filter '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))) (if (setq ss (ssget Filter)) (progn (setq fname (getfiled "Save Text File As:" "" "csv" 1)) (setq fn (open fname "w")) (if fn (progn (setq ct (sslength ss)); Code to process in reverse order came from: David Bethel - [url]https://www.theswamp.org/index.php?topic=3162.msg39448#msg39448[/url] (while (not (minusp (setq ct (1- ct)))) (setq Obj (vlax-ename->vla-object (ssname ss Ct))) (if Obj (progn (setq txt (LM:Unformat (LM:GetTextString Obj) T)) (if txt (write-line txt fn) ) ) ) ) (princ (strcat "\n* Text file " fname " \n has been created *")) (close fn) (startapp (strcat "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.exe" " " (chr 34) fname (chr 34)));Make sure you update the path to match where your installation of Excel is or write a routine to find the location of Excel. ) (princ "\n* Text file was not created.") ) ) (princ "\n* No text was found to export.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
lucky9 Posted July 8, 2018 Author Share Posted July 8, 2018 KESHAR Thanks Quote Link to comment Share on other sites More sharing options...
KESHAR Posted July 9, 2018 Share Posted July 9, 2018 You're quite welcome. I am glad I could help. Quote Link to comment Share on other sites More sharing options...
Maddy Posted June 7, 2019 Share Posted June 7, 2019 Hello @KESHAR, I tried using the lisp file you gave in Autocad 2015, but its not workin for me. on running the MTO command I am able to select all the MText that I want in the cvs file. On pressing enter after selecting the MTexts, a window opens up prompting for the location to save the cvs file. After I have saved the .cvs file, on opeing the said file( using excel) it is empty. The MText that I had selected for extraction are not in the file. Can you please help me out.? Quote Link to comment Share on other sites More sharing options...
vailin Posted April 23, 2020 Share Posted April 23, 2020 On 6/7/2019 at 6:45 PM, Maddy said: May be you use this lisp: c2e (chuan).lsp Quote Link to comment Share on other sites More sharing options...
ArbaDan75 Posted October 22, 2021 Share Posted October 22, 2021 (edited) the line of code must be corrected: LINE 57: (_replace "\\\\" "\032" (_replace "[url=file://\\$1$2$3]\\$1$2$3[/url]" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) Edited October 22, 2021 by ArbaDan75 Quote Link to comment Share on other sites More sharing options...
ArbaDan75 Posted October 22, 2021 Share Posted October 22, 2021 (edited) Unfortunately, this script does not cover the full range of formatting for Mtext. So the UNFORMAT code needs to be enriched with a lot of replays, the ones in this script are just the basic Mtexts formatting. However, the only method that fully covers all possible Mtexts formatting is to bring them geometrically in a shape so that you can create a table with that data (find scripts that turn old table into new table), then export to the final table. Indeed, the function that executes the export to csv (the one implemented in autocad, and whose code I can't see, so that I can retrieve the data for the MTEXTS conversion) does the MTEXTs conversion correctly. Example: format from MTEXT : | KM 498+794 (FIR I)\PStalp 357 | {\fTrebuchet MS|b0|i0|c0|p34;\H0.84615x;\C250;498} | \pxqc;{\fTrebuchet MS|b0|i0|c0|p34;\C250;8} ---> Finally, after applying this method: Edited October 22, 2021 by ArbaDan75 Quote Link to comment Share on other sites More sharing options...
ArbaDan75 Posted October 25, 2021 Share Posted October 25, 2021 (edited) I come back with a small update to the last method explained above: the table can be created with DATAEXTRACTION (that function has option to select objects, not for all object from drawing), but it is very important that at the end of the function you insert the table in the drawing, not save in CSV (because there you will see MTEXT as well, formatted) , but if you insert it in the drawing and then right-click on the table and export, it will modify MTEXT without formatting, ie only the content that interests us in excel. Eventually, if ordering is needed (X or Y), DATAEXTRACTION has the option to create the table with GEOMETRYCALDATA; this means that we can use coordinates to sort the texts in excel. I hope this information helps someone. Edited October 25, 2021 by ArbaDan75 Quote Link to comment Share on other sites More sharing options...
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.
Note: Your post will require moderator approval before it will be visible.