Skip to main content
13-Aquamarine
January 10, 2024
Solved

Display instructions on button click with respective to sequence steps

  • January 10, 2024
  • 1 reply
  • 2364 views

As per the original post

 

 

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

Best answer by RolandRaytchev

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. 

1 reply

21-Topaz I
January 12, 2024

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

13-Aquamarine
January 12, 2024

@RolandRaytchev Thank you for suggested solution.

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

21-Topaz I
January 19, 2024

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.