See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Help needed for modification of block extraction lisp

  1. #1
    Login to Give a bone
    0

    Default Help needed for modification of block extraction lisp

    The attached lisp selects all blocks named "TEST" in the drawing and writes a line with coordinates (Y, X) for each one in a txt file. Can someone help with a modification that will add the attributes values after the coordinates, for example:

    Now it's: Y,X (one line for each block)

    Should be: Y,X,Material att value,Year att value,Status att value (one line for each block)

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,103
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Have you searched the forums on how to get the attribute data? I'm fairly certain someone has posted a solution that may help you get there. If you use the VLISP methods, you might be able to get there easier.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    The ActiveX BlockReference object has a GetAttributes method that you can foreach. See this thread for some sample code.
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member
    Join Date
    2016-05
    Posts
    19
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Use "dataextraction" command in AutoCAD to extract the current drawing attribute data or select multiple drawings or a folder that contains a lot of drawings.

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    That was fun.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2023 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: This function will extract Y,X position of ALL test block plus data from attributes and
    ; export it to a csv data file of same name as drawing.
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line function list
    ;___________________________________________________________________________________________________________|
    
    ;* C:SUR
    ;* Command Line Function to extract position and attribute textstrings of ALL "test" blocks
    
    ;* C:SurveyData
    ;* Command Line Function to extract position and attribute textstrings of ALL "test" blocks
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;* (BlockData objBlock)
    ;* Function to convert a entity based selection set to a list.
    
    ;* (SurveyDataFileName)
    ;* Function to make a datafile name. 
    
    ;* (ErrorTrap symFunction)
    ;* Function to convert a entity based selection set to a list.
    
    ;* (ListToCSVFile strFilename lstOfSublists strChar)
    ;* Export a list of sublists of strings to a text file
    
    ;* (ListToCSVString lstSublist strChar)
    ;* Function to Convert List to CSV String
    
    ;* (SelectionSetToList ssSelections)
    ;* Function to convert a entity based selection set to a list.
    
    ;$ End Header
    
    
    ;___________________________________________________________________________________________________________| 
    ;
    ; Command Line Function to extract position and attribute textstrings of ALL "test" blocks
    ;___________________________________________________________________________________________________________|
    
    (defun C:SUR ()(C:SurveyData))
    
    (defun C:SurveyData (/ lstBlocks lstOfSublists ssSelections strDataFile)
     (if (and (setq ssSelections  (ssget "X" (list (cons 2 "TEST"))))
              (setq lstBlocks     (SelectionSetToList ssSelections))
              (setq lstOfSublists (mapcar 'BlockData lstBlocks))
              (setq strDataFile   (SurveyDataFileName))
              (ListToCSVFile strDataFile lstOfSublists ",")
              (getstring "\nPress Enter to view data file: ")
         )
      (command "notepad" strDataFile)
     )
     (princ)
    )
    
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a entity based selection set to a list.
    ;___________________________________________________________________________________________________________|
    
    (defun BlockData (objBlock / lstAttributeObjects lstTextStrings lstInsertion )
     (if (and (setq lstInsertion        (vlax-get objBlock "insertionpoint"))
              (setq lstAttributeObjects (vlax-invoke objBlock "getattributes"))
              (setq lstTextStrings      (mapcar '(lambda (X)(vlax-get X "textstring"))  lstAttributeObjects))
         )
      (list (nth 1 lstInsertion)
            (nth 0 lstInsertion)
            (nth 0 lstTextStrings)
            (nth 1 lstTextStrings)
            (nth 2 lstTextStrings)
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to make a datafile name. 
    ;___________________________________________________________________________________________________________|
    
    (defun SurveyDataFileName (/ strFileName strFullName)
     (if (and (setq strFilename (getvar "dwgname"))
              (/= strFileName "")
              (setq strFullName          (findfile strFileName))
              (setq strFullName          (strcase strFullName T))
         )
      (vl-string-subst ".csv" ".dwg"  strFullName 0)
     )
    )
    
    
    
    
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a entity based selection set to a list.
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (X)(set X (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Export a list of sublists of strings to a text file
    ;___________________________________________________________________________________________________________|
    
    (defun ListToCSVFile (strFilename lstOfSublists strChar / filData lstSublist)
     (and
      (errortrap (quote (setq filData (open strFileName "w"))))
      (errortrap (quote (close filData)))
      (errortrap (quote (setq filData (open strFileName "w"))))
      (mapcar '(lambda (X)(and
                           (setq strText (ListtoCSVString X strChar))
                           (errortrap (quote (write-line strText filData)))
                          )
               )
               lstOfSublists
      )
     )
     (and
      filData
      (errortrap (quote (close filData)))
     ) 
    )
    
    
    ;___________________________________________________________________________________________________________|
    ; 
    ; Function to Convert List to CSV String
    ;___________________________________________________________________________________________________________|
    
    (defun ListToCSVString (lstSublist strChar / lstOfSublists)
     (if (and
          (setq lstSublist    (mapcar 'vl-princ-to-string lstSublist))
          (setq lstSublist  (mapcar '(lambda (X)(list strChar X)) lstSublist))
          (setq lstSublist  (apply 'append lstSublist))
         )
      (apply 'strcat (cdr lstSublist))
     )
    )
    
    ;___________________________________________________________________________________________________________| 
    ;
    ; Function to convert a entity based selection set to a list.
    ;___________________________________________________________________________________________________________|
    
    (defun SelectionSetToList (ssSelections / entSelection intCount lstObjects objSelection )
     (repeat (setq intCount (sslength ssSelections))
      (setq intCount (1- intCount))
      (setq entSelection (ssname ssSelections intCount))
      (setq objSelection (vlax-ename->vla-object entSelection))
      (setq lstObjects   (cons objSelection lstObjects))
     )
     lstObjects
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2023-06-07 at 11:19 PM.
    AutomateCAD

  6. #6
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    1

    Default Re: Help needed for modification of block extraction lisp

    Should these be other way around XY not YX ?

    (nth 1 lstInsertion)
    (nth 0 lstInsertion)

    A bit of fun.

    Select multiple blocks with various attributes, from none to up to 25 atts in my test dwg.

    Count the blocks and base the count on up to 5 levels deep in the attributes.

    Make a table of the result or send to Excel direct.

    Yes has a cost. Done in lisp.

    eg result Door block

    DOOR Black silverhandle 22
    DOOR Black goldhandle 12
    DOOR White silverhandle 4
    DOOR White goldhandle 4

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Al,

    Surveyors as a convention record Northing and Easting or Y,X.

    So what he was asking for was correct if he is working with surveying

    That is why I named it Survey Data.

    ...

    I have posted recursive counting functions here too.

    Yes very valuable.

    If designed correctly you can generate automatic bill of materials, survey points, legends...

    The potential is infinite and profitable.


    P=

    Al do you have this program or just working on it?

    Can you post test drawing?
    Last edited by peter; 2023-06-08 at 04:41 PM.
    AutomateCAD

  8. #8
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Peter I will test make a few blocks and edit the blocks.

  9. #9
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Big Al,

    I have the extract portion and wondered if you wanted a column for each tagstring or just ignore the tagstring and just extract the attributes in order.

    Peter
    AutomateCAD

  10. #10
    Member
    Join Date
    2011-11
    Location
    Nicaragua
    Posts
    3
    Login to Give a bone
    0

    Default Re: Help needed for modification of block extraction lisp

    Hi Sr. I can ask you a question, I need to make some modifications to your code that work for me. What I need is that instead of being a block with attributes, it is a block that only contains text. Below you will find the file that I mentioned
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Similar Threads

  1. AutoLisp (Modification in Area Lisp Needed)
    By Sameer Ahmed in forum AutoLISP
    Replies: 2
    Last Post: 2019-09-25, 05:12 AM
  2. Need a help in modification of lisp. Please update the lisp code as required.
    By brahmanandam.thadikonda762224 in forum AutoLISP
    Replies: 0
    Last Post: 2018-09-20, 04:12 AM
  3. Replies: 3
    Last Post: 2015-01-05, 03:05 AM
  4. Help needed with Attribute extraction and import into MS Excel
    By Lee Buckmaster in forum Productstream - General
    Replies: 0
    Last Post: 2012-04-30, 08:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •