cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Find all ThingTemplates implementing a base ThingTemplate

asinclair
1-Newbie

Find all ThingTemplates implementing a base ThingTemplate

If an application has only a handful of ThingTemplates but hundreds of Things, what is the best way to find all of the ThingTemplates that are derived from a base ThingTemplate?

2 REPLIES 2
PaiChung
22-Sapphire I
(To:asinclair)

There are services that give you the dependencies. To narrow down the search and not just start from GenericThing, I would either tag the base templates or hardcode the basetemplate if there is only one.

Pai,

I found that services like GetAllImplementingThings and the like do not filtering on EntityType (or maybe I just don't know how).

In our case, to find out if another ThingTemplate has been derived from the base ThingTemple, we will have to weed through an ever growing number of Things to find that one ThingTemplate that has probably been there from the beginning.

Here is what I came up with ... I turned the problem over and started by getting a list of ThingTemplate entities, which should be a smaller list and more stable over time than the "implementing things" list, and then loop through that list looking for ThingTemplates that are derived from the base. Also, in the same logic, if you know that Model Tags are used in a disciplined way, this knowledge can be used to quickly narrow the field to a handful of user created ThingTemplates.

Is there a more direct way to get what I am after?

-Andy

// Returns all ThingTemplates marked with Tags that are derived from Base


// Get all ThingTemplates that are marked with 'Tags'

var Types = { items: ['ThingTemplate'] }

var params = {

                maxItems: undefined /* NUMBER */,

                searchExpression: undefined /* STRING */,

                types: Types /* JSON */,

                aspects: undefined /* JSON */,

                excludedAspects: undefined /* JSON */,

                maxSearchItems: undefined /* NUMBER */,

                tags: Tags /* TAGS */

}

// result: INFOTABLE dataShape: EntityDescriptor

var allTemplates = Resources["SearchFunctions"].SearchModelEntities(params);

var derivedTemplates = Resources["InfoTableFunctions"].Clone({ t1: allTemplates});

derivedTemplates.RemoveAllRows();

// Discard templates that are not derived from Base

var baseAsParam = { thingTemplateName: Base /* THINGTEMPLATENAME */ }

var tableLength = allTemplates.rows.length;

for (var x = 0; x < tableLength; x++) {

                var row = allTemplates.rows;

                //Your code here

    if (ThingTemplates[row.name].IsDerivedFromTemplate(baseAsParam))

        derivedTemplates.AddRow(row);

}

result = derivedTemplates;

Top Tags