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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Extract more information from PVZ files

AlexK
15-Moonstone

Extract more information from PVZ files

Dear Community

 

My goal is to streamline the process of creating AR experiences, ideally the users wouldn't need to open the Vuforia Studio Editor to create Step by Step instructions.

 

Is there a "best" way to extract all the information from the PVZ file using JS?

 

For example "step_acknowledge", or which parts are needed for each step, like a BOM of Parts the user needs to install for each step. This is visible in the animation track in creo Illustrate.

 

step_name and step_discription is available with parsedArg3

 

Thanks for your help!

 

Alex

11 REPLIES 11
AlexK
15-Moonstone
(To:VladimirN)

I don't have access to the WebGL toolkit, is there no other way?

Hello @AlexK ,

I think the informaiton what you required could be found in the pvi file. I think we can parse that <figrue name >.pvi file/xml format without Creo Toolkit for pvz/ and check for some step related informaiton e.g. to create a list of parts to a step. I check that information in the past and believe that my findings were that this should  be possible via javascript also inside studio. So means we will extract the informaiton from the pvi file to a specific sequence. I think it will be better to extract that informaiton outside Studio and prepare with the correct/desired syntax then in additional .json file which could be then used during the session inside Studio

AlexK
15-Moonstone
(To:RolandRaytchev)

Hi Roland

 

Adding an additional .json or .xml file is how I do it now. But it is always double the work and the files that we need to manage.

My goal is to be able to do everything in Illustrate, upload it to windchill, and load it dynamically to a generic template in Vuforia View.

 

In Illustrate having it is possible to define a BOM for each figure, but not for each sequence step. There is some work needed, to improve how illustrate works together with Studio.

 

Do you have an example of the pvi extraction code, that gives you the BOM information?

 

Best wishes

 

Alex

VR_4000
13-Aquamarine
(To:AlexK)

A few months ago I used this to extract BOM data from .pvi file.
How to extract model data of 3d models in Vuforia... - PTC Community

AlexK
15-Moonstone
(To:VR_4000)

Thanks for the link! I'll check it out

Hi @AlexK ,

ok I will check it , so far I understand you want to have all parts which are used /participated /affected by step operation right? Because we can only extract what is writen to the sequence. So far I know all information are in the pvi file. I will check what we can extract and will you know what are my finding. Thanks

AlexK
15-Moonstone
(To:RolandRaytchev)

Hi Roland

 

Exactly, the parts visible that are listed in the keyframe, for example:

AlexK_0-1726662989468.png

Best wishes

Alex

Thanks for the example. I checked and need to go step back. Unfortunately. I see that this is as animation:

 <galaxy_3di:animation::Timeline>
        <galaxy_3di:property
          type="string"
          name="Content"
          value="&lt;pvm&#x0a;  xmlns:ads=&quot;http://www.ptc.com/productview/namespace/pvm&quot;&#x0a;  version=&quot;1.1&quot;&gt;&#x0a;  &lt;timeline&#x0a;    name=&quot;Step 1&quot;&#x0a;    autoplay=&quot;false&quot;&#x0a;    timescale=&quot;ms&quot;&#x0a;    units=&quot;m&quot;&#x0a;    recordpartsstate=&quot;true&quot;&#x0a;    recordcamerastate=&quot;false&quot;&#x0a;    recordpausestate=&quot;false&quot;&#x0a;    show3dpath=&quot;true&quot;&#x0a;    selectTrack=&quot;true&quot;&gt;&#x0a;    &lt;containertrack&#x0a;      id=&quot;0&quot;&#x0a;      name=&quot;Step 1&quot;&#x0a;      locked=&quot;false&quot;&gt;&#x0a;      &lt;containertrack&#x0a;        id=&quot;1&quot;&#x0a;        name=&quot;New Track 1&quot;&#x0a;        locked=&quot;false&quot;&gt;&#x0a;        &lt;itemtrack&#x0a;          id=&quot;1&quot;&#x0a;          name=&quot;MAIN_BEARING_END.PRT&quot;&#x0a;          locked=&quot;false&quot;&#x0a;          type=&quot;selectionitem&quot;&gt;&#x0a;          &lt;selectionitem&#x0a;            itemtype=&quot;MCAD_Instance&quot;&#x0a;            sbomIdPath=&quot;/0/1/1/7&quot;&#x0a;            instance=&quot;:0/29/38/56&quot;/&gt;&#x0a;          &lt;propertytrack&#x0a;            id=&quot;1&quot;&#x0a;            name=&quot;Location&quot;&#x0a;            
