Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
ThingShape
Much like the ThingTemplate, ThingShapes are one of the basic entities for modeling the business logic within the ThingWorx composer. They are best used for describing the relationships between the objects within your IoT model being designed in ThingWorx platform. See ThingShape in Help Center for more
Note: Additional helpful read ThingTemplate : Nuances, Tips & Tricks
ThingShape vs ThingTemplate
ThingShape vs DataShape
While ThingShape is used for defining the relationships within your IoT model in ThingWorx, DataShapes are targeted towards structuring and giving shapes & definition to the data model and how it will be represented.
DataShapes are also used for describing a data set e.g. when there's a requirement on fetching result in a specific format when querying InfoTable.
Methods to create ThingShape
There are quite a few possibilities to create ThingShape
Via the ThingWorx Composer
Via the custom ThingWorx Service within the Composer
ThingShape can also be created via the OOTB available JavaScript service under the Resources > Entity Service > CreateThingService. To use this service
var params = { name: "DemoThingShape" /* STRING */, description: "Custom ThingShape Creation Script" /* STRING */, tags: undefined /* TAGS */ }; // no return Resources["EntityServices"].CreateThingShape(params);
Via the ThingWorx Extension SDK as custom extension for ThingWorx
ThingWorx Extension SDK allows users to extend and add functionalities to ThingWorx that may not be available OOTB.
@ThingworxBaseTemplateDefinition(name = "GenericThing") public class DemoThingShape102 extends Thing { /** * custom thingShape created using Extension SDK to display most basic * structure for the class. * Note that the class is annotated with ThingworxBaseTemplateDefinition to * define GenericThing Template */ public DemoThingShape102() { // TODO Auto-generated constructor stub } }
This simple example can be extended by adding couple of properties, similar to what's defined in the ThingShape created in ThingWorx Composer. Properties are defined with annotation ThingworxPropertyDefinitions like so :
@ThingworxPropertyDefinitions(properties = { @ThingworxPropertyDefinition(name = "Prop1", description = "defined in Extension SDK ; and is persistent", category = "", baseType = "STRING", isLocalOnly = false, aspects = { "isPersistent:true", "dataChangeType:VALUE" }), @ThingworxPropertyDefinition(name = "Prop2", description = "defined in Extension SDK", category = "", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:VALUE" }) })
Putting it all toegther :
@ThingworxBaseTemplateDefinition(name = "GenericThing") @ThingworxPropertyDefinitions(properties = { @ThingworxPropertyDefinition(name = "Prop1", description = "defined in Extension SDK ; and is persistent", category = "", baseType = "STRING", isLocalOnly = false, aspects = { "isPersistent:true", "dataChangeType:VALUE" }), @ThingworxPropertyDefinition(name = "Prop2", description = "defined in Extension SDK", category = "", baseType = "NUMBER", isLocalOnly = false, aspects = { "dataChangeType:VALUE" }) }) public class DemoThingShape102 extends Thing { /** * */ public DemoThingShape102() { // TODO Auto-generated constructor stub } }
Tips & Tricks
Other related reads