Hi Everyone I am new to Autolisp,
Please guide me on the following code, I have taken the efforts to go through the complete forum for solution but could not understand.
(defun c:CRTP (/ sel SS dxeFile)
(initget 1 "All Select")
(setq sel (strcase (getkword "\Select individual blocks or Select All (S or A): ")))
(if (= sel "SELECT")
(setq SS (ssget '((2 . "xyz123")))
)
(setq SS (ssget "_X" '((2 . "xyz123")))
)
)
; Define the path to your predefined DXE file
(setq dxeFile "C:\\Users\\Desktop\\dsf.dxe") ; Update with the full path to your DXE file
; Check if any blocks were selected
(if (null SS)
(prompt "\nNo blocks selected.")
(progn
; Load the predefined DXE file
(command "-dataextraction" "DATAEXTRACTION" "LOAD" dxeFile)
; Select the specified objects
(command "-dataextraction" "SELECT" SS "")
; Generate the data extraction table
(command "-dataextraction" "EXTRACT" "")
(princ "Data Extraction table created.")
)
)
(princ)
)
(defun c:CRTP (/ sel SS)
(setq sel (strcase (getkword "\nSelect individual blocks or select all (S ou A): ")))
(if (= sel "S")
(setq SS (ssget "X" '((2 . "YOURBLOCKNAME"))) ; Replace "YOURBLOCKNAME" with the name of the block you want to select.
)
(setq SS (ssget "_X" '((2 . "YOURBLOCKNAME")))
)
)
(if (null SS)
(alert "No blocks selected.")
(progn
(comando "-dataextraction" "DATAEXTRACTION" "ON")
(comando "-dataextraction" "OBJECTS" SS)
(comando "-dataextraction" "INCLUDE" "Y" "Atributos")
(comando "-dataextraction" "EXTRACT" "S" "M" "Sim" "")
(comando "-dataextraction" "EXIT")
(princ "\nCreated data extraction table.")
)
)
(principal)
)
Here are the main corrections and clarifications:
Corrected the prompt for "Select individual blocks or Select All (S or A):" to clarify the "S" options for individual selection and "A" for selection of all.
The block selection is made based on the user's choice and stored in the SS variable. Make sure to replace "YOURBLOCKNAME" with the name of the block you want to select.
To create the data extraction table, the code uses a series of "-dataextraction" commands. It activates data extraction, defines the selected objects, adds attributes to the extraction, extracts the data, and finally ends the extraction and displays a message indicating that the table has been created.
Thank you for the response.
I am trying to add Data Extraction table in the model space using pre-defined dxe file, but I am unable to change the selection of objects for the dxe file, And I get the same result everytime I run the lisp.
(defun c:CRTP (/ sel SS dxeFile)
(initget 1 "All Select")
(setq sel (strcase (getkword "\Select individual blocks or Select All (S or A): ")))
(if (= sel "SELECT")
(setq ss (ssget '((2 . "xyz123"))))
(setq ss (ssget "X" '((2 . "xyz123"))))
)
(if (zerop (getvar "CMDACTIVE"))
(progn (sssetfirst ss ss)(princ))
ss
)
(command "-DATAEXTRACTION" (strcat (getvar 'dwgprefix) "dsf.dxe"))
(if (wcmatch (getvar "cmdnames") "*DATAEXTRACTION*") (command "_Y"))
)
The data extraction command does not take the selected block set as a selection for the command.
It creates table at the end which is based on default manual selection by dxe.file
If you want end result a table of multiple blocks etc then dont worry about dataextraction, there are so many extract attribute details and put into a table using lisp. These can be a custom single answer or a more complex multi named block solution.
As an example select multiple named blocks with multiple attributes per block, count similar blocks and up to 5 levels of attributes and put in a table.
If you post a dwg with blocks and the desired table I am sure you will get multiple answers.
So will it be a datalink and can be updated as DataExtraction after changes are made. If yes can you share some reference for the lisp.
I am talking about a custom extract from blocks attribute values and put in a table. There are hundreds of examples out there, that is why I suggested post a dwg and a resulting table. There are so many options like fixed names of blocks, pick pick pick blocks and so on. A more global answer may be what you want.
Include your dxe.
I have attached screenshot of my blocks and table result I am interested in, For your reference also attached. Want to achieve this with the help of lisp.
TRY
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-table/td-p/7821821
(defun c:TESTCoordinatesBlock (/ ss name ref refs insPt table row)
(vl-load-com)
(or *acdoc*
(setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(or *blocks*
(setq *blocks* (vla-get-Blocks *acdoc*))
)
(prompt "\nSelect blocks to list or <All>")
(or (setq ss (ssget '((0 . "INSERT"))))
(setq ss (ssget "_X" '((0 . "INSERT") (66 . 1)))
)
)
(if ss
(progn
(vlax-for x (setq ss (vla-get-ActiveSelectionSet *acdoc*))
(if (not (vlax-property-available-p x 'Path))
(progn
(setq attn
(vl-remove nil (mapcar '(lambda (v) (IF (or (= "TP_ID" (vla-get-tagstring v)) (= "BP_ID" (vla-get-tagstring v))) (vla-get-textstring v) ) )
(vlax-invoke x 'Getattributes)
)) ;_ end of car
) ;_ end of setq
(setq attELEVATION
(vl-remove nil (mapcar '(lambda (v) (IF(= "ELEVATION" (vla-get-tagstring v)) (vla-get-textstring v) ) )
(vlax-invoke x 'Getattributes)
)) ;_ end of car
) ;_ end of setq
(setq ipt (vlax-get x 'InsertionPoint)
iptx (car ipt)
ipty (cadr ipt)
)
(setq name (vla-get-effectivename x))
(setq refs (cons (list (car attn) iptx ipty (car attELEVATION)) refs) )
;(setq refs nil )
)
)
)
(vla-delete ss)
(initget 1)
(setq insPt (trans (getpoint "\nInsertion point: ") 1 0))
(setq table (vla-addtable
(vla-get-modelspace *acdoc*)
(vlax-3d-point insPt)
(+ 2 (length refs)) ; number of rows (including title and header)
4 ; number of colums
0.5 ; cell height
2 ; row width
)
)
(vla-put-TitleSuppressed table :vlax-false)
(vla-put-HeaderSuppressed table :vlax-false)
(vla-setText table 0 0 "Coordinates")
(vla-setText table 1 0 name)
(vla-setText table 1 1 "Position X")
(vla-SetColumnWidth table 1 2.2 )
(vla-setText table 1 2 "Position Y")
(vla-SetColumnWidth table 2 2.2)
(vla-setText table 1 3 "ELEVATION")
(setq row 2)
(foreach item refs
(vla-settext table row 0 (car item))
(vla-settext table row 1 (cAdr item))
(vla-settext table row 2 (cADDr item))
(vla-settext table row 3 (cAdDDr item))
(setq row (1+ row))
)
)
)
(princ)
)
Thank you for the reply but using this I am not able to update table data links.
If any changes are made to the blocks later.
@hosneyalaa Can you help to sort the block in order for the table. It disrupts the order if some blocks are created later.
Can't find what you're looking for? Ask the community or share your knowledge.