Exracting list properties of objects into txt file.

Exracting list properties of objects into txt file.

abdul.raufJJ89F
Advocate Advocate
6,181 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,182 Views
28 Replies
Replies (28)
Message 2 of 29

pbejse
Mentor
Mentor

Does it need to be the format you specified? We can think of a cuople of ways to go about doing that.

But, what are you going to use it for?

 

 

0 Likes
Message 3 of 29

abdul.raufJJ89F
Advocate
Advocate

@pbejse 

I need to pass this data to my colleague who will replicate the objects using this geometrical data in the web compatible format such as SVG

I have chosen this format as it gives - object type details (LINE, ARC, POLYLINE)  with the corresponding geometric details (co-ordinates, length, etc). Non-geometric details such as handle, line type, color, etc are not required.

Thanks


 

0 Likes
Message 4 of 29

Kent1Cooper
Consultant
Consultant

Do you normally keep Log Files of your drawings?  If not, then maybe one could do something with turning LOGFILEON, doing your LIST command, turning LOGFILEOFF, then opening the log file and stepping through its lines, passing on to another file any line whose content [after leading spaces] doesn't start with an unwanted category.

 

One difficulty in my mind is the finding  of the log file by an AutoLisp routine.  I find that for a drawing called test.dwg, the associated log file is called test_15ab58da0.log -- I assume the latter part of that is arbitrarily assigned, like the Block name in a drawing when you use the PASTEBLOCK command [Ctrl+Shift+V].  But I don't think the (open) function can take wildcards, so how to have a routine determine the actual file name is a question -- it might be necessary to take the User to the log file folder and have them pick the appropriate one.

 

Another is that when I turn LOGFILEOFF and later LOGFILEON, the same file is appended to, not started over.  So I assume it would be necessary, if you do this more than once in a drawing, to have the routine delete that file if it exists, and start a new one [which will presumably get a different file name] for your current LIST command.  Otherwise, every time you use it, it will repeat information from a previous usage, in addition to the new information.

Kent Cooper, AIA
0 Likes
Message 5 of 29

pbejse
Mentor
Mentor

@abdul.raufJJ89F wrote:


I need to pass this data to my colleague who will replicate the objects using this geometrical data in the web compatible format such as SVG


And your colleague  can generate the SVG file directly form the TXT file? or is it just  going to be use as placeholder for the information ? that still still needs to be translated to a format that can be imported to SVG? 

 

Can you ask your colleague in what format / syntax ? for all we know it could be pdf, png, xml etc.. that can be directly imported to the program to create the SVG?

 

 

 

 

0 Likes
Message 6 of 29

dlanorh
Advisor
Advisor

If you want something quick and dirty using command list and a log file, try the below. It assumes logging is off and copies the log file to the current drawings directory and renames it. You'll still get some information you don't want though.

 

(defun c:lse ( / *error* sv_lst sv_vals ss)

  (defun *error* ( msg )
    (if (not (zerop (getvar 'qaflags))) (setvar qaflags 0))
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq sv_lst (list 'cmdecho 'logfilemode)
        sv_vals (mapcar 'getvar sv_lst)
  )

  (mapcar 'setvar sv_lst (list 0))

  (princ "\nSelect Entities to List : ")
  (setq ss (ssget))
  (cond (ss
          (setvar 'qaflags 2)
          (setvar 'logfilemode 1)
          (repeat (setq cnt (sslength ss)) (command "list" (ssname ss (setq cnt (1- cnt))) ""))
          (setvar 'logfilemode 0)
          (setvar 'qaflags 0)
        )
  )
  (mapcar 'setvar sv_lst sv_vals)
  (graphscr)
  (vl-file-copy (getvar 'logfilename) (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname))"-" (rtos (getvar 'cdate)) ".log"))
  (princ)
)

I am not one of the robots you're looking for

0 Likes
Message 7 of 29

abdul.raufJJ89F
Advocate
Advocate

@Kent1Cooper 

But I need to select the multiple objects probably by windows or crossing selection. There are many objects in the real cases in which selecting individually is not desirable.

I have checked using the system variable "LOGFILEPATH" the folder in which the log file will be saved.

There is some additional info such as space type, handle, line type, line weight, etc given by "list" command which is not required.

0 Likes
Message 8 of 29

Kent1Cooper
Consultant
Consultant

@abdul.raufJJ89F wrote:

.... I need to select the multiple objects probably by windows or crossing selection. There are many objects in the real cases in which selecting individually is not desirable.
....


Nothing about my suggestion limits you to selecting individually.  The log file would contain the results of a LIST command, which would include whatever you select in that command, by whatever selection method(s).

Kent Cooper, AIA
0 Likes
Message 9 of 29

abdul.raufJJ89F
Advocate
Advocate

@pbejse 

Let me share what I know. I am aware that we can get SVG from Inkscape using Dxf from AutoCAD.
But here , we are getting AutoCAD drawing from the client and we do not want to convert the whole drawing to SVG but only certain specific objects which may or may not be organized in the drawing provided by the client.

Normally , when we tried to get SVG from Dxf or pdf , it was quite large in size with many extra details and issues.
We want to create lightweight SVG with filesize desirable to be in KB without the extra baggage.

I talked to my colleague and what is required is the minimum details required which defined the geometry and its type
For eg- In order to define the circle, we need at least centre point and radius 
              In order to define the line, we need at least start point & end point and angle.
So , in short I need the object type and the minimum properties necessary to define them.


I hope I am clear now
Thanks








0 Likes
Message 10 of 29

abdul.raufJJ89F
Advocate
Advocate

@dlanorh 

Thanks for your piece of code. It is working fine,
My main focus is to get the geometrical properties of the curves such as line, polyline , circle, ellipse, etc.
Since non-geometrical properties such as space, handle , line type, color, etc are common to all types of objects , is it possible to filter it out or eliminate in our output txt file?

Ideally, I wanted the object type (circle, line, ellipse, etc) and minimum properties required to define that object as output 
  For eg: In order to define the circle, we need at least a center point and radius
               In order to define the line, we need standpoint, endpoint, and angle

I would really appreciate if you can suggest some ideas.
Thanks





0 Likes
Message 11 of 29

abdul.raufJJ89F
Advocate
Advocate

@Kent1Cooper 

I got it. Thanks
But can you also suggest me some way to filter out the properties which are not required?
My main aim is to extract geometrical properties only (to be specific minimum geometrical properties required to define the respective curve)
I don't want non-geometrical properties such as space type, handle, color, line weight, line type, etc which is common to all object type (circle, line, polyline, etc) in the final output file.

Thanks 


0 Likes
Message 12 of 29

abdul.raufJJ89F
Advocate
Advocate

@pbejse 

I am also open to any alternative solution for my case. You seem to be quite experienced
Thanks for taking interest in the topic .😀

0 Likes
Message 13 of 29

john.uhden
Mentor
Mentor

From what I've read in this thread, it appears that you might want to create a simplified dxf file containing only the geometric data.  It strikes me that this can be done by either:

a)  DXFOUT just the selected entities, then read the file line by line discarding the non-geometric data and writing a new simplified file.  or

b)  Use AutoLisp to write out the limited entity data in dxf format.

 

Either way will require knowledge of the dxf codes and their formatting.  Plus, in the case of things like text and mtext, you might have to include the style definitions.

John F. Uhden

0 Likes
Message 14 of 29

abdul.raufJJ89F
Advocate
Advocate

@john.uhden 

I have basic knowledge of AutoLISP and some of its functions. Regarding, DXf codes, I know some of the group code meaning like 0- entity type, 8- layer name, etc. I am quite a beginner and  gradually learning

FYI, my case does not require to extract any details regarding text, Mtext, attribute, dimension, leader, table or any such things. My main focus is on extracting geometrical data for curves such as line, polyline, arc, circle, spline, ellipse, etc into external file 

Any help will be appreciated.

Thanks


0 Likes
Message 15 of 29

john.uhden
Mentor
Mentor
Because you know what data you want, you might be the best one to figure
out what data to write. Your problem is in learning how to write the data.
I suggest that you create a dwg with one each of the entities you want to
write and then do a dxfout, studying the dxf file for its applicable codes
and formats.
Then for each of the objects do an (entget) to see what the data looks like
in AutoLisp format. Each property will have the same code as in the dxf
file.
You see, around here many of us would rather you solve your own problem
with our guidance, not our solving your problem with complete code. Though
there are times when we can't resist creating the full code just to test if
our ideas can really work, or if the code might be helpful in our own work.

John F. Uhden

0 Likes
Message 16 of 29

Kent1Cooper
Consultant
Consultant

@abdul.raufJJ89F wrote:

.... can you also suggest me some way to filter out the properties which are not required? ....


I was unaware of the LOGFILENAME System Variable brought up by @dlanorh in Message 6 [I don't usually deal in these things], which very conveniently includes the whole file-path and everything, so it's easy to find that file.  On the assumption that you do not  want an ongoing log file for the current drawing [because this empties it out  before it does its thing], this seems to work [minimally tested]:

 

(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
  (setvar 'logfilemode 1); turn on log file recording
  (command-s "_.list"); do command to end
  (setvar 'logfilemode 0); turn off
  (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

 

Make sure you have permissions for the folder location.

 

It depends on you to select only appropriate kinds of things for your purposes.  It could also be made to skip certain objects, such as Text, for which geometric information is irrelevant.

 

I included some things to exclude in addition to the ones you listed [linetype scale, for example], but there may be some other properties things could have, reported in LIST but that you don't want.  It's easy to add them to the exclusions string.

Kent Cooper, AIA
Message 17 of 29

Sea-Haven
Mentor
Mentor

For Abdul

 

Going back to a coded answer, you need to write a defun for each type of object. If you use dumpit.lsp you can see the properties using VL is simple. 

 

 

 

(while (setq obj (vlax-ename->vla-object (car (entsel "Pick object "))))
(setq obname (vlax-get Obj 'Objectname))
(cond
((= obname "AcDbArc")(do_arc))
((= obname "AcDbCircle)(do_circle))
((= obname "AcDBLine)(do_line))
((= obname "AcDbPolyline")(do_pline))
((alert  "object not supported"))
)
)

 

 

I hate this site keep forgetting to click poster.

 

0 Likes
Message 18 of 29

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

…. you need to write a defun for each type of object. ….


[Why was this in Reply to me?]

 

Except that then you can pull the information from only one object at a time.  Using the LIST command, they can get it from as many objects as they want, all at once.

Kent Cooper, AIA
0 Likes
Message 19 of 29

abdul.raufJJ89F
Advocate
Advocate

@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. 

Can you please fix this issue?  I simply want to select objects and get the output external file and do not want unnecessary prompt and popups in the AutoCAD

You are correct regarding that I am not concerned about objects such as text, mtext, dimensions, attribute, etc. My main focus is geometrical curves such as line, arc, polyline, ellipse, circle and so on

I have changed the following line for the desired output file location (same as dwg file location)

data (open "X:/Your/File/Path/YourFilename.txt" "w")

to 

data (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) " - Object data" ".txt") "w")


Just wondering if it is possible to have some custom prompt to users such as "SELECT ENTITIES TO EXPORT PROPERTIES: "? 

I would be grateful if you will help me to get rid of unnecessary prompts during program execution in the AutoCAD.
Thanks 

 



0 Likes
Message 20 of 29

abdul.raufJJ89F
Advocate
Advocate

@Sea-Haven 

Thanks for looking into my issue. 
In my case, Individual object selection is not desirable since there are many objects.
I simply want to select multiple objects (geometric curves such as line, arc, polyline, circle, ellipse, etc) and want to get their geometric properties into an external file.

Thanks


0 Likes