Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Default value of a configurable variable from an imported part studio?

MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
I have imported a studio to be instantiated. There is a configured variable called "fillet". Is there a way to grab the imported studio's default value for "fillet"?

Learn more about the Gospel of Christ  ( Here )

CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎

Best Answers

  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    Answer ✓
    If you’re talking about configurations, then the answer is not really, unless you try doing shenanigans with queries to figure out the fillet radius after importing. However, the instantiator does give you options to drive the configuration of imported part studios, even ones which are selected manually, so although you don’t know the default, you could easily override it with whatever computer value you want. 
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
    Answer ✓
    For anyone else trying to instantiate a part studio and would like to control the custom configurations while keeping the default configurations default values if they are not changed... Each instantiation definition map must be the same size. I wrote this to check for the largest definition in my array of maps. Once it finds the largest definition map, it goes through all the other definition maps and adds fake configurations to maintain the definition map size for the instantiation... 
    //For instantiations, each instantiation definition map must be the same size
            //Find the largest map
            var largestMap = 0;
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                if (size(customParameterDefinitions[i]) >= largestMap)
                {
                    largestMap = size(customParameterDefinitions[i]);
                }
            }
    
            //Adds fake configurations to the map until all maps are the same size for instantiations
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                var thisMap = size(customParameterDefinitions[i]);
    
                if (thisMap < largestMap)
                {
                    for (var k = 0; k < largestMap; k += 1)
                    {
                        if (size(customParameterDefinitions[i]) < largestMap)
                        {
                            customParameterDefinitions[i] = mergeMaps(customParameterDefinitions[i], { "Nothingness" ~ toString(k) : 0 * inch });
                        }
                    }
                }
            }


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    A couple things can help build this type of feature:

    1) When FeatureScript controls a specific configuration value, you can make that value unsettable by end users with the "ComputedConfigurationInputs" option.
    Place with length
    2) When using that option, the value passed in will always be the default value of that Part Studio configuration parameter at the time the feature was created. Its exact value can be accessed as e.g. definition.selectedPartStudio.Length

    3) When adding the instances, any number of configuration inputs can be overridden in the addInstance function with e.g.
    addInstance(instantiator, definition.partStudio, {
                "configurationOverride" : {
                    "Length" : computedLength
                }
            });
    You can make a single instance with a custom value, or make many instances with different custom values.

    @MichaelPascoe
    For your specific issue on map size, it seems very odd that such code would be necessary. What error are you seeing from the instantiator if instance maps are not the same size?

Answers

  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    Answer ✓
    If you’re talking about configurations, then the answer is not really, unless you try doing shenanigans with queries to figure out the fillet radius after importing. However, the instantiator does give you options to drive the configuration of imported part studios, even ones which are selected manually, so although you don’t know the default, you could easily override it with whatever computer value you want. 
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
    I will go with the override method for now. Thanks for the advice!

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
    Answer ✓
    For anyone else trying to instantiate a part studio and would like to control the custom configurations while keeping the default configurations default values if they are not changed... Each instantiation definition map must be the same size. I wrote this to check for the largest definition in my array of maps. Once it finds the largest definition map, it goes through all the other definition maps and adds fake configurations to maintain the definition map size for the instantiation... 
    //For instantiations, each instantiation definition map must be the same size
            //Find the largest map
            var largestMap = 0;
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                if (size(customParameterDefinitions[i]) >= largestMap)
                {
                    largestMap = size(customParameterDefinitions[i]);
                }
            }
    
            //Adds fake configurations to the map until all maps are the same size for instantiations
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                var thisMap = size(customParameterDefinitions[i]);
    
                if (thisMap < largestMap)
                {
                    for (var k = 0; k < largestMap; k += 1)
                    {
                        if (size(customParameterDefinitions[i]) < largestMap)
                        {
                            customParameterDefinitions[i] = mergeMaps(customParameterDefinitions[i], { "Nothingness" ~ toString(k) : 0 * inch });
                        }
                    }
                }
            }


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Alex_KempenAlex_Kempen Member Posts: 248 EDU
    edited August 2021
    Last time I checked, there are no requirements anywhere in FeatureScript regarding the size of maps since maps are basically infinitely expandable. So long as required keys (and matching values) are present, additional key - value pairs are disregarded, even when doing things like type checking:
    var myPlane = XY_PLANE;
    myPlane.hi = true;
    println(myPlane as map); // prints: { hi : true , normal : (0, 0, 1) , origin : (0 meter, 0 meter, 0 meter) , x : (1, 0, 0) }
    println(myPlane is Plane); // prints true

    If you want to see an example of the configurator being used to bring in configured bodies, I would take a look at lines 912-981 of my belt calculator FS here:
    https://cad.onshape.com/documents/9cffa92db8b62219498f89af/w/06b332ccabc9d2e0aa0abf88/e/99672d1e329b38e647d90146
    addInstance(instantiator, configurablePulley::build, {
                            "configuration" : {
                                    "Pulley_type" : beltType,
                                    "Teeth" : pulleyTwoTeeth,
                                    "size_mod" : definition.fitAdjustment,
                                    "Width" : definition.pulleyTwoWidth,
                                    "Bore" : definition.pulleyTwoBoreType,
                                    "Bore_Diameter" : definition.pulleyTwoBoreDiameter,
                                    "Flanged" : definition.pulleyTwoEnableFlange,
                                    "Flange_Width" : definition.pulleyTwoFlangeWidth,
                                    "Mate_Connectors" : false //set to true to add outer mate connectors to custom pulleys
                                },
                            "transform" : transform(toWorld(pulleyTwoCoords)),
                            "name" : "pulleytwo"
                        });
    Notably, omitting an argument from the configuration map simply causes the value of that configuration to become the default for the part studio. Similarly, additional configuration arguments which don't match the FeatureScript value of a configuration are ignored. The above process looks slightly different if using PartStudioData from a part studio reference parameter, but the core concepts are more or less the same.
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



  • MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
    edited August 2021
    The feature I'm working on instantiates a part with multiple configurations. When I would add configurations to one part while not to another part, I would get a "matrices are not the same size" error. Having these fake configurations allowed me to add configurations to one part while skipping the next part. 

    I will release the feature soon. You will be able to see what I'm talking about then.  B)

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    A couple things can help build this type of feature:

    1) When FeatureScript controls a specific configuration value, you can make that value unsettable by end users with the "ComputedConfigurationInputs" option.
    Place with length
    2) When using that option, the value passed in will always be the default value of that Part Studio configuration parameter at the time the feature was created. Its exact value can be accessed as e.g. definition.selectedPartStudio.Length

    3) When adding the instances, any number of configuration inputs can be overridden in the addInstance function with e.g.
    addInstance(instantiator, definition.partStudio, {
                "configurationOverride" : {
                    "Length" : computedLength
                }
            });
    You can make a single instance with a custom value, or make many instances with different custom values.

    @MichaelPascoe
    For your specific issue on map size, it seems very odd that such code would be necessary. What error are you seeing from the instantiator if instance maps are not the same size?
  • MichaelPascoeMichaelPascoe Member Posts: 1,953 PRO
    edited August 2021
    @kevin_o_toole_1
    This is valuable info. Thank you!

    The specific error I was getting: @matrixDifference: Matrices must be the same size.
    This error would happen if instances had different map sizes.

    For example, if customParameterDefinitions[0] was { "fillet" : 1 * inch} while customParameterDefinitions[1] was { "fillet" : 2 * inch, "chamfer : 1 * inch} the error would occur.

    Solution: Make each instantiation map the same size.
    //For instantiationos, each instantiations definition map must be the same size
            //Find the largest map
            var largestMap = 0;
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                if (size(customParameterDefinitions[i]) >= largestMap)
                {
                    largestMap = size(customParameterDefinitions[i]);
                }
            }
    
            //Add fake configurations to other maps until all maps are the same size
            for (var i = 0; i < size(customParameterDefinitions); i += 1)
            {
                var thisMap = size(customParameterDefinitions[i]);
    
                if (thisMap < largestMap)
                {
                    for (var k = 0; k < largestMap; k += 1)
                    {
                        if (size(customParameterDefinitions[i]) < largestMap)
                        {
                            customParameterDefinitions[i] = mergeMaps(customParameterDefinitions[i], { "Nothingness" ~ toString(k) : 0 * inch });
                        }
                    }
                }
            }
    
            for (var i = 0; i < size(instancePlanes); i += 1)
            {
                var configMap = {
                    "x" : newSizeX[i],
                    "y" : newSizeY[i],
                    "z" : newSizeZ[i] };
    
                //This code behaves the same as the following code, Thanks Alex!
                // for (var entry in customParameterDefinitions[i])
                // {
                //     var key = entry.key;
                //     var value = entry.value;
    
                //     configMap = mergeMaps(configMap, { entry.key : value });
                // }
    
                configMap = mergeMaps(configMap, customParameterDefinitions[i]);
    
                addInstance(instantiator, textureBody,
                    { "configuration" : configMap,
                            "transform" : transform[i]
                        });
            }
    
            instantiate(context, instantiator);


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Thanks for the additional info @MichaelPascoe, this makes sense now.

    This is definitely an issue in the instantiator where we could do better on our end. We've filed it as a bug internally and we'll update here if/when there is a fix. For now your workaround is good. Thanks for reporting!

Sign In or Register to comment.