4 Sep 2019

executeUserFunction accepts user data

As mentioned in the release notes of the v7 version of the Viewer here, now you can pass user data to the executeUserFunction() ?

That simplifies the autoSelect() function used in this article, since now we don't have to play with template literals in order to achieve what we need:

async function autoSelect(viewer, tag) {
    let res = await viewer.model.getPropertyDb().executeUserFunction(function userFunction(pdb, tag) {
        var dbIds = [];

        pdb.enumObjects(dbId => {
            let p = pdb.getObjectProperties(dbId);
            let pv = p && p.properties;
            if (!pv) return;

            if (p.name === tag) {
                return true;
        return dbIds;  
    }, tag);
    let dbId = res[0];
    console.log(`dbId with tag ${tag} => ${dbId}`);


Related Article

Posted By

Adam Nagy

Follow @AdamTheNagy Adam Nagy joined Autodesk back in 2005 and has been providing programming support, consulting, training and evangelism to external developers. He started his career in Budapest, then worked in Prague for 3 years and now lives in South England, UK. At the moment focusing on Inventor and Fusion 360, plus cloud and mobile related technologies. Adam has a degree in Software Engineering and has...