SimplifiedLogic / creoson

OpenSource Automation using JSON Transactions for PTC's CREO Parametric
http://www.creoson.com
MIT License
79 stars 23 forks source link

View object creation error #105

Closed bperryrm closed 6 months ago

bperryrm commented 6 months ago

Hello, I'm attempting to get the list of views from an open model and seem to be getting an error rather than the list of views. Hoping someone can point out where I've gone wrong below or if there's a Creoson error. I'm running this code in the playground window.

The file name is test.prt and there is a view inside the model named "FRONT".

let fileObj = new creo.FileObj();
fileObj.display = true;
fileObj.activate = true;
fileObj.file = 'test.prt';
fileObj.new_window = true;
let bFileOpen = 0;
bFileOpen = fileObj.open();
if (bFileOpen <= 0) {
    alert("Fileopen failed = " + fileObj.file);
}

let dMV = new creo.ViewObj();
dMV.file = fileObj.file;
dMV.name = "FRONT";
dMV.list()
    .then(function(arViewList){

    //Error: The list function appears to return something valid
    //but arViewList[0] is undefined.
    alert('Array View List = ' + arViewList[0]);

    })
    .catch((err) => {
            alert('ERROR: '+err);
    });
bperryrm commented 6 months ago

test.prt.zip

Here's the test part I'm using with a FRONT view inside it.

bperryrm commented 6 months ago

I realized my error, I forgot the view.List function returns a promise rather than an array.