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.
FeatureScript Editing Logic: Array Indices Not Updating Properly
Objectives:
I am working on a FeatureScript called "Base Array Numbering", which assigns an incremental index to each element of an array. The indices should always start from 1 and update automatically whenever the user adds or removes elements.
The feature uses:
Editing Logic Function
(showLogic
) to dynamically recalculate indices.- A
for
loop to iterate over the array and assign thearrayPointIndex
value.
My goal is to ensure:
- At the first execution, indices are correctly set as 1, 2, 3, ....
- When the user adds new elements, the indices continue sequentially.
- If elements are removed, the remaining items are renumbered starting from 1.
The Problem:
Currently, the code works only on the first launch. When I reopen the feature or add new elements:
- Some items receive incorrect indices (often 2 is repeated).
- The numbering logic does not update correctly in the user interface.
Debug Output:
When printing values inside the showLogic
function, I can see that indices are being recalculated. However, the interface does not reflect the correct values.
Question for the Community:
Why are the indices not updating properly in the user interface?
Is there something I am missing in my use of Editing Logic
and for
loops?
How can I ensure that the array indices are reassigned consistently when the feature is reopened or modified?
Any insights, corrections, or suggestions would be greatly appreciated. Thank you in advance for your help! 😊
https://cad.onshape.com/documents/ef57e2c5563e31fd6ab509b6/w/145b578f3abf4613a6c46697/e/0829cf8f973dd60a7caaa61e
Best Answers
-
Caden_Armstrong Member Posts: 195 PRO
I suggest reading the documentation on editing logic. Some useful stuff in there.
if the "isCreating" parameter is omitted, then the editing logic function only runs during creation.
www.smartbenchsoftware.com --- fs.place --- Renaissance
Custom FeatureScript and Onshape Integrated Applications1 -
mko_sc Member Posts: 27 PRO
Yes, Oliver, that’s exactly the goal!
Let me clarify further:Expected Behavior:
- Each item in the array should have a sequential index starting from 1.
- When an item is removed, the remaining items should be renumbered, maintaining the sequence.
- When a new item is added, it should receive the next available index, keeping the sequence intact.
For example:
Item A: Index 1
Item B: Index 2
Item C: Index 3______
After removing Item B:
Item A: Index 1
Item C: Index 2________
After adding Item D:
Item A: Index 1
Item C: Index 2
Item D: Index 3Current Issue:
- The
showLogic
function recalculates indices correctly only on the first execution. - If I reopen the feature or modify the array, the indices don’t update correctly. Sometimes, the indices repeat or don’t align with the expected sequence.
Do you have any suggestions on how I can reliably renumber the indices whenever the feature is reopened or modified?
Thank you for taking the time to look into this! 😊
0
Answers
To clarify, your goal is?
Becomes
Correct?
I suggest reading the documentation on editing logic. Some useful stuff in there.
https://cad.onshape.com/FsDoc/uispec.html
if the "isCreating" parameter is omitted, then the editing logic function only runs during creation.
Custom FeatureScript and Onshape Integrated Applications
Yes, Oliver, that’s exactly the goal!
Let me clarify further:
Expected Behavior:
For example:
Item A: Index 1
Item B: Index 2
Item C: Index 3
______
After removing Item B:
Item A: Index 1
Item C: Index 2
________
After adding Item D:
Item A: Index 1
Item C: Index 2
Item D: Index 3
Current Issue:
showLogic
function recalculates indices correctly only on the first execution.Do you have any suggestions on how I can reliably renumber the indices whenever the feature is reopened or modified?
Thank you for taking the time to look into this! 😊
it's the parameter "isCreating is boolean"
Thanks to allI 🙏
leave code for newbies.
"Basic structure for array numbering"