Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
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
"How to extract the components with properties from a pvz file":
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
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
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
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
Hi Roland
Exactly, the parts visible that are listed in the keyframe, for example:
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="<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"

...
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:
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 < ... bla bla < bla bla...."
my_anim_string=my_anim_string.replace('<','<');
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
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