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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Display instructions on button click with respective to sequence steps

IB_10645210
13-Aquamarine

Display instructions on button click with respective to sequence steps

As per the original post

 

 

@RolandRaytchev How to implement this Json file with annotation description text ? From sequence file?

ACCEPTED SOLUTION

Accepted Solutions

Hi @IB_10645210 ,So far I understood your request : you want to have some kind of extraction from pvi , sequence /figure to json file so that we can use this information in any codes

So want to provide here an simple example for parser that will e.g. read the pvi file and then write it a json file. So follwong steps

  1.  unzip the model.pvi file e.g. to folder - means you have to save the pvi file outside the pvz file. e.g. on windows simple RMB>unzip (if winzip on system is installed)
  2.  let say the pvi file is "l-Creo 3D - Assemble.pvi"   the use the variable name 
    figureName    = "Assemble"​

     and call in windows shell where a node.js is installed the following script (let say the name is myStepTool.js)  :

    /********** myStepTool.js *************/
    let figureName    = "Assemble"
    let xmlFileName   ="l-Creo 3D - " +figureName+".pvi"
    let jsonFileName  = figureName+".json"
    //name is "l-Creo 3D - Assemble.pvi"
    //=================================
    var request = require('request');
    var fs = require('fs');
    let myXmlData=[]
    let myArr     = []
    let myJsonArr =	[]
    let TempjsonObj={stepNumber: 0 , step_name_locid: "" ,
                 step_name:"",step_acknowledge:false,
                 step_description_locid:"",step_description:""}
     
    xml2js = require('xml2js');
    
    var parser = new xml2js.Parser();
    fs.readFile(__dirname + '/'+xmlFileName, function(err, data) {
        parser.parseString(data, function (err, result) {
            //console.dir(result);
    		let seq_s=result['galaxy_3di:figure']['galaxy_3di:sequence']
    		//console.log(JSON.stringify(seq_s))
    		//console.dir(  seq_s[0]['galaxy_3di:sequence_step'] )
    		//console.log( seq_s )
            console.log('Done');
    		let prop_animats=seq_s[0]['galaxy_3di:sequence_step']
    		prop_animats.forEach(el_function1)
        });
    	console.info("jsonArray\n=================\n")
    	console.log(JSON.stringify(myJsonArr))
        fs.writeFileSync(__dirname + '/'+jsonFileName, JSON.stringify(myJsonArr, null, 2) , 'utf-8');
    });
     
    
     
    function el_function1(item, index, arr) {
      let jsonObj= JSON.parse(JSON.stringify(TempjsonObj))
      jsonObj.stepNumber= index;
      myArr[index] = item['galaxy_3di:property']
      //console.log("myArr["+index+"] = "+myArr[index])
      //console.dir(myArr[index])
      //console.log("myArr["+index+"][1][\'$\'].value = "+myArr[index][1]['$'].value)
      console.log("myArr["+index+"] ["+ myArr[index][0]['$'].name+ "] = "+myArr[index][0]['$'].value)
      jsonObj.step_name_locid  =        myArr[index][0]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][1]['$'].name+ "] = "+myArr[index][1]['$'].value)
      jsonObj.step_name  =              myArr[index][1]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][2]['$'].name+ "] = "+myArr[index][2]['_'])
      jsonObj.step_acknowledge = myArr[index][2]['_']
      console.log("myArr["+index+"] ["+ myArr[index][3]['$'].name+ "] = "+myArr[index][3]['$'].value)
      jsonObj.step_description_locid =  myArr[index][3]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][4]['$'].name+ "] = "+myArr[index][4]['$'].value)
      jsonObj.step_description =        myArr[index][4]['$'].value
      
      myJsonArr.push(jsonObj)
    }
    
    
  3.  execute the tool
    >> node myStepTool.js​
  4. check for <figureNaem>.json file here in example Assemble.json
    [
      {
        "stepNumber": 0,
        "step_name_locid": "stepName_2728332481823371952_2",
        "step_name": "Assemble",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 1,
        "step_name_locid": "stepName_5894254086109201976_2",
        "step_name": "Step 1",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 2,
        "step_name_locid": "stepName_15897802472779891525_2",
        "step_name": "Step 2",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 3,
        "step_name_locid": "stepName_4089111003020719364_2",
        "step_name": "Step 3",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 4,
        "step_name_locid": "stepName_1444424151131004256_2",
        "step_name": "Step 4",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 5,
        "step_name_locid": "stepName_16935999301123799101_2",
        "step_name": "Step 5",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 6,
        "step_name_locid": "stepName_4549226109679838932_2",
        "step_name": "Step 6",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 7,
        "step_name_locid": "stepName_11110415484410389698_2",
        "step_name": "Step 7",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 8,
        "step_name_locid": "stepName_11227030841165917496_2",
        "step_name": "Step 8",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 9,
        "step_name_locid": "stepName_307606632875771006_2",
        "step_name": "Step 9",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 10,
        "step_name_locid": "stepName_5267734679139784604_2",
        "step_name": "Step 10",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 11,
        "step_name_locid": "stepName_18093258235493727066_2",
        "step_name": "Step 11",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 12,
        "step_name_locid": "stepName_8642537011799624768_2",
        "step_name": "Step 12",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 13,
        "step_name_locid": "stepName_9423943722212754853_2",
        "step_name": "Step 13",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 14,
        "step_name_locid": "stepName_6512444656035031150_2",
        "step_name": "Step 14",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 15,
        "step_name_locid": "stepName_14841759718657189243_2",
        "step_name": "Step 15",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 16,
        "step_name_locid": "stepName_7345189520540227377_2",
        "step_name": "Step 16",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      }
    ]
  5. you can test this also for the Disassembly figure with the provided data to see the attachment. So hope this helps. 

View solution in original post

6 REPLIES 6

seems to be related to the post:  and the sample project ?

Or is this new quesiton? could you ,please, check and provide details if required. Thanks

@RolandRaytchev Thank you for suggested solution.

I have sent details through message. Please check. I would appreciate any suggestions.

Hi @IB_10645210 ,So far I understood your request : you want to have some kind of extraction from pvi , sequence /figure to json file so that we can use this information in any codes

So want to provide here an simple example for parser that will e.g. read the pvi file and then write it a json file. So follwong steps

  1.  unzip the model.pvi file e.g. to folder - means you have to save the pvi file outside the pvz file. e.g. on windows simple RMB>unzip (if winzip on system is installed)
  2.  let say the pvi file is "l-Creo 3D - Assemble.pvi"   the use the variable name 
    figureName    = "Assemble"​

     and call in windows shell where a node.js is installed the following script (let say the name is myStepTool.js)  :

    /********** myStepTool.js *************/
    let figureName    = "Assemble"
    let xmlFileName   ="l-Creo 3D - " +figureName+".pvi"
    let jsonFileName  = figureName+".json"
    //name is "l-Creo 3D - Assemble.pvi"
    //=================================
    var request = require('request');
    var fs = require('fs');
    let myXmlData=[]
    let myArr     = []
    let myJsonArr =	[]
    let TempjsonObj={stepNumber: 0 , step_name_locid: "" ,
                 step_name:"",step_acknowledge:false,
                 step_description_locid:"",step_description:""}
     
    xml2js = require('xml2js');
    
    var parser = new xml2js.Parser();
    fs.readFile(__dirname + '/'+xmlFileName, function(err, data) {
        parser.parseString(data, function (err, result) {
            //console.dir(result);
    		let seq_s=result['galaxy_3di:figure']['galaxy_3di:sequence']
    		//console.log(JSON.stringify(seq_s))
    		//console.dir(  seq_s[0]['galaxy_3di:sequence_step'] )
    		//console.log( seq_s )
            console.log('Done');
    		let prop_animats=seq_s[0]['galaxy_3di:sequence_step']
    		prop_animats.forEach(el_function1)
        });
    	console.info("jsonArray\n=================\n")
    	console.log(JSON.stringify(myJsonArr))
        fs.writeFileSync(__dirname + '/'+jsonFileName, JSON.stringify(myJsonArr, null, 2) , 'utf-8');
    });
     
    
     
    function el_function1(item, index, arr) {
      let jsonObj= JSON.parse(JSON.stringify(TempjsonObj))
      jsonObj.stepNumber= index;
      myArr[index] = item['galaxy_3di:property']
      //console.log("myArr["+index+"] = "+myArr[index])
      //console.dir(myArr[index])
      //console.log("myArr["+index+"][1][\'$\'].value = "+myArr[index][1]['$'].value)
      console.log("myArr["+index+"] ["+ myArr[index][0]['$'].name+ "] = "+myArr[index][0]['$'].value)
      jsonObj.step_name_locid  =        myArr[index][0]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][1]['$'].name+ "] = "+myArr[index][1]['$'].value)
      jsonObj.step_name  =              myArr[index][1]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][2]['$'].name+ "] = "+myArr[index][2]['_'])
      jsonObj.step_acknowledge = myArr[index][2]['_']
      console.log("myArr["+index+"] ["+ myArr[index][3]['$'].name+ "] = "+myArr[index][3]['$'].value)
      jsonObj.step_description_locid =  myArr[index][3]['$'].value
      console.log("myArr["+index+"] ["+ myArr[index][4]['$'].name+ "] = "+myArr[index][4]['$'].value)
      jsonObj.step_description =        myArr[index][4]['$'].value
      
      myJsonArr.push(jsonObj)
    }
    
    
  3.  execute the tool
    >> node myStepTool.js​
  4. check for <figureNaem>.json file here in example Assemble.json
    [
      {
        "stepNumber": 0,
        "step_name_locid": "stepName_2728332481823371952_2",
        "step_name": "Assemble",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 1,
        "step_name_locid": "stepName_5894254086109201976_2",
        "step_name": "Step 1",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 2,
        "step_name_locid": "stepName_15897802472779891525_2",
        "step_name": "Step 2",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 3,
        "step_name_locid": "stepName_4089111003020719364_2",
        "step_name": "Step 3",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 4,
        "step_name_locid": "stepName_1444424151131004256_2",
        "step_name": "Step 4",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 5,
        "step_name_locid": "stepName_16935999301123799101_2",
        "step_name": "Step 5",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 6,
        "step_name_locid": "stepName_4549226109679838932_2",
        "step_name": "Step 6",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 7,
        "step_name_locid": "stepName_11110415484410389698_2",
        "step_name": "Step 7",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 8,
        "step_name_locid": "stepName_11227030841165917496_2",
        "step_name": "Step 8",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 9,
        "step_name_locid": "stepName_307606632875771006_2",
        "step_name": "Step 9",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 10,
        "step_name_locid": "stepName_5267734679139784604_2",
        "step_name": "Step 10",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 11,
        "step_name_locid": "stepName_18093258235493727066_2",
        "step_name": "Step 11",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 12,
        "step_name_locid": "stepName_8642537011799624768_2",
        "step_name": "Step 12",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 13,
        "step_name_locid": "stepName_9423943722212754853_2",
        "step_name": "Step 13",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 14,
        "step_name_locid": "stepName_6512444656035031150_2",
        "step_name": "Step 14",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 15,
        "step_name_locid": "stepName_14841759718657189243_2",
        "step_name": "Step 15",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      },
      {
        "stepNumber": 16,
        "step_name_locid": "stepName_7345189520540227377_2",
        "step_name": "Step 16",
        "step_acknowledge": "false",
        "step_description_locid": "",
        "step_description": ""
      }
    ]
  5. you can test this also for the Disassembly figure with the provided data to see the attachment. So hope this helps. 

