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

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 : Nuances, Tips & Tricks

No ratings

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

 

While both ThingShape and ThingTemplate are basic building blocks for IoT model in ThingWorx platform; they differ to an extent in terms of the usage and logic
 
  • ThingShapes could be seen as bit more basic building block compared to the ThingTemplate
  • ThingTemplates can implement one or more ThingShapes, this is not possible vice versa
  • ThingShapes are ought to be used for implementing more generalised business logic as opposed to ThingTemplate
  • There's no requirement to select ThingTemplate while creating a ThingShape
  • A Thing inherits a ThingShape via the ThingTemplate which it is implementing

 

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

  1. Navigate to the ThingWorx Composer > New > ThingShape
  2. Add an unique name to the ThingShape
  3. Notice during creation there's no ThingTemplate needed for selection, however behind the scene all Things in ThingWorx draw from base template called GenericThing
  4. Under Properties and Alerts section add required properties
  5. Finally, Save the entity

imageCreating ThingShape via 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

  1. Navigate to a Thing > Services > Snippets > Search for ThingShape
  2. And add the CreateThingShape service, which will look like this
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

 

  • Adding new entities while developing custom extension via the Extension SDK would require adding those entities to the metadata.xml
  • Failing to appropriately update metadata.xml will lead to either failure in importing the extension whithin ThingWorx or Entities might not appear correctly
  • Custom extension development process can be greatly accelerated and extension project correctly configured using the Eclipse Plugin for ThingWorx Extensions available for download from ThingWorx Marketplace
  • Eclipse Plugin for ThingWorx Extensions ensures that custom entities are correctly organized under metadata.xml - this update to the metadata.xml file is applied automatically as the user go about creating entities within the project's scope
  • Users might prefer to write custom entities over creating them in ThingWorx for the reasons custom entities and code used for creating custom services under the extension - are hidden when they are built into an extension and imported into ThingWorx

Other related reads

Version history
Last update:
‎Mar 09, 2018 08:03 AM
Updated by: