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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Creating Media entities and style definitions through scripting

muzzammil
11-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
mnarang
17-Peridot
(To:muzzammil)

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
mnarang
17-Peridot
(To:muzzammil)

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

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

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

mnarang
17-Peridot
(To:muzzammil)

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 

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??

@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);

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

Top Tags