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

Can you BIND ThingWorx data to a Model Item Augmentation in Vuforia Studios?

rrzink91
8-Gravel

Can you BIND ThingWorx data to a Model Item Augmentation in Vuforia Studios?

I've been wondering this for some time. The goal is that once you press the model item, a list of data will render on a 2D dropdown widget. As it stands, I know how to bind IoT data from ThingWorx over to gauges and 3d text on Vuforia Studios. However, due to a lack of documentation (a comprehensive API), I'm unable to discern if what I'm asking is even possible. At this point, I'm trying to discover a plausible solution through trial and error. Any help/insight is appreciated.

ACCEPTED SOLUTION

Accepted Solutions

Hi @rrzink91 

I think the answer is yes. This is possible.

The solution could consist of 2 parts

1.) register first a click event on item - I believe here is intended to have an assembly where you pick simple an component- and want to have then information about the selected component, right?

And depending on which component was clicked then you need a way to identify the clicked component.

You can register the 'userpick' event and then depending on the selection you can check the selection - it should be something like   <model>-pathid  (path id = occurrence path in a modelItem widget – but here you do not need to defined explicitly and modelItem widget  )

Example for selection  model-1-/0/3/2

The code could be something like this :

$rootScope.$on('modelLoaded', function()  {
 
angular.forEach($element.find('twx-dt-model'), function(value, key) {
    // search all twx-td-model's -> means all model widgets
   angular.element(value).scope().$on('userpick',function(event,target,parent,edata) {
     //for each model widget will set a userpick listener 
     try{
      console.log('edata');console.warn(edata);
	  console.log("JSON.parse(edata)");console.warn(JSON.parse(edata));       
   	   	var pathid = JSON.parse(edata).occurrence;
	    $scope.currentSelection = target + "-" + pathid;
// this is the current selection - the selected component occurence
// you can use it for example as shown below
     console.log("=>>"+$scope.currentSelection);
     } catch (ea) {console.error("not twx-model is clicked but still fired")}
 try{ 

     // if in preview mode we will hide this/ selected component
	 tml3dRenderer.setProperties($scope.currentSelection, { hidden:true } );  
   
} catch (wrong) {console.error( "wrong:"+wrong); }

	     } ) //end of the userpick defintion	 
		 } ) //end of for each funciton

/////////////////////  
} )

 2.) you can prepare you  data in an json file in the project upload folder which could be loaded in the current session via the $http service. 

 $http.get('app/resources/Uploaded/' + jsonFile).success(function(data, status, headers, config) {
    $scope.compJSON_mod[target]=data;
   
 angular.forEach(data , function(position, path_id){
$scope.compJSON_Data[target+'-'+path_id] =position;
 
console.log("target="+target+" --> $scope.compJSON_Data["+path_id+"] = "+$scope.compJSON_Data[path_id]);
   
});//end of the error function ////////// finish for each path_id

  })
  .error(function(data, status, headers, config) {console.log("problem in the http will create a new ");

 

here we will load the position data (position is only a sample name of any data) to an array with index = UI selection. So you can get later directly the data from the array,  when you have the selection - in userpick event - then you  can find the position data – or as mentioned  it could by any Object data which could be displayed later in a 2d widget

 

View solution in original post

1 REPLY 1

Hi @rrzink91 

I think the answer is yes. This is possible.

The solution could consist of 2 parts

1.) register first a click event on item - I believe here is intended to have an assembly where you pick simple an component- and want to have then information about the selected component, right?

And depending on which component was clicked then you need a way to identify the clicked component.

You can register the 'userpick' event and then depending on the selection you can check the selection - it should be something like   <model>-pathid  (path id = occurrence path in a modelItem widget – but here you do not need to defined explicitly and modelItem widget  )

Example for selection  model-1-/0/3/2

The code could be something like this :

$rootScope.$on('modelLoaded', function()  {
 
angular.forEach($element.find('twx-dt-model'), function(value, key) {
    // search all twx-td-model's -> means all model widgets
   angular.element(value).scope().$on('userpick',function(event,target,parent,edata) {
     //for each model widget will set a userpick listener 
     try{
      console.log('edata');console.warn(edata);
	  console.log("JSON.parse(edata)");console.warn(JSON.parse(edata));       
   	   	var pathid = JSON.parse(edata).occurrence;
	    $scope.currentSelection = target + "-" + pathid;
// this is the current selection - the selected component occurence
// you can use it for example as shown below
     console.log("=>>"+$scope.currentSelection);
     } catch (ea) {console.error("not twx-model is clicked but still fired")}
 try{ 

     // if in preview mode we will hide this/ selected component
	 tml3dRenderer.setProperties($scope.currentSelection, { hidden:true } );  
   
} catch (wrong) {console.error( "wrong:"+wrong); }

	     } ) //end of the userpick defintion	 
		 } ) //end of for each funciton

/////////////////////  
} )

 2.) you can prepare you  data in an json file in the project upload folder which could be loaded in the current session via the $http service. 

 $http.get('app/resources/Uploaded/' + jsonFile).success(function(data, status, headers, config) {
    $scope.compJSON_mod[target]=data;
   
 angular.forEach(data , function(position, path_id){
$scope.compJSON_Data[target+'-'+path_id] =position;
 
console.log("target="+target+" --> $scope.compJSON_Data["+path_id+"] = "+$scope.compJSON_Data[path_id]);
   
});//end of the error function ////////// finish for each path_id

  })
  .error(function(data, status, headers, config) {console.log("problem in the http will create a new ");

 

here we will load the position data (position is only a sample name of any data) to an array with index = UI selection. So you can get later directly the data from the array,  when you have the selection - in userpick event - then you  can find the position data – or as mentioned  it could by any Object data which could be displayed later in a 2d widget

 

Announcements

Top Tags