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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

how to specify the template?

旭王1
1-Newbie

how to specify the template?

I am not very understanding of this,how to specify the template?

QQ截图20170610095409.png

1 ACCEPTED SOLUTION

Accepted Solutions
AnnaAn
13-Aquamarine
(To:旭王1)

Dear 旭王,

Firstly I believe you have already setup your Extension project with "New Extension Project" option(this is on the prerequisite that you have already installed ThingWorx extension eclipse plugin from Marketplace), if not you need to manually add a new project and organize your project folders that is compatible with Extension's requirement(for exmaple, you should add src,configfiles,lib,etc.)

and then please follow the given example in our developer guide - HelloWorld Example. Basically it is authored like:

1. Create a new java class name with HelloWorldThing and extends with com.thingworx.things.Thing, and configure the property, service, event definition which are needed per your requirement

2. Edit metadata.xml:

this is a sample:

<Entities>

<ExtensionPackages>

  <ExtensionPackage name="HelloWorld_Extension"

        description="HelloWorld Extension. Sample extension."

        vendor="ThingWorx Customer Service"

        packageVersion="1.0"

        minimumThingWorxVersion="5.0.0" >

  <JarResources>

    <FileResource type="JAR" file="thingworx-helloworld-extension.jar" description="HelloWorld ThingPackage JAR" />

  </JarResources>

  </ExtensionPackage>

</ExtensionPackages>

<ThingPackages>

  <ThingPackage name="HelloWorldThing" description="Sample Extension" className="com.helloinc.things.helloworld.HelloWorldThing" aspect.isSystemObject="false" aspect.isCreatable="true" />

  <ThingPackage name="GoodByeThing" description="Sample Extension" className="com.helloinc.things.goodbye.GoodByeThing" aspect.isSystemObject="false" aspect.isCreatable="true" />

</ThingPackages>

<ThingTemplates>

  <ThingTemplate name="HelloWorld" description="HelloWorld Template" thingPackage="HelloWorldThing" aspect.isSystemObject="false">

  <avatar/>

  </ThingTemplate>

  <ThingTemplate name="GoodBye" description="GoodBye Template" thingPackage="GoodByeThing" aspect.isSystemObject="false">

  <avatar/>

  </ThingTemplate>

</ThingTemplates>

<DataShapes>

  <DataShape name="SalutationSentEvent" description="Hello World salutation event" aspect.isSystemObject="false">

  <FieldDefinitions>

    <FieldDefinition name="userGreeted" description="Name of user receiving the salutation" baseType="STRING" aspect.isPrimaryKey="true"/>

  </FieldDefinitions>

  </DataShape>

</DataShapes>

</Entities>

Notice that in the ThingTemplates node in metadata.xml, we have HelloWorld setting as the template and HelloWorldThing as the ThingPackage, so after importing your extension into Thingworx, you will see there is HelloWorld ThingTemplate in ThingWorx Composer.

I hope it will help you.

Br,

Anna

View solution in original post

1 REPLY 1
AnnaAn
13-Aquamarine
(To:旭王1)

Dear 旭王,

Firstly I believe you have already setup your Extension project with "New Extension Project" option(this is on the prerequisite that you have already installed ThingWorx extension eclipse plugin from Marketplace), if not you need to manually add a new project and organize your project folders that is compatible with Extension's requirement(for exmaple, you should add src,configfiles,lib,etc.)

and then please follow the given example in our developer guide - HelloWorld Example. Basically it is authored like:

1. Create a new java class name with HelloWorldThing and extends with com.thingworx.things.Thing, and configure the property, service, event definition which are needed per your requirement

2. Edit metadata.xml:

this is a sample:

<Entities>

<ExtensionPackages>

  <ExtensionPackage name="HelloWorld_Extension"

        description="HelloWorld Extension. Sample extension."

        vendor="ThingWorx Customer Service"

        packageVersion="1.0"

        minimumThingWorxVersion="5.0.0" >

  <JarResources>

    <FileResource type="JAR" file="thingworx-helloworld-extension.jar" description="HelloWorld ThingPackage JAR" />

  </JarResources>

  </ExtensionPackage>

</ExtensionPackages>

<ThingPackages>

  <ThingPackage name="HelloWorldThing" description="Sample Extension" className="com.helloinc.things.helloworld.HelloWorldThing" aspect.isSystemObject="false" aspect.isCreatable="true" />

  <ThingPackage name="GoodByeThing" description="Sample Extension" className="com.helloinc.things.goodbye.GoodByeThing" aspect.isSystemObject="false" aspect.isCreatable="true" />

</ThingPackages>

<ThingTemplates>

  <ThingTemplate name="HelloWorld" description="HelloWorld Template" thingPackage="HelloWorldThing" aspect.isSystemObject="false">

  <avatar/>

  </ThingTemplate>

  <ThingTemplate name="GoodBye" description="GoodBye Template" thingPackage="GoodByeThing" aspect.isSystemObject="false">

  <avatar/>

  </ThingTemplate>

</ThingTemplates>

<DataShapes>

  <DataShape name="SalutationSentEvent" description="Hello World salutation event" aspect.isSystemObject="false">

  <FieldDefinitions>

    <FieldDefinition name="userGreeted" description="Name of user receiving the salutation" baseType="STRING" aspect.isPrimaryKey="true"/>

  </FieldDefinitions>

  </DataShape>

</DataShapes>

</Entities>

Notice that in the ThingTemplates node in metadata.xml, we have HelloWorld setting as the template and HelloWorldThing as the ThingPackage, so after importing your extension into Thingworx, you will see there is HelloWorld ThingTemplate in ThingWorx Composer.

I hope it will help you.

Br,

Anna

Top Tags