...

where we can see in the animation <galaxy_3di:animation::Timeline> which is one element what as text contains all the information to the animation- so we can see the step - here on the short piece is Step 1 and some component e.g.  sbomIdPaht /0/1/1/7  name MAIN_VEARING_END.PRT. That will make much difficult to get it. So I think is that possible but have no description about the meaning of the whole characters so to find out the syntax of the animation definition. I think reading informaiton still could be possibly but need a different approach. 

so checked it furher- each animation timeline element  <galaxy_3di:animation::Timeline> contains one step and list of the components of that steps.

Using the following text replacements:

  1. replaced &quot; by "
  2. Replaced &#x0a; by space charecter but it could be better a new line
  3. replaced &lt by <
  4.  replaced &gt by >

I got a little more readable string:

 

<pvm  xmlns:ads="http://www.ptc.com/productview/namespace/pvm"    version="1.1">      <timeline      name="Step 1"      autoplay="false"      timescale="ms"      units="m"      recordpartsstate="true"      recordcamerastate="false"      recordpausestate="false"      show3dpath="true"      selectTrack="true">        <containertrack        id="0"        name="Step 1"        locked="false">          <containertrack          id="1"          name="New Track 1"          locked="false">            <itemtrack            id="1"            name="MAIN_BEARING_END.PRT"            locked="false"            type="selectionitem">              <selectionitem              itemtype="MCAD_Instance"              sbomIdPath="/0/1/1/7"              instance=":0/29/38/56"/>              <propertytrack              id="1"              name="Location"              locked="false"              property="location">                <key                time="14000"                fraction="0"                segment="true"                type="linear">                  <trajectory/>                  <value>0,-0.252651,3.09398e-17,0,0,0,1,1,-0.168731,-0.152145,0.00766173,0  </value>                </key>                <key                time="15000"                fraction="1"                segment="false"                original="true"                type="linear">                  <trajectory/>                  <value>0,0,0,0,0,0,1,1,-0.168731,-0.152145,0.00766173,0  </value>                </key>              </propertytrack> 
....
....

 

so when you need only the  components used of a step then possibly that will work fine

So the replacement could be done also js /also node.js via 

String.replace('old_text,'new_text')  e.g.

 

let my_anim_string=" bla bla &lt; ... bla bla &lt; bla bla...."
my_anim_string=my_anim_string.replace('&lt;','<');

 

you can use also a RegEx but for each element you need a specific parttern -> .please see also https://stackoverflow.com/questions/1162529/javascript-replace-regex

so therefore I think replace is the more easy option.  

 

I think to decript it we need to use xml decode - some xml entity table similar to that is mentioned in the  https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

and 

https://www.baeldung.com/xml-encode-special-characters

so at the end to get a pure xml what we can parse and search for the entities or convert to json format

I found now one of my previous attempt to extract data from pvi with node.js /javascript. required some libs /standard , I think these libs are also availible for javascript in generally - I need to check  more detailed in stackoverflow.

 

var fs = require('fs');
var request = require('request');
xml2js = require('xml2js');
var parser = new xml2js.Parser();

 

for example that I used to extracting the steps from pvi file e.g.:

 

[
  {
    "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": ""
  },
....

 

where I used that code:

 

//======== 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)
}

 

demo files attached to that post - means demo pvi the extracted text files and the js code in myStepTool.js. That code was tested in node.js evirment

2024-09-18_14-49-38.jpg

OK here the code will extract only the step attribute (for all pvi files in the current directory) but I think when the parser  could adapted so to  extract any data what is in the pvi file but need to check more detailed , it was some time ago where I tested it. So the quesiton what of data what you want to  have and  you want to extract. Possibly if you could provide a short pvi example file and sample  demo file txt what the extracted file should contain so in this case  I could try to  test and to modfy it  so to achieve that . so possibly it could work. Thanks BR

Announcements

Top Tags