Aller au contenu

extraire des données


Messages recommandés

Posté(e)

bonjour a tous,

 

je travaille sur Autocad 2008 et je doit extraire toutes les données texte ( attribut, texte simple,...) sous un fichier excel.

 

Quelqu'un aurait-il un truc pour que je puisse continuer ??

 

un grand merci

Posté(e)

Bonjour,

 

Un travail excellent réalisé par JefferyPSanders du nom de WORDS

 

Le lisp :

 

 ;;;--- WORDS.lsp   -  Count the words in a drawing.
;;;
;;;
;;;--- Copyright 2006 by JefferyPSanders.com
;;;    All rights reserved.
;;;
;;;
;;;--- Revision 2/14/07  -   Added the ability to save the word list to a file.
;;;
;;;
;;;

(defun C:WORDS()



 ;;;--- Function to get the attribute data

 (defun getAttData(/ eset blkCntr en enlist blkType blkName entName val group66)

   ;;;--- If that type of entity exist in drawing
   (if (setq eset(ssget "X" (list (cons 0 "INSERT"))))
     (progn

       ;;;--- Set up some counters
       (setq blkCntr 0 cntr 0 pcntr 0)
                    
       ;;;--- Loop through each entity
       (while (                                
         ;;;--- Get the entity's name
         (setq en(ssname eset blkCntr))
                        
         ;;;--- Get the DXF group codes of the entity
         (setq enlist(entget en))

         ;;;--- Get the name of the block
         (setq blkName(cdr(assoc 2 enlist)))
                     
         ;;;--- Check to see if the block's attribute flag is set
         (if(cdr(assoc 66 enlist))
           (progn
                                  
             ;;;--- Get the entity name
             (setq en(entnext en))
                  
             ;;;--- Get the entity dxf group codes
             (setq enlist(entget en))
                   
             ;;;--- Get the type of block
             (setq blkType (cdr(assoc 0 enlist)))
                   
             ;;;--- If group 66 then there are attributes nested inside this block
             (setq group66(cdr(assoc 66 enlist)))
                  
             ;;;--- Loop while the type is an attribute or a nested attribute exist
             (while(or (= blkType "ATTRIB")(= group66 1))
                   
               ;;;--- Get the block type 
               (setq blkType (cdr(assoc 0 enlist)))
                         
               ;;;--- Get the block name         
               (setq entName (cdr(assoc 2 enlist)))
                      
               ;;;--- Check to see if this is an attribute or a block
               (if(= blkType "ATTRIB")
                 (progn
                       
                   ;;;--- Get the value of the attribute
                   (setq val(cdr(assoc 1 enlist))) 
                       
                   ;;;--- Convert to words
                   (foreach a (convert2Words val)
                     (while(= (substr a 1 1) " ")(setq a(substr a 2)))
                     (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))
                     (setq wordList(append wordList (list a)))
                   )
                            
                   ;;;--- Increment the counter
                   (setq cntr (+ cntr 1))

                   ;;;--- Inform the user every ten entities
                   (if(> pcntr 9)
                     (progn

                       ;;;--- Inform the user of progress
                       (princ "\n Attribute entities found - ")(princ cntr)(terpri)

                       ;;;--- Reset the progress counter
                       (setq pcntr 0)
                     )
                   )

                      
                   ;;;--- Get the next sub-entity or nested entity as you will
                   (setq en(entnext en))
                      
                   ;;;--- Get the dxf group codes of the next sub-entity
                   (setq enlist(entget en))
                     
                   ;;;--- Get the block type of the next sub-entity
                   (setq blkType (cdr(assoc 0 enlist)))
                       
                   ;;;--- See if the dxf group code 66 exist.  if so, there are more nested attributes
                   (setq group66(cdr(assoc 66 enlist)))
                 ) 
               )
             )
           )
         )
         (setq blkCntr (+ blkCntr 1))
       )
     )                    
   )
 )




 ;;;--- Function to get the text or mtext string from a sub-entity's dxf group code list

 (defun getBlkString(enlista)

   ;;;--- Get the sub-entity type
   (setq entType(cdr(assoc 0 enlista)))

   ;;;--- If it is a text entity...
   (if(= entType "TEXT")
     (progn
                      
       ;;;--- Get the value of the attribute
       (setq val(cdr(assoc 1 enlista))) 
                       
       ;;;--- Convert to words
       (foreach a (convert2Words val)

         ;;;--- Remove spaces prefixed
         (while(= (substr a 1 1) " ")(setq a(substr a 2)))

         ;;;--- Remove spaces suffixed
         (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))

         ;;;--- Add the word to the list
         (setq wordList(append wordList (list a)))
       )
     )
   )
 
   ;;;--- If the sub-entity type is MText
   (if(= entType "MTEXT")
     (progn

       ;;;--- Get the value of the mtext entity
       (setq val (getMtxt enlista))

       ;;;--- Convert to words
       (foreach a (convert2Words val)

         ;;;--- Remove spaces prefixed 
         (while(= (substr a 1 1) " ")(setq a(substr a 2)))

         ;;;--- Remove spaces suffixed
         (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))

         ;;;--- Add the word to the list
         (setq wordList(append wordList (list a)))
       )
     )
   )
 )

 ;;;--- Function to get the block entity data

 (defun getBlkData()

   ;;;--- If that type of entity exist in drawing
   (if (setq eset(ssget "X" (list (cons 0 "INSERT"))))
     (progn

       ;;;--- Set up a counter
       (setq blkCntr 0 cntr 0 pcntr 0)
                    
       ;;;--- Loop through each block entity
       (while (                                
         ;;;--- Get the block entity's name
         (setq en(ssname eset blkCntr))
                        
         ;;;--- Get the DXF group codes of the block entity
         (setq enlist(entget en))

         ;;;--- Get the name of the block
         (setq blkName(cdr(assoc 2 enlist)))
  
         ;;;--- Get the block table
         (if(setq tbl(tblsearch "BLOCK" blkName))
           (progn
       
             ;;;--- Get the block table entity name
             (setq tblen(cdr(assoc -2 tbl)))

             ;;;--- Cycle through the sub-entites
             (while(setq tblen(entnext tblen))
              
               ;;;--- Get the dxf group codes   
               (setq enlist(entget tblen))         

               ;;;--- Get the string
               (getBlkString enlist)
             )
           )
         )

         ;;;--- Increment the counter
         (setq blkCntr (+ blkCntr 1))

         ;;;--- Inform the user every ten entities
         (if(> pcntr 9)
           (progn

             ;;;--- Inform the user of progress
             (princ "\n BLOCK entities found - ")(princ cntr)(terpri)

             ;;;--- Reset the progress counter
             (setq pcntr 0)
           )
         )


       )
     )
   )
 )







 ;;;--- Function to convert a sentence into a list of words

 (defun convert2Words(a / cnt tmpwrd words)

   ;;;--- Remove the special characters
   (setq a(removeChars a))

   ;;;--- Setup some variables
   (setq cnt 1 tmpWrd "" words(list))

   ;;;--- Cycle through each character in the string
   (while(
     ;;;--- If the character is not a space...
     (if(/= (setq c(substr a cnt 1)) " ")

       ;;;--- Start building a word
       (setq tmpWrd(strcat tmpWrd c))

       ;;;--- Else, it is a space, so add the word to the words list
       (if(and(/= tmpWrd "")(/= tmpWrd " "))(setq words(append words (list tmpWrd)) tmpWrd ""))
     )

     ;;;--- Get the next character
     (setq cnt(+ cnt 1))
   )

   ;;;--- See if there was a word on the end without a trailing space and add it to the words list
   (if(and(/= tmpWrd "")(/= tmpWrd " "))(setq words(append words(list tmpWrd))))

   ;;;--- Return the list of words created from a string
   words
 )  







 ;;;--- Function to remove a list of characters from a string

 (defun removeChars(myString)

   ;;;--- Set up a list of characters to be removed
   (setq remList(list "\\P" "\\O" "\\o" "\\L" "\\l" "\\~" "\\{" "\\}" ))

   ;;;--- Cycle through each special character to be removed
   (foreach a remList

     ;;;--- If this special character is in the string
     (while(wcmatch myString (strcat "*" a "*"))

       ;;;--- Set up a counter
       (setq cnt 1)

       ;;;--- Cycle through each pair of characters in the string [ remove chars have a string length of 2 ]
       (while(
         ;;;--- Get the first two characters
         (setq ch(substr myString cnt 2))

         ;;;--- If the string has one of these special characters
         (if(= ch a)

           ;;;--- Rebuild the string without the special character
           (setq myString
             (strcat

                ;;;--- Get the part of the string before the special character
                (substr myString 1 (- cnt 1))

                ;;;--- Insert a space if it was the end of a paragraph character
                (if(= ch "\\P") " " "")

                ;;;--- Get the part of the string after the special character 
                (substr myString (+ cnt 2))
             )
           )
         )

         ;;;--- Increment the counter to get the next set of characters
         (setq cnt(+ cnt 1))
       )
     )
   )

   ;;;---  Remove the other mtext control strings
   (setq remList(list "*\\C*;*" "*\\F*;*" "*\\H*;*" "*\\S*;*" "*\\T*;*" "*\\Q*;*" "*\\W*;*" "*\\A*;*"
                    "*\\c*;*" "*\\f*;*" "*\\h*;*" "*\\s*;*" "*\\t*;*" "*\\q*;*" "*\\w*;*" "*\\a*;*"
   )            )

   ;;;--- Cycle through the remove list
   (foreach a remList

     ;;;--- While the string contains a special control string
     (while(wcmatch myString a)

       ;;;--- Set up a counter
       (setq cnt 1)

       ;;;--- Cycle through each character in the string
       (while(
         ;;;--- Get the first two characters from the string
         (setq ch(substr myString cnt 2))

         ;;;--- If these two characters match part of the control string from the remove list
         (if(= ch (substr a 2 2))
           (progn

             ;;;--- Set a new counter to find the end of the special control string 
             (setq cnt2 cnt)

             ;;;--- Keep cycling until we find the end marked by a semi-colon or end of string
             (while(and (/= ch ";")(                (setq cnt2(+ cnt2 1))
               (setq ch(substr myString cnt2 1)) 
             )

             ;;;--- If we do find the end of the special control string  [ ; ]
             (if(= ch ";")

               ;;;--- Rebuild the string without the special control string
               (setq myString
                 (strcat

                   ;;;--- Get the part before the special controls string
                   (substr myString 1 (- cnt 1))

                   ;;;--- Get the part after the special control string
                   (substr myString (+ cnt2 1))
                 )
               )
             )
           )
         )

         ;;;--- Increment the counter to get the next set of characters
         (setq cnt(+ cnt 1))
       )
     )
   )    

   ;;;--- Return the string
   myString
 )





 ;;;--- Function to get the complete string from an MText entity   

 (defun GetMtxt(enl / extx)

   ;;;--- Set the initial text variable to nothing
   (setq extx "")

   ;;;--- If group 3 codes exist...
   (if(assoc 3 enl)

     ;;;--- String them all together to make one string
     (foreach a enl
       (if(= 3 (car a))
         (setq extx(strcat extx(cdr a)))
       )
     )
   )

   ;;;--- Add the group code 1 string to the end      
   (setq extx(strcat extx (cdr(assoc 1 enl))))

   extx
 )



 ;;;--- Function to get the words from the WORDS.txt file into a list

 (defun getWordsFromFile()

   ;;;--- Can the file be located...
   (if(setq wordsFile(findfile "WORDS.TXT"))
     (progn

       ;;;--- If it exist, open the file to read
       (if(setq fil(open wordsFile "r"))
         (progn

           ;;;--- Set up a list to hold the "filter" words
           (setq useWordsList(list))

           ;;;--- Read each line from the file
           (while(setq a(read-line fil))

             ;;;--- Add the word to the list
             (setq useWordsList(append useWordsList (list a)))
           )

           ;;;--- Close the file after reading all lines
           (close fil)
         )

         ;;;--- Else the text file could not be opened so set it to nil
         (setq useWordsList nil)

       )
     )
     (progn

       ;;;--- Else the text file was not found so set it to nil
       (setq useWordsList nil)

       (alert "The WORDS.TXT file could not be located!")
     )
   )
 )





 ;;;--- Function to update the data

 (defun updateData()

   ;;;--- See if the word text file should be used as a filter
   (if(= "1" (get_tile "only"))

       ;;;--- Get the words from the words.txt file
       (getWordsFromFile)

       ;;;--- Else, empty the list
       (setq useWordsList nil)

   )

   ;;;--- Setup an empty list to hold all of the words
   (setq wordList(list))

   ;;;--- Inform the user of progress
   (princ "\n Saving Defaults...")

   ;;;--- Save the settings from the dialog box
   (if(= (get_tile "gettxt") "1")(setq getTxt T)(setq getTxt nil))
   (if(= (get_tile "getatt") "1")(setq getAtt T)(setq getAtt nil))
   (if(= (get_tile "getmtx") "1")(setq getMtx T)(setq getMtx nil))
   (if(= (get_tile "getblk") "1")(setq getBlk T)(setq getBlk nil))
   (if(= (get_tile "getdim") "1")(setq getDim T)(setq getDim nil))

   ;;;--- Do some stuff to save the current dialog box settings
   (setq nextDfalt 0)
   (if getTxt (setq nextDfalt(+ nextDfalt 1 )))
   (if getAtt (setq nextDfalt(+ nextDfalt 2 )))
   (if getMtx (setq nextDfalt(+ nextDfalt 4 )))
   (if getBlk (setq nextDfalt(+ nextDfalt 8 )))
   (if getDim (setq nextDfalt(+ nextDfalt 16))) 

   ;;;--- Save the default settings for next use
   (setvar "useri4" nextDfalt)

   ;;;--- If text entities are required
   (if getTxt

     ;;;--- Get a selection set of all text entities
     (if(setq eset(ssget "X" (list(cons 0 "TEXT"))))
       (progn

         ;;;--- Set up some counters
         (setq cntr 0 pcntr 0)

         ;;;--- Inform the user of progress
         (princ "\n Checking for text entities...")

         ;;;--- Cycle through each text entity in the selection set
         (while(
           ;;;--- Get the entity name of the nth item
           (setq en(ssname eset cntr))

           ;;;--- Get the DXF group codes from the text entity
           (setq enlist(entget en))

           ;;;--- Get the value of the text entity
           (setq val(cdr(assoc 1 enlist)))

           ;;;--- Get the words from the value string and cycle through them
           (foreach a (convert2Words val)

             ;;;--- Remove all spaces prefixed
             (while(= (substr a 1 1) " ")(setq a(substr a 2)))

             ;;;--- Remove all spaces suffixed
             (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))

             ;;;--- Add the word to the list
             (setq wordList(append wordList (list a)))
           )

           ;;;--- Increment the counter to get the next text entity
           (setq cntr(+ cntr 1))

           ;;;--- Increment the progress counter
           (setq pcntr(+ pcntr 1))

           ;;;--- Inform the user every fifty entities
           (if(> pcntr 49)
             (progn

               ;;;--- Inform the user of progress
               (princ "\n Text entities found - ")(princ cntr)(terpri)

               ;;;--- Reset the progress counter
               (setq pcntr 0)
             )
           )
         )
       )
     )
   )

   ;;;--- If attribute entities are required
   (if getAtt

     ;;;--- Run the attribute extraction function
     (getAttData)
   )

   ;;;--- If mtext entities are required
   (if getMtx

     ;;;--- Get a selection set of all MTEXT entities
     (if(setq eset(ssget "X" (list(cons 0 "MTEXT"))))
       (progn

         ;;;--- Set up a counter
         (setq cntr 0 pcntr 0)

         ;;;--- Inform the user of progress
         (princ "\n Checking for MText entities...")

         ;;;--- Cycle through each of the mtext entities in the selection set
         (while(
           ;;;--- Get the entity name of the mtext object
           (setq en(ssname eset cntr))

           ;;;--- Get the DXF group codes from the mtext entity
           (setq enlist(entget en))

           ;;;--- Get the value of the mtext by using the GETMTXT extraction function
           (setq val (getMtxt enlist))

           ;;;--- Convert the mtext value into words and cycle through them
           (foreach a (convert2Words val)

             ;;;--- Remove all spaces prefixed
             (while(= (substr a 1 1) " ")(setq a(substr a 2)))

             ;;;--- Remove all spaces suffixed
             (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))

             ;;;--- Add the word to the list
             (setq wordList(append wordList (list a)))
           )

           ;;;--- Increment the counter to get the next mtext entity
           (setq cntr(+ cntr 1))

           ;;;--- Increment the progress counter
           (setq pcntr(+ pcntr 1))

           ;;;--- Inform the user every fifty entities
           (if(> pcntr 49)
             (progn

               ;;;--- Inform the user of progress
               (princ "\n MText entities found - ")(princ cntr)(terpri)

               ;;;--- Reset the progress counter
               (setq pcntr 0)
             )
           )
         )
       )
     )
   )


   ;;;--- If text entities inside a block are required
   (if getBlk

     ;;;--- Run the block extraction function
     (getBlkData)
   )

   ;;;--- If dimension entities are required
   (if getDim

     ;;;--- Get a selection set of all dimension entities
     (if(setq eset(ssget "X" (list(cons 0 "DIMENSION"))))
       (progn

         ;;;--- Set up a counter
         (setq cntr 0 pcntr 0)

         ;;;--- Cycle through each of the dimensions in the selection set
         (while(
           ;;;--- Get the entity name
           (setq en(ssname eset cntr))

           ;;;--- Get the DXF group codes
           (setq enlist(entget en))

           ;;;--- If a dimension value was typed in... [ no group code 1 if not ]
           (if(assoc 1 enlist)
             (progn

               ;;;--- Get the value of the dimesion text               
               (setq val(cdr(assoc 1 enlist)))

               ;;;--- Convert the dimension string into words and cycle through them
               (foreach a (convert2Words val)

                 ;;;--- Remove spaces prefixed
                 (while(= (substr a 1 1) " ")(setq a(substr a 2)))

                 ;;;--- Remove spaces suffixed
                 (while(= (substr a (strlen a) 1) " ")(setq a(substr a 1 (- (strlen a) 1))))

                 ;;;--- Add the dimension word to the list
                 (setq wordList(append wordList (list a)))
               )
             )
           )

           ;;;--- Increment the counter to get the next entity
           (setq cntr(+ cntr 1))

           ;;;--- Inform the user every ten entities
           (if(> pcntr 9)
             (progn

               ;;;--- Inform the user of progress
               (princ "\n Dimension entities found - ")(princ cntr)(terpri)

               ;;;--- Reset the progress counter
               (setq pcntr 0)
             )
           )
         )
       )
     )
   )
 
   ;;;--- Inform the user of progress
   (princ "\n Sorting words...")

   
   ;;;--- Sort the words
   (if(wcmatch "14" (ver)) (setq wordList(sort wordList)))
   (if(wcmatch "20" (ver)) (setq wordList(vl-sort wordList '
   ;;;--- Inform the user of progress
   (princ "\n Counting words...")

   ;;;--- Build a new empty list to hold the used words [ no copies ]
   (setq onceList(list))
   
   ;;;--- Cycle through the words in the main word list
   (foreach a wordList

     ;;;---  If it does not exist in the onceList, add it
     (if(not(member a onceList))
       (setq onceList(append onceList (list a)))
     )
   )

   ;;;--- Create a new empty list to hold the results
   (setq resultsList(list))

   ;;;--- If the word text file is being used as a filter...
   (if useWordsList

     ;;;--- Reset the words to use with the words from the words.txt file      
     (setq onceList useWordsList)
   )

   ;;;--- Cycle through each word to count the words
   (foreach a onceList

     ;;;--- Set up a counter
     (setq cntr 0 cnt 0 pcntr 0)

     ;;;--- Cycle through each word in the main list [ words found in drawing ]
     (foreach b wordList

       (setq cntr(+ cntr 1))

       ;;;--- If it matches, then count it
       (if(= a b)
         (setq cnt(+ cnt 1))
       )

       ;;;--- Increment the progress counter
       (setq pcntr(+ pcntr 1))

       ;;;--- Inform the user every fifty entities
       (if(> pcntr 49)
         (progn
           (princ "\n working on entity - ")(princ cntr)(terpri)
           (setq pcntr 0)
         )
       )
     )

     ;;;--- Inform the user of progress
     (princ "\n Formatting for display...")

     ;;;--- Convert the count to a string
     (setq cnt(itoa cnt))

     ;;;--- Format the string to be 25 characters long for display purposes
     (while(
     ;;;--- Format the count string to be 10 characters for display purposes
     (while(
     ;;;--- Add the string and the count to the new list
     (setq newList(append newList (list (strcat a cnt))))
   )

   ;;;--- Reset the wordList to contain the data
   (setq wordList newList)

   ;;;--- Clear the abandoned list
   (setq newList nil)
   (setq onceList nil)


   (princ "\n Update completed.")

   ;;;--- Refresh the list in the dialog box
   (start_list "wordlist" 3)
   (mapcar 'add_list wordList)
   (end_list)

   (if(      (progn

       ;;;--- Refresh the list in the dialog box
       (start_list "wordlist" 3)
       (mapcar 'add_list (list "No words found"))
       (end_list)
     )
   )
 )




 ;;;--- Function to sort a list for AutoCAD Release 14
 ;;;
 ;;;--- Usage  (sort (list "F" "A" "B"))
 ;;;
 (defun sort(alist / n)(setq lcup nil rcup nil)
   (defun cts(a b)
     (cond
       ((> a b)t)
       ((= a b )t)
       (t nil)
   ) )
   (foreach n alist
     (while (and rcup(cts n(car rcup)))(setq lcup(cons(car rcup)lcup)rcup(cdr rcup)))
     (while (and lcup(cts(car lcup)n))(setq rcup(cons(car lcup)rcup)lcup(cdr lcup)))
     (setq rcup(cons n rcup))
   )
   (append(reverse lcup)rcup)
 )



 ;;;--- Function to replace a word in the word editor dialog

 (defun replaceWord()

   (setq newWord(get_tile "newword"))
   
   (if (and word (/= newword ""))
     (progn

       (setq oldList useWordsList)
       (setq useWordsList(list))
       (foreach a oldList
         (if(/= a word)
           (setq useWordsList(append useWordsList (list a)))
           (setq useWordsList(append useWordsList (list newWord)))
         )
       )

       ;;;--- Sort the list
       (setq useWordsList(sort useWordsList))

       ;;;--- Refresh the list in the dialog box
       (start_list "wordslist" 3)
       (mapcar 'add_list useWordsList)
       (end_list)

       (set_tile "newword" "")

       (mode_tile "replword" 1)
       (mode_tile "addword"  1)
       (mode_tile "delword"  1)
     )
   )
 )


 ;;;--- Function to replace a word in the word editor dialog

 (defun deleteWord()
   (if word
     (progn

       ;;;--- Save the old list
       (setq oldList useWordsList)

       ;;;--- Clear the good list
       (setq useWordsList(list))

       ;;;--- Cycle through old list
       (foreach a oldList

         ;;;--- If it is not the word to delete, then add it
         (if(/= a word)
           (setq useWordsList(append useWordsList (list a)))
         )
       )

       ;;;--- Refresh the list in the dialog box
       (start_list "wordslist" 3)
       (mapcar 'add_list useWordsList)
       (end_list)

       ;;;--- Clear the edit box 
       (set_tile "newword" "")

       (mode_tile "replword" 1)
       (mode_tile "addword"  1)
       (mode_tile "delword"  1)
     )
   )
 )




 ;;;--- Function to add a word in the word editor dialog

 (defun addWord()

   ;;;--- Get the word from the edit box
   (setq newWord(get_tile "newword"))

   (if (/= newWord "")
     (progn

       (setq useWordsList(append useWordsList (list newWord)))

       ;;;--- Sort the list
       (setq useWordsList(sort useWordsList))

       ;;;--- Refresh the list in the dialog box
       (start_list "wordslist" 3)
       (mapcar 'add_list useWordsList)
       (end_list)

       ;;;--- Clear the edit box 
       (set_tile "newword" "")

       ;;;--- Clear the list box of selections
       (set_tile "wordslist" "0")

       (setq word nil)

       (mode_tile "replword" 1)
       (mode_tile "addword"  1)
       (mode_tile "delword"  1)

     )
   )
 )


 ;;;--- Function to save the words list in the word editor to file

 (defun saveWords()

   (if(setq wordFile(findfile "WORDS.TXT"))
     (progn
       (if(setq fil(open wordFile "w"))
         (progn
           (setq cnt 0)
           (foreach a useWordsList
             (if(= cnt 0)
               (princ a fil)
               (princ (strcat "\n" a) fil)
             )
             (setq cnt(+ cnt 1))
           )
           (close fil)
           (alert "Save current word list to file!")
         )
         (alert "Could not open the WORDs.TXT file!")
       )
     )
     (alert "Could not find the WORDS.TXT file!")
   )
 )
        



 ;;;--- Function to get the selected item from the word editor list

 (defun getSelection()
   (setq indexItem(atoi(get_tile "wordslist")))
   (setq word(nth indexItem useWordsList))
   (set_tile "newword" word)
   (mode_tile "addword"  0)
   (mode_tile "delword"  0)
   (mode_tile "replword" 0)
 )

 


 ;;;--- Function to edit the words in the word.txt file

 (defun editWords()

   ;;;--- Load the dialog definition
   (new_dialog "WORDEDITOR" dcl_id)

   (getWordsFromFile)

   ;;;--- Refresh the list in the dialog box
   (start_list "wordslist" 3)
   (mapcar 'add_list useWordsList)
   (end_list)

   (mode_tile "addword"  1)
   (mode_tile "delword"  1)
   (mode_tile "replword" 1)

   ;;;--- If an action event occurs, do this function
   (action_tile "wordslist" "(getSelection)")
   (action_tile "replword"  "(replaceWord)")
   (action_tile "addword"   "(addWord)")
   (action_tile "delword"   "(deleteWord)")
   (action_tile "savewords" "(saveWords)")
   (action_tile "cancel2"   "(done_dialog)")

   ;;;--- Display the dialog box
   (start_dialog)

 )





 ;;;--- Function to save the word list to file (text or csv)

 (defun save2File()

   ;;;--- Get a default file name
   (setq filName(getvar "dwgname"))
   (if(= (strcase(substr filName (- (strlen filName) 3))) ".DWG")
     (setq filName(substr filName 1 (- (strlen filName) 4)))
   )
   
   ;;;--- Ask the user for a file name
   (if(setq filName(getfiled "File to Save" filName "txt;csv" 1))
     (progn
       
       ;;;--- See if the user chose a CSV file or a TXT file
       (if(= "CSV" (strcase(substr filName (- (strlen filName) 2))))
         (setq filType "CSV")
         (setq filType "TXT")
       )

       ;;;--- Try to open the file to write
       (if(setq fil(open filName "w"))
         (progn

           ;;;--- Cycle through all of the items in the word list
           (foreach a wordList

             ;;;--- If a CSV type file was selected...
             (if(= filType "CSV")
               (progn

                 ;;;--- Seperate the word from the count  "word  count" -->  word, count
                 (setq cnt 1 char "X" word "" count 0)
                 (while(/= char " ") 
                   (setq char(substr a cnt 1))
                   (setq cnt(+ cnt 1))
                 )
                 (setq word(substr a 1 (- cnt 1)))
                 (setq count(itoa(fix(atof (substr a cnt)))))

                 ;;;--- Print the data to the CSV file
                 (princ (strcat word "," count "\n") fil)

               )

               ;;;--- Else, a TXT file was selected...
               (princ (strcat a "\n") fil)
             )
           )

           ;;;--- Close the file
           (close fil)

           ;;;--- Inform the user
           (alert (strcat "File " filName " created!"))
         )

         (alert "Error trying to open file.\n\nMake sure it is not open by another application.")
       )
     )
     (alert "Error - Function cancelled by null file name.\n\nData will not be written to a file.")
   )
 )




 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;                                                                          ;;;
 ;;;     888       888          888           8888888      8888   888         ;;;
 ;;;     8888     8888         88888            888        88888  888         ;;;
 ;;;     88888   88888        888 888           888        888888 888         ;;;
 ;;;     888888 888888       888   888          888        888 888888         ;;;
 ;;;     888 88888 888      88888888888         888        888  88888         ;;;
 ;;;     888  888  888     888       888      8888888      888   8888         ;;;
 ;;;                                                                          ;;;
 ;;;                                                                          ;;;
 ;;;                888            888888888        888888888                 ;;;
 ;;;               88888           888   888        888   888                 ;;;
 ;;;              888 888          888   888        888   888                 ;;;
 ;;;             888   888         888888888        888888888                 ;;;
 ;;;            88888888888        888              888                       ;;;
 ;;;           888       888       888              888                       ;;;
 ;;;                                                                          ;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



 ;;;--- Load the dialog box from file
 (setq dcl_id (load_dialog "WORDS.dcl"))

 ;;;--- See if it is loaded
 (if (not (new_dialog "WORDS" dcl_id))
   (progn
     (alert "The WORDS.DCL file could not be found!")
     (exit)
   )
 )

 ;;;--- See if there are default settings to use
 (setq deflt(getvar "useri4"))
 (if(> deflt 15)(progn(set_tile "getdim" "1")(setq deflt(- deflt 16)))(set_tile "getdim" "0"))
 (if(> deflt 7 )(progn(set_tile "getblk" "1")(setq deflt(- deflt 8 )))(set_tile "getblk" "0"))
 (if(> deflt 3 )(progn(set_tile "getmtx" "1")(setq deflt(- deflt 4 )))(set_tile "getmtx" "0"))
 (if(> deflt 1 )(progn(set_tile "getatt" "1")(setq deflt(- deflt 2 )))(set_tile "getatt" "0"))
 (if(> deflt 0 )(progn(set_tile "gettxt" "1")(setq deflt(- deflt 1 )))(set_tile "gettxt" "0"))

 (if(setq wordsFile(findfile "WORDS.TXT"))
   (mode_tile "only" 0)
   (mode_tile "only" 1)
 )

 ;;;--- If an action event occurs, do this function
 (action_tile "editwords" "(editWords)")
 (action_tile "okay"      "(updateData)")
 (action_tile "save2file" "(save2File)")
 (action_tile "cancel"    "(done_dialog)")

 ;;;--- Display the dialog box
 (start_dialog)

 ;;;--- Unload the dialog box from memory
 (unload_dialog dcl_id)

 (princ)
)

 

le DCL :

 

 WORDS  : dialog {
        label = "WORDS - Get the quantity of words. [JefferyPSanders.com]";
        : column {
          : boxed_row {
            label = "Select the type of entities to get the words from:";
            : toggle {
              label = "Text";
              key = "gettxt";
            }
            : toggle {
              label = "Attributes";
              key = "getatt";
            }
            : toggle {
              label = "MText";
              key = "getmtx";
            }
            : toggle {
              label = "Text inside Blocks";
              key = "getblk";
            }
            : toggle {
              label = "Dimension Text";
              key = "getdim";
            }
          }
          : row {
            : toggle {
              label = "Only show words listed in the WORDS.TXT file. [ Disabled if not found ]";
              key = "only";
            }
            : button { 
              key = "editwords";
              label = "Edit Word List";
              is_default = false;
              is_cancel = false;
            }
          }
          : boxed_row {
            : list_box { 
              label = "Word List";
              key = "wordlist";  
              height = 10;
              width = 35;
              multiple_select = false;
              fixed_width_font = true;
              value = 0;
            }
          }
          : boxed_row {
            : button { 
              key = "okay";
              label = "Run";
              is_default = true;
              is_cancel = false;
            }
            : button { 
              key = "save2file";
              label = "Save to File";
              is_default = true;
              is_cancel = false;
            }
            : button { 
              key = "cancel";
              label = "Exit";
              is_default = false;
              is_cancel = true;
            }
          }
        }
}
WORDEDITOR : dialog {
            label = "WORD Editor [JefferyPSanders.com]";
            : column {
              : boxed_column {
                : list_box { 
                  label = "Word List";
                  key = "wordslist";  
                  height = 10;
                  width = 35;
                  multiple_select = false;
                  fixed_width_font = true;
                  value = 0;
                }
                : edit_box {
                  key = "newword";
                  label = "Word:";
                  edit_width = 25;
                }                 
              }
              : boxed_row {
                : button { 
                  key = "addword";
                  label = "Add";
                  is_default = true;
                  is_cancel = false;
                }
                : button { 
                  key = "delword";
                  label = "Delete";
                  is_default = false;
                  is_cancel = false;
                }
                : button { 
                  key = "replword";
                  label = "Replace";
                  is_default = false;
                  is_cancel = false;
                }
                : button { 
                  key = "savewords";
                  label = "Save";
                  is_default = false;
                  is_cancel = false;
                }
                : button { 
                  key = "cancel2";
                  label = "Exit";
                  is_default = false;
                  is_cancel = true;
                }
              }
            }
}

 

Son site :

 

http://www.jefferypsanders.com/

Civil 3D 2025 - COVADIS_18.3b

https://www.linkedin...3%ABt-95313341/

Créer un compte ou se connecter pour commenter

Vous devez être membre afin de pouvoir déposer un commentaire

Créer un compte

Créez un compte sur notre communauté. C’est facile !

Créer un nouveau compte

Se connecter

Vous avez déjà un compte ? Connectez-vous ici.

Connectez-vous maintenant
×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer. Politique de confidentialité