Exracting list properties of objects into txt file.

Exracting list properties of objects into txt file.

abdul.raufJJ89F
Advocate Advocate
6,186 Views
28 Replies
Message 1 of 29

Exracting list properties of objects into txt file.

abdul.raufJJ89F
Advocate
Advocate

Hello,

I need to extract the properties of various objects (such as line, polyline, ellipse, circle, and so on )  which is given by "list" command into an external txt file.

Users should be able to select the multiple objects simultaneously and thus export the list properties of all the objects into a txt file(refer attached txt file for reference) .

However, I am mostly concerned with geometrical properties and do not want details such as space type, handle, line weight, line-type, color , etc

I am attaching the sample dwg file along with the desired output required txt file.

Thanks


0 Likes
Accepted solutions (1)
6,187 Views
28 Replies
Replies (28)
Message 21 of 29

pbejse
Mentor
Mentor

@abdul.raufJJ89F wrote:

@Kent1Cooper 

Thanks for your help. But there is one issue with your code, after selecting objects, the command window gets poped up and "Press ENTER to continue" prompt appears for each object. Say if there are 100 objects, it will ask to ENTER 100  times, which is not desirable. 


 

set QAFLAGS = 3 and back to 0 after.

Better yet incorporate it on the routine.

 

 

 

0 Likes
Message 22 of 29

cadffm
Consultant
Consultant

@abdul.raufJJ89F 

Set QAFLAGS to 2 if 0 (default) before, not 3.

bit2 is only for this Textscreen stop, nothing more.

 

For someone without the knowldge: 0 default is good, 2 is not a problem, for all other values you should to know what you do.

 

My 2ct

 

Sebastian

0 Likes
Message 23 of 29

Kent1Cooper
Consultant
Consultant

@abdul.raufJJ89F wrote:

…. after selecting objects, the command window gets poped up and "Press ENTER to continue" prompt appears for each object. Say if there are 100 objects, it will ask to ENTER 100  times, which is not desirable. 
….


[It doesn't prompt for Enter to continue after each object, but only after each screen-full of data, which would mean far fewer  than 100 Enters for 100 Lines, but could be far more  than 100 Enters for 100 Polylines of numerous vertices.]

 

I can't dig into it right now, but do some Searching -- I think the question of bypassing the Enter-to-continue prompt has come up before.  I don't recall that anyone had a way to do it, but maybe.  [EDIT -- written before seeing the previous two Replies.]

 

A prompt can certainly be added before the LIST command is called.  Maybe this evening....

Kent Cooper, AIA
0 Likes
Message 24 of 29

john.uhden
Mentor
Mentor
True. But if he wants to create a DXF file, then he has to learn the codes
and format which a dump will not provide. But at least he could could
compare the dump to the entity data list to give some meaning to the codes
(or read the DXF help). I have done that myself to try to figure out which
method is easier or faster or both (VL vs. AL). Of course I've been
dealing with the object model since R14 because I bought Vital Lisp (God
bless Peter Petrov).

John F. Uhden

0 Likes
Message 25 of 29

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

 

A prompt can certainly be added before the LIST command is called.  Maybe this evening....


And also incorporating the QAFLAGS suggestion from @cadffm, try this:

(defun C:LGDO (/ source data txtline) ; = Log of Geometric Data Only
  (if (findfile (getvar 'logfilename)); log file already exists
    (progn ; then
      (setq source (open (getvar 'logfilename) "w")); empty any current content
      (close source)
    ); progn
  ); if
  (prompt "\nTo Export their Properties,")
  (if (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
    ; [will provide its own "Select objects:" prompt]
    ; *LINE covers Line/Polyline/Spline
    (progn ; then
      (setvar 'qaflags 2)
      (setvar 'logfilemode 1); turn on log file recording
      (command "_.list" ss "")
      (setvar 'logfilemode 0); turn off
      (setvar 'qaflags 0)
    ); progn
  ); if
  (setq
    source (open (getvar 'logfilename) "r"); log file just created
    data (open "X:/Your/File/Path/YourFilename.txt" "w"); reduced-content file <-- EDIT this
  ); setq
  (while (setq txtline (read-line source)); step through lines in file
    (if
      (not
        (wcmatch
          (vl-string-left-trim " " txtline); remove leading spaces
          "`[ A*,_.li*,Sel*,Spa*,Col*,Line*,Tra*,Thi*,Han*,Pre*,Ent*,Com*"
            ;; beginnings of unwanted-line content [could be more]
        ); wcmatch
      ); not
      (write-line txtline data); then -- put line into geometric data file
    ); if
  ); while
  (close source)
  (close data)
  (princ)
); defun

[Ideally, it ought to have an *error* handler added, to ensure that QAFLAGS gets reset if anything goes wrong, but the likelihood of that is small, since it's set up to change it only if there's a valid selection, and only for long enough to pull the information from the selection.  But I can add it if you want, and don't know how to.]

Kent Cooper, AIA
Message 26 of 29

john.uhden
Mentor
Mentor
I admire your perspicacity, though I should probably look up what that
means.

John F. Uhden

0 Likes
Message 27 of 29

abdul.raufJJ89F
Advocate
Advocate

Much Thanks @Kent1Cooper 

I tried searching for system variable  "QAFLAGS" but can't get many resources on the net, it seems that it is an undocumented system variable. But it solves the issue

I would be grateful if you add the error handler as I don't know how to do that, it will prevent the AutoCAD from misbehaving if something goes wrong or program is aborted suddenly.



0 Likes
Message 28 of 29

Kent1Cooper
Consultant
Consultant
Accepted solution

@abdul.raufJJ89F wrote:

.... I would be grateful if you add the error handler as I don't know how to do that, it will prevent the AutoCAD from misbehaving if something goes wrong or program is aborted suddenly.


This should do it [untested, and I didn't  incorporate your filepath/filename, so edit that again]:

(defun C:LGDO (/ *error* source data txtline) ; = Log of Geometric Data Only
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'qaflags 0); reset
    (princ)
  ); defun -- *error*
  (if (findfile (getvar 'logfilename)); log file already exists
    (progn ; then
      (setvar 'logfilemode 0); in case currently on
      (setq source (open (getvar 'logfilename) "w")); empty any current content
      (close source)
    ); progn
  ); if
  (prompt "\nTo Export their Properties,")
  (if (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
    ; [will provide its own "Select objects:" prompt]
    ; *LINE covers Line/Polyline/Spline/Xline/Mline
    (progn ; then
      (setvar 'qaflags 2)
      (setvar 'logfilemode 1); turn on log file recording
      (command "_.list" ss "")
      (setvar 'logfilemode 0); turn off
      (setvar 'qaflags 0)
    ); progn
  ); if
  (setq
    source (open (getvar 'logfilename) "r"); log file just created
    data (open "X:/Your/File/Path/YourFilename.txt" "w"); reduced-content file <-- EDIT this
  ); setq
  (while (setq txtline (read-line source)); step through lines in file
    (if
      (not
        (wcmatch
          (vl-string-left-trim " " txtline); remove leading spaces
          "`[ A*,_.li*,Sel*,Spa*,Col*,Line*,Tra*,Thi*,Han*,Pre*,Ent*,Com*"
            ;; beginnings of unwanted-line content [could be more]
        ); wcmatch
      ); not
      (write-line txtline data); then -- put line into geometric data file
    ); if
  ); while
  (close source)
  (close data)
  (princ)
); defun

 

Kent Cooper, AIA
Message 29 of 29

abdul.raufJJ89F
Advocate
Advocate

Thanks mate @Kent1Cooper 

0 Likes