Using SSGET with -ATTEXT

Using SSGET with -ATTEXT

KeithSWD
Advocate Advocate
630 Views
8 Replies
Message 1 of 9

Using SSGET with -ATTEXT

KeithSWD
Advocate
Advocate

I have Autocad LT 2025, and am trying to create a short AutoLisp routine to extract attributes from selected blocks which are located on multiple layout tabs, and cannot therefore be selected manually.

 

I am just testing the essentials of the routine, before adding any 'niceties' or error trapping etc.  I have two block names to collect data from (plname and plname-na). The selection set is getting created correctly, but -attext doesn't seem to accept it. I have tried with and without the "" after passing the selection set, but execution is not progressing correctly beyond this point.

 

My familiarity with AutoLisp is pretty basic, so I'm probably missing something very obvious, but I can't figure out what!

 

Many thanks

 

(defun c:getplants ()
(setq tags (ssget "x" '((0 . "insert") (-4 . "<or") (2 . "plname") (2 . "plname-na") (-4 . "or>"))))
(command "-attext" "o" tags "" "c" "Plname-Template.txt" ".\\PlantList.txt")
(princ)
)

  

0 Likes
Accepted solutions (3)
631 Views
8 Replies
Replies (8)
Message 2 of 9

Moshe-A
Mentor
Mentor

@KeithSWD ,

 

it been a while since i used this method but i think you do not have to preselect the blocks. you can specify the block attribute tag to extract in plantList.txt

BL:NAME C015000
TAG1 C007000
TAG2 C007000
TAG3 C007000

Moshe

 

 

0 Likes
Message 3 of 9

ВeekeeCZ
Consultant
Consultant

It works for me - it found the dummy template file...

 

Select objects: Enter attribute extraction type [Cdf/Sdf/Dxf] <C>: c
Enter template file name <C:\Users\xxx\Documents\Plname-Template.txt>: Plname-Template.txt ** Invalid field specification:
AAA

 

Edit: It works only with blocks in the current space. ATTEXT filters them out. You would need to loop the routine across all the layouts where blocks are stored and process ATTEXT for each of them.

 

Command: GETPLANTS
-attext Enter extraction type or enable object selection [Cdf/Sdf/Dxf/Objects] <C>: o
Select objects: 1 found
1 was not in current space.

0 Likes
Message 4 of 9

KeithSWD
Advocate
Advocate

Apologies, you are right, I should have posted the template and a sample file. I expected that I had made some simple rookie syntax error that someone would spot straight off! 

In restarting Autocad and setting up a new clean test drawing etc. to post here, the routine is now suddenly working, I have no idea why.  But now I have a different problem, the extract is only working for the "plname" blocks, not the "plname-na" blocks. It seems to be the addition of a dynamic 'mirror' action to that block that prevents extraction due to anonymous block naming. I doesn't look like there is a solution for this with LT, as the EATTEXT command is only available in full Autocad.

 

So I have removed the dynamic attributes from the "plname-na" block, and confirmed that I can extract the attributes from them interactively with ATTEXT. However, when I run the routine, despite SSGET retrieving 132 block entities, the -ATTEXT only extracts the three that are in the current layout visible when executing the command. So I am back to square one...

0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

At some point, writing the entire thing down is just more convenient than trying to persuade the built-in commands to behave.

 

(vl-load-com)

(defun c:ExportAtts ( / *error* f s l bs as x p)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if f (close f))
    (princ))
  

  (setq bs "plname,plname-na"
	as '("NAME" "NO" "BED" "SIZE" "GROUP" "AREA"))


  (if (setq s (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat "`*U*," bs)))))
    (repeat (setq i (sslength s))
      (and (setq e (ssname s (setq i (1- i))))
	   (not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list e "BlockTableRecord/Name")))))
	   (wcmatch x bs)
	   (setq l (cons e l))
	   )))

  (and l
       (setq f (open (setq p (strcat (getvar "dwgprefix") (getvar "dwgname") "-PlantList" ".csv")) "w"))
       (foreach e l
	 (write-line (write-line (substr (apply 'strcat (mapcar (function (lambda (a) (strcat ",'" (if (not (vl-catch-all-error-p (setq x (vl-catch-all-apply 'getpropertyvalue (list e a))))) x "") "'") )) as)) 2)) f))
       (write-line (strcat "Stored at '" p "'"))
       )

  (*error* "end")
  )

 

Message 6 of 9

KeithSWD
Advocate
Advocate

Thank you very much for taking the time to write an alternative routine for me - certainly beyond my current coding ability!

Unfortunately when I run it I get an error:

 

Command: EXPORTATTS
Error: ADS request error

 

I believe this is something to do with 'getpropertyvalue' but I'm afraid I don't know how to fix it!

 

thanks again for your help.

0 Likes
Message 7 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Updated. Try again. Does it fail on your posted sample file?

0 Likes
Message 8 of 9

KeithSWD
Advocate
Advocate
Accepted solution

That has fixed it - I can't thank you enough @ВeekeeCZ !  You have save me so much time.

 

keith

0 Likes
Message 9 of 9

ВeekeeCZ
Consultant
Consultant

Glad to help. Cheers

0 Likes