How do I traverse through all the entities in a .layout file


#1

Can some one tell me how do I traverse through the entities in a .layout file with new Layout 2016 C API ?

I have tried the following
LOEntityListRef entity_list;
LOEntityListCreate(&entity_list);
LODocumentGetSharedEntities(document_ref,entity_list);
LOEntityListGetNumberOfEntities(entity_list,&num_entities);

I am getting an access violation reading location error in the 4th line


#2

Did you inspect the return values of the functions prior to this?
Also, you don’t show in your example how you declared num_entities. Can you provide a more complete snippet of what you are currently doing?

Have you looked at the examples in the SDK package?


#3

Thanks thomthom. I could’nt find any example in the SDK package which does similar operation. But I figured out why I was getting the error. In the second line I didn’t assign LOEntityListRef entity_list as SU_INVALID.

size_t num_entities = 0;
LOEntityListRef entity_list = SU_INVALID;
SUResult res;
res = LOEntityListCreate(&entity_list);
std::cout << "Result - LOEntityListCreate : " << res << std::endl;
res = LODocumentGetSharedEntities(document_ref,entity_list);
std::cout << "Result - LODocumentGetSharedEntities : " << res << std::endl;
res = LOEntityListGetNumberOfEntities(entity_list,&num_entities);
std::cout << "Result - LOEntityListGetNumberOfEntities : " << res << std::endl;

For the above snippet I am getting the output

Result - LOEntityListCreate : 0
Result - LODocumentGetSharedEntities : 9
Result - LOEntityListGetNumberOfEntities : 0

Not sure why the second line is showing the output 9. That means SU_ERROR_NO_DATA. My layout document contains 4 layers which includes some texts in the title block and the exported skp model.

I need to modify the texts in the title block. And I assumed I can achieve it by looping through all the entities, finding the text and replacing it.


#4

@adam or @JeremyWalker - got some insight to add to this?


#5

My first guess is that there are no entities on shared layers. Try using
LOPageGetNonSharedEntities () instead of LODocumentGetSharedEntities ().
That will get all of the entities that belong to a given page.

Hope that helps,
Adam


#6

@adam, Thanks for your support :slightly_smiling:

You were right. I was able to access all the entities with LOPageGetNonSharedEntities () .