Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hi All,
I want to make a thing to Enable and Restart within Eclipse Extension.
How can i do this?
Thing things = new Thing();
things.Enable Thing();
things.RestartThing();
Above code is not working.
Thanks & Regards,
Sathishkumar C.
Solved! Go to Solution.
@Sathishkumar_C In that case I think the issue might be that you are attempting start / enable of thing on template level and that's not possible. You need to attempt that on the object , something like this
@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = { "isAsync:false" }) @ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {}) public void CreateAThing() throws Exception { _logger.trace("Entering Service: CreateAThing"); _logger.trace("Exiting Service: CreateAThing"); EntityServices newThingService = new EntityServices(); String name = "UniqueThingName"; String desc = "Static Thing from Custom Extension"; TagCollection myTag = null; try { newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew"); } catch (Exception e) { System.out.println("Failed to create Thing"); e.printStackTrace(); } Thing mything = (Thing) EntityUtilities.findEntity(name, ThingworxRelationshipTypes.Thing); _logger.trace("Failed to find thing", mything.getName()); try { mything.EnableThing(); } catch (Exception e) { System.out.println("Failed to enable thing" + mything.getName()); e.printStackTrace(); }
Hi @Sathishkumar_C could you share exactly what sort of error / issue you are running into?
I can't able to enable and restart the thing after creation.
Do you mean once you import the extension you can't enable and restart those Entities? could you please share any screenshot or template detail you are working with?
Thing Creation script itself written in eclipse only. After importing an extension, i will create a thing and then i will enable and restart thing.
I quickly tested it out for me it's working, not sure if you are doing something different. Here's my script from the extension in the eclipse
@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = { "isAsync:false" }) @ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {}) public void CreateAThing() throws Exception { _logger.trace("Entering Service: CreateAThing"); _logger.trace("Exiting Service: CreateAThing"); EntityServices newThingService = new EntityServices(); String name = "UniqueThingName"; String desc = "Static Thing from Custom Extension"; TagCollection myTag = null; try { newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew"); } catch (Exception e) { // TODO Auto-generated catch block System.out.println("Failed to create the thing"); e.printStackTrace(); } }
After importing the extension I get the ExtensionStandardNew ThingTemplate from which I create a thing say T2, from T2 I execute the CreateAThing
Which creates a thing called "UniqueThingName" which is disabled by default, so from a different thing i check for it and enable & restart it
This is fine.
After thing created it will be disabled state. So, i want to EnableThing() and RestartThing().
newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew");
Here,
EnableThing();
RestartThing();
it should happen automatically within eclipse code.
Thanks & Regards,
Sathishkumar C.
@Sathishkumar_C In that case I think the issue might be that you are attempting start / enable of thing on template level and that's not possible. You need to attempt that on the object , something like this
@ThingworxServiceDefinition(name = "CreateAThing", description = "", category = "", isAllowOverride = false, aspects = { "isAsync:false" }) @ThingworxServiceResult(name = "Result", description = "", baseType = "BOOLEAN", aspects = {}) public void CreateAThing() throws Exception { _logger.trace("Entering Service: CreateAThing"); _logger.trace("Exiting Service: CreateAThing"); EntityServices newThingService = new EntityServices(); String name = "UniqueThingName"; String desc = "Static Thing from Custom Extension"; TagCollection myTag = null; try { newThingService.CreateThing(name, desc, myTag, "ExtensionStandardNew"); } catch (Exception e) { System.out.println("Failed to create Thing"); e.printStackTrace(); } Thing mything = (Thing) EntityUtilities.findEntity(name, ThingworxRelationshipTypes.Thing); _logger.trace("Failed to find thing", mything.getName()); try { mything.EnableThing(); } catch (Exception e) { System.out.println("Failed to enable thing" + mything.getName()); e.printStackTrace(); }
Working fine.
Thanks.