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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

List Uploaded Folder Models

AlexK
14-Alexandrite

List Uploaded Folder Models

Hi community

 

I have a advanced question. 

 

Is it possible to populate a list with parts from the Uploaded folder? The Model Resources selection in Studio does the same thing. But I want the View user to be able to do it, without having to hardcode the model names in JS. If we could filter the models by some part of their name, that would be even better.

 

AlexK_0-1700728948472.png

Thank you for your help!

 

Best wishes

 

Alex

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AlexK ,

so far I know this list is  a static list . During the Vuforia View session you can not add any files to the Vuforia Studio Project folder(loaded already in the view app) So that when you have a list in Vuforia Studio it will not change during the view session

I have a similar issue , and solve this issue by creating  a list as text file (I think better will be a json file) and then loading it when  opening the project. something like this:

my list "folderList.txt" in the upload folder

1.6,sonne1.mp4
2.3,ForBiggerJoyrides.mp4
5.6,20201103_173339_HoloLens.mp4

and used then such code like this:

$scope.app.files=[]
 const directory = "app/resources/Uploaded/"
 const file="folderList.txt" 
//=====================================================
 $scope.$on("$ionicView.afterEnter", function (event) {
  $scope.app.getListObj();
})
//=======================================================================

function List_items(display,value,type,size) {
  this.display = display;
  this.value = value;
  this.type=type;
  this.size=size;
  return this;
 
}

//////=========================================================
$scope.app.getListObj=function(){
 var resp = null
  const fullFile=directory+file
 
 function reqListener() {
 // console.log(this.responseText);

   const result = this.responseText.split(/\r?\n/);
   result.forEach(element => { console.log(element );   
       let size = parseFloat(element.split(",")[0]); 
       let fname =element.split(",")[1]; 
    try{
   $scope.app.files.push(new List_items(fname,directory+fname,fname.split('.').pop(),size)) 
       } catch(e){ console.error(e);  console.warn(element)} 
    });//for elem
 $timeout(()=>{
      $scope.setWidgetProp('select-1','list' $scope.app.files )
      $scope.setWidgetProp('select-1','value', $scope.app.files[0].label)
               },250)
}

const req = new XMLHttpRequest();
req.addEventListener("load", reqListener);
req.open("GET", fullFile);
req.send();
  
}//end of getListObje
//=====================================================

 In my case I used this list for some automatic play in the background and not to display it. But I think the same approach could be used also to display the list e.g. in select widget. This was my workflow but possibly there could be a better solution and somebody could share it here. Thanks

View solution in original post

4 REPLIES 4

Hi @AlexK ,

so far I know this list is  a static list . During the Vuforia View session you can not add any files to the Vuforia Studio Project folder(loaded already in the view app) So that when you have a list in Vuforia Studio it will not change during the view session

I have a similar issue , and solve this issue by creating  a list as text file (I think better will be a json file) and then loading it when  opening the project. something like this:

my list "folderList.txt" in the upload folder

1.6,sonne1.mp4
2.3,ForBiggerJoyrides.mp4
5.6,20201103_173339_HoloLens.mp4

and used then such code like this:

$scope.app.files=[]
 const directory = "app/resources/Uploaded/"
 const file="folderList.txt" 
//=====================================================
 $scope.$on("$ionicView.afterEnter", function (event) {
  $scope.app.getListObj();
})
//=======================================================================

function List_items(display,value,type,size) {
  this.display = display;
  this.value = value;
  this.type=type;
  this.size=size;
  return this;
 
}

//////=========================================================
$scope.app.getListObj=function(){
 var resp = null
  const fullFile=directory+file
 
 function reqListener() {
 // console.log(this.responseText);

   const result = this.responseText.split(/\r?\n/);
   result.forEach(element => { console.log(element );   
       let size = parseFloat(element.split(",")[0]); 
       let fname =element.split(",")[1]; 
    try{
   $scope.app.files.push(new List_items(fname,directory+fname,fname.split('.').pop(),size)) 
       } catch(e){ console.error(e);  console.warn(element)} 
    });//for elem
 $timeout(()=>{
      $scope.setWidgetProp('select-1','list' $scope.app.files )
      $scope.setWidgetProp('select-1','value', $scope.app.files[0].label)
               },250)
}

const req = new XMLHttpRequest();
req.addEventListener("load", reqListener);
req.open("GET", fullFile);
req.send();
  
}//end of getListObje
//=====================================================

 In my case I used this list for some automatic play in the background and not to display it. But I think the same approach could be used also to display the list e.g. in select widget. This was my workflow but possibly there could be a better solution and somebody could share it here. Thanks

I think, when you have often such tasks (where you need a list of files)  - you could use some tools to create  the list of the files in the directory /or list of  directories. e.g. node.js ( e.g. referring to link)

 

let ProjectPathsrc='C:/Users/rraytchev/Documents/VuforiaStudio/Projects/Test_Eyewear'
let folder='/src/phone/resources/Uploaded'
//--------
var fs = require('fs');
var files = fs.readdirSync(ProjectPathSrc+folder);
 files.forEach(function (fname) {
 try{
   $scope.app.files.push(new List_items(fname,directory+fname)) 
// not sure if the fname is with path or only the name 
// if path then use this below instead
// $scope.app.files.push(new List_items(fname,directory+fname)) 
//var path = require('path');
//var file_name = path.basename(fname);
//$scope.app.files.push(new List_items(file_name,fname)) 
       } catch(e){ console.error(e);  console.warn(element)} 
}

 

so later the json object containing the list  (here in the variable $scope.app.files  could be saved to file (referring to the link)

 

Hello @RolandRaytchev , I tried to use this code of yours in my experience but what I get is "ReferenceError: require is not defined"

Hello @Roccobarocco ,

possibly my description was incomplete. I did not really meant to do this action inside Vuforia Studio. 

The idea was to use an external tool. So e.g. you can javaScript in node.js -but you need to install node.js e.g. for windows and then call the tool (a node.js program as javascript) in windows command prompt

> node myTool.js

Possibly first you could set the projectName where the list should be created in the tool or as enviroment variable - in this case the javascript code should read the variable: e.g.

in OS -here windows set the paths

 

set PROJECTSPATH=C:/Users/rraytchev/Documents/VuforiaStudio/Projects/
set PROJECTNAME=TEST_Eyewear

 

an later in js code:

 

let PROJECTPATH = process.env.PROJECTSPATH+process.env.PROJECTNAME

 

 So the code could be started to create the list e.g. as json in the project folder with name what you load then in your project via js. Then you can publish the proejct. The idea was to create the structure outside the proejct manually - possibly not the best option

Top Tags