Thank you so much!!!!!! Instructions help a lot. 

Hello @IB_10645210 

Thanks for the  feedback! Here is  another verison which will read all pvi files in the current directory and will save them there as< FirgureName>.json. You do not need to set arguments it will extract this form the file:

 

 

/*** ++++  myStepTool.js  ++++ ***/
//=================================
const request = require('request');
const fs = require('fs');
const path = require('path');
let myArr     = []
//---------------------
let TempjsonObj={stepNumber: 0 , step_name_locid: "" ,
             step_name:"",step_acknowledge:false,
             step_description_locid:"",step_description:""}
//---------------------
function readFiles(dir,processFile) {
  // read directory
  fs.readdir(dir, (error, fileNames) => {
    if (error) throw error;

    fileNames.forEach(filename => {
      // get current file name
      const name = path.parse(filename).name;
      // get current file extension
      const ext = path.parse(filename).ext;
      // get current file path
      const filepath = path.resolve(dir, filename);

      // get information about the file
      fs.stat(filepath, function(error, stat) {
        if (error) throw error;

        // check if the current path is a file or a folder
        const isFile = stat.isFile();

        // exclude folders
        if (isFile) {
          // callback, do something with the file
          processFile(filepath, name, ext, stat);
        }
      });
    });
  });
}
//---------------------
let processFile =(filepath, name, ext, stat)=>{
	console.info("filepath >>:",filepath)
	console.info("name >>:",name)
	console.info("ext >>:",ext)
	//console.info("stat >>:",stat)
	console.info("size >>:",stat.size)
	console.info("creationTime >>:",stat.birthtime)
	let ret=0;checkStr="l-Creo 3D - ";
	if(ext.indexOf('pvi') != -1)
		{console.warn("ext is PVI")
	      if((ret=filepath.indexOf(checkStr))!=-1){
		     //console.log(" ret ="+ret+" >>"+name.substring(checkStr.length));
			 let nameFigure=name.substring(checkStr.length)
			 processData(filepath,nameFigure)
	        }
	    }
		else console.warn("extension is not PVI")
}
//---------------------
function processData(fpath,nameFigure){
var dataset = {data: [],myJsonArr:[]};
	//--------------------
	xml2js = require('xml2js');
	let myArr     = []
    let myJsonArr =	[]
	var parser = new xml2js.Parser();
	fs.readFile(fpath, function(err, data) {
		parser.parseString(data, function (err, result) {
			//console.dir(result);
			let seq_s=result['galaxy_3di:figure']['galaxy_3di:sequence']
			let prop_animats=seq_s[0]['galaxy_3di:sequence_step']
			prop_animats.forEach(
			function(item, index, arr) {
				let jsonObj= JSON.parse(JSON.stringify(TempjsonObj))
				jsonObj.stepNumber= index;
				myArr = item['galaxy_3di:property']
				jsonObj.step_name_locid  =        myArr[0]['$'].value
				jsonObj.step_name  =              myArr[1]['$'].value
				jsonObj.step_acknowledge =        myArr[2]['_']
				jsonObj.step_description_locid =  myArr[3]['$'].value
				jsonObj.step_description =        myArr[4]['$'].value
  
			dataset.myJsonArr.push(jsonObj)
			},{_self:this,dataset:dataset})  });
		//+++++++++++++++++++++++++++++++++++++++++++++
		console.info("jsonArray was done!\n=================\n")
		//console.log(JSON.stringify(dataset.myJsonArr))
		fs.writeFileSync(__dirname + '/'+nameFigure+'.json', JSON.stringify(dataset.myJsonArr, null, 2) , 'utf-8');
});
} 
//==================================================
// below program execution in current directory
//==================================================
readFiles(__dirname,processFile)
//==================================================
console.warn("Done!")
 

 

 

 

@RolandRaytchev Hello Roland, 

Could you show an example how this was applied within the project.

I am little stuck... research didn't help

 

Announcements

Top Tags