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

Creating Media entities and style definitions through scripting

SOLVED
Highlighted
Garnet

Creating Media entities and style definitions through scripting

How can i go for creating Media entities and style definitions through service scripting?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Creating Media entities and style definitions through scripting

For style:

var params = {
name: "MyStyle12" /* STRING */,
description: undefined /* STRING */,
content: { "content":
{ "params" : "",
backgroundColor: "",
displayString: "",
fontEmphasisBold: false,
fontEmphasisItalic: false,
fontEmphasisUnderline: false,
foregroundColor: "",
image: "",
lineColor: "",
lineStyle: "solid",
lineThickness: 1,
secondaryBackgroundColor: "",
textSize: "normal",
description: ""
//name: "TestScriptStyle"
//tags: [] /* JSON */,
}
}
//tags: undefined /* TAGS */}
};

// no return
Resources["EntityServices"].CreateStyleDefinition(params);

 

 

 

For media ,the content type requires is image ,so get the content type from LoadImage and then use it there liek this :

 


var params1 = {
proxyScheme: undefined /* STRING */,
headers: undefined /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: undefined /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

// result: IMAGE
var result = Resources["ContentLoaderFunctions"].LoadImage(params);

var params = {
name: undefined /* STRING */,
description: undefined /* STRING */,
content: result /* IMAGE */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateMediaEntity(params);

 

 

Thanks ,

Mukul Narang 

View solution in original post

7 REPLIES 7
Highlighted

Re: Creating Media entities and style definitions through scripting

For style definitions :


var params = {
name: undefined /* STRING */,
description: undefined /* STRING */,
content: undefined /* JSON */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateStyleDefinition(params);

 

 

For Media entity:

 


var params = {
name: undefined /* STRING */,
description: undefined /* STRING */,
content: undefined /* IMAGE */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateMediaEntity(params);

 

 

Thanks,

Mukul Narang

Highlighted

Re: Creating Media entities and style definitions through scripting

Hi @mnarang , Actually i know that the snippets are there for creating media entity and style definition, but, i don't know how to assign content values in those snippets. So, kindly give some example to explain it

Highlighted

Re: Creating Media entities and style definitions through scripting

@muzzammil : entities attached .that will help in creating media & style def entities through services.

Highlighted

Re: Creating Media entities and style definitions through scripting

For style:

var params = {
name: "MyStyle12" /* STRING */,
description: undefined /* STRING */,
content: { "content":
{ "params" : "",
backgroundColor: "",
displayString: "",
fontEmphasisBold: false,
fontEmphasisItalic: false,
fontEmphasisUnderline: false,
foregroundColor: "",
image: "",
lineColor: "",
lineStyle: "solid",
lineThickness: 1,
secondaryBackgroundColor: "",
textSize: "normal",
description: ""
//name: "TestScriptStyle"
//tags: [] /* JSON */,
}
}
//tags: undefined /* TAGS */}
};

// no return
Resources["EntityServices"].CreateStyleDefinition(params);

 

 

 

For media ,the content type requires is image ,so get the content type from LoadImage and then use it there liek this :

 


var params1 = {
proxyScheme: undefined /* STRING */,
headers: undefined /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN */,
workstation: undefined /* STRING */,
useProxy: undefined /* BOOLEAN */,
proxyHost: undefined /* STRING */,
url: undefined /* STRING */,
timeout: undefined /* NUMBER */,
proxyPort: undefined /* INTEGER */,
password: undefined /* STRING */,
domain: undefined /* STRING */,
username: undefined /* STRING */
};

// result: IMAGE
var result = Resources["ContentLoaderFunctions"].LoadImage(params);

var params = {
name: undefined /* STRING */,
description: undefined /* STRING */,
content: result /* IMAGE */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateMediaEntity(params);

 

 

Thanks ,

Mukul Narang 

View solution in original post

Highlighted

Re: Creating Media entities and style definitions through scripting

Actually, i have the set of images in my PC (in D drive). I need to use those images to create media entities. So, how can i go for doing that??

Highlighted

Re: Creating Media entities and style definitions through scripting

@muzzammil : rather you can place your image file in ThingworxStorage repository

i have created a thing(imageLoadTest) using thingtemplate as FileRepository.

in ThingworxStorage repository folder created a repository named as imageLoadTest-- created a folder image inside it and placed the png file.

 

below is the script to load & create media entity

///////////////////////////////////////////////////////////////////////////////

var params = {
path: "/image/TCS_style&Media.PNG" /* STRING */
};

// result: IMAGE
var Content = Things["imageLoadTest"].LoadImage(params);

 

var params = {
name: "newMediaEntity" /* STRING */,
description: "newMediaEntity" /* STRING */,
content: Content /* IMAGE */,
tags: undefined /* TAGS */
};

// no return
Resources["EntityServices"].CreateMediaEntity(params);

Highlighted

Re: Creating Media entities and style definitions through scripting

Is there any way i could duplicate the default style definitions through scripting?

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!