Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Editing logic breaking reference to variables in array parameter?
 MichaelPascoe                
                
                    Member Posts: 2,619 PRO
MichaelPascoe                
                
                    Member Posts: 2,619 PRO                
            
                    Both of these custom features have array parameters: Texture & Freeform Spline. Input variables are lost when a new array item is added. Is there a way to fix this?
@Evan_Reese, you may be interested in the solution to this if there is one.

                
                @Evan_Reese, you may be interested in the solution to this if there is one.

Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
0    
            Best Answer
- 
             Alex_Kempen
                        
                        
                            Member Posts: 255 EDU                        
                    The value of sortXReturned (and sortYReturned and so on) should have no bearing on whether your variables are getting overridden. Rather, it's the statement definition.groups[g].sizeX = storeSizes.x that's tripping you up, since that's setting the value of definition.groups[g].sizeX to the saved value of definition.groups[g].sizeX, which doesn't include the necessary variable information, even if the values are technically the same. The solution, therefore, is only to override the variables when the override value is actually different from the input value: Alex_Kempen
                        
                        
                            Member Posts: 255 EDU                        
                    The value of sortXReturned (and sortYReturned and so on) should have no bearing on whether your variables are getting overridden. Rather, it's the statement definition.groups[g].sizeX = storeSizes.x that's tripping you up, since that's setting the value of definition.groups[g].sizeX to the saved value of definition.groups[g].sizeX, which doesn't include the necessary variable information, even if the values are technically the same. The solution, therefore, is only to override the variables when the override value is actually different from the input value:// if definition.groups[g].sizeX is already the correct value, leave it alone! // if storeSizes.x is zero and autoScale.x is different from definition.groups[g].sizeX: if (storeSizes.x == 0 && !tolerantEquals(definition.groups[g].sizeX, autoScale.x)) { definition.groups[g].sizeX = autoScale.x; } else if (!tolerantEquals(definition.groups[g].sizeX, storeSizes.x)) { definition.groups[g].sizeX = storeSizes.x; }Don't forget to repeat the following code for sizeY and sizeZ as well.Software Developer at Epic Systems
 FRC Design Mentor - Team 1306 BadgerBots2
Answers
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
To prevent this from happening, add conditions to shield parameters from being updated unless they actually need a new value:
if (!tolerantEquals(newValue, oldValue)) { // arrayParameter = newValue; }I suppose this behavior could actually be used desirably to selectively break variable references or move variables to an internal parameter. Of course, that's a very specific use case, but you never know.FRC Design Mentor - Team 1306 BadgerBots
Near line 3201 in the Texture feature:
if (!tolerantEquals(definition.groups[g].sizeX, oldDefinition.groups[g].sizeX)) { if (oldDefinition.groups[g].sizeX == .999 * inch || definition.groups[g].sortX == Sort.PLUS_Y) { if (storeSizes.x == 0) // if scale has not been used, use auto scale { definition.groups[g].sizeX = autoScale.x; } else // if scale has been used, use the last stored value { definition.groups[g].sizeX = storeSizes.x; } } }Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Also, as a more general note, using 0.999 * inch as the indicator for whether the feature has been scaled is low key not great. I would recommend using a hidden map to store that information instead - it should be more reliable and silent to the user.
FRC Design Mentor - Team 1306 BadgerBots
I don't care too much about the name of the config so I can simply delete code at line 3158. However, I do not want to get rid of the functionality from lines 3195 and 3206. I have tried placing them in an if statement so that they only return if something has changed, however if they return at all, they break the previous groups reference to the users variables.
Line 3158, name is changed in edit logic then returned to the hidden parameter above.
for (var g = 0; g < size(definition.groups); g += 1) { definition.groups[g].name = "Configuration" ~ " " ~ toString(g + 1); }Line 3195
if (oldDefinition.groups[g].sizeX == .999 * inch || definition.groups[g].sortX == Sort.PLUS_Y) { if (storeSizes.x == 0) // if scale has not been used, use auto scale { definition.groups[g].sizeX = autoScale.x; } else // if scale has been used, use the last stored value { definition.groups[g].sizeX = storeSizes.x; } }<br>Line 3206
if (oldDefinition.groups[g].sortX != definition.groups[g].sortX) { definition.groups[g].sortXReturned = definition.groups[g].sortX; }Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
// if definition.groups[g].sizeX is already the correct value, leave it alone! // if storeSizes.x is zero and autoScale.x is different from definition.groups[g].sizeX: if (storeSizes.x == 0 && !tolerantEquals(definition.groups[g].sizeX, autoScale.x)) { definition.groups[g].sizeX = autoScale.x; } else if (!tolerantEquals(definition.groups[g].sizeX, storeSizes.x)) { definition.groups[g].sizeX = storeSizes.x; }Don't forget to repeat the following code for sizeY and sizeZ as well.FRC Design Mentor - Team 1306 BadgerBots
Here is the code that seems to be working, I will need to tweak it some more:
if (storeSizes.x == 0 && !tolerantEquals(definition.groups[g].sizeX, autoScale.x)) { definition.groups[g].sizeX = autoScale.x; } else if (oldDefinition.groups[g].sizeX == .999 * inch && !tolerantEquals(definition.groups[g].sizeX, storeSizes.x)) { definition.groups[g].sizeX = storeSizes.x; }Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