[PythonCAD] seek to entity

Eric Wilhelm ewilhelm at sbcglobal.net
Sun Oct 5 22:23:29 EDT 2003


> The following was supposedly scribed by
> Art Haas
> on Sunday 05 October 2003 06:54 pm:

>The way reading the entities works, at least with the R13, R14, and R15
>readers, is the object map section is read in first, creating a list of
>file offsets where the objects are stored. At this point the number of
>entities in the file is known. So there can certainly be something
>written where each each entity is individually read in. In the code I've
>made, this is kinda-sorta done in the read_objects() functions, This
>function just saves all the entities it reads in as a list then returns
>the list. Some sort of generator-type code could be created to where
>each entry taken from the object map processed one "object" at a time.

I'm not a fluent speaker of Python, so correct me if I'm reading this 
incorrectly.

It looks like the read_objects() function is storing the entity data in a data 
structure and then adding this entire structure to the return list.

What I had in mind (since it looks like you are going to run through yet 
another level of code before getting this into your pythoncad data structure 
anyway) is something more along the lines of:

(if you don't mind me speaking in Perl)

$dwg = Class::Whatever->new()
$dwg->load("file/from/disk.dwg");
$handle = $dwg->StartEntityGet("modelspace"); # rewinds the list
while($object = $dwg->getObject($handle) ) {
	$type = $object->type();
	if($type eq "line") { # whatever, you get the point
		my %data = (
			"pts" => $object->getPoints(),
			"color" => $object->getColor(),
			);
		$self->addline(\%data);
		}
	} # end while

See, I am going to loop over the entity list and load the data into a 
structure of my own design (as I am guessing you plan to do as well.)

For this reason, I think it makes sense to simply provide a way to get to the 
next entity (I agree that the format does not seem to lend itself to random 
access.)  If you set it up like this, it is similar to while($line = <FILE>) 
and you simply burn through the list, picking and choosing what you want.

I only suggest this because it looks like the current function is using 
memory, when the data is going to be reassigned to another structure in the 
long run anyway.  If everything is just pointers and references, then that is 
fine (and my apologies for not speaking the native tongue.)

--Eric
-- 
Cult: A small, unpopular religion.
Religion: A large, popular cult.
                                        -- Unknown




More information about the PythonCAD mailing list