Solved! Go to solution

Iterating through sheets sometimes fails

In the AddIn I'm working on, I'm trying to iterate through all sheets of type workingSection and run a command on each sheet. Here is part of the code:


 for (int sheetCounter = document.ActiveSheet.Index + 1; sheetCounter <= document.Sheets.Count; sheetCounter++)
var sheet = document.Sheets.Item(sheetCounter) as SolidEdgeDraft.Sheet;
if (sheet.SectionType == SolidEdgeDraft.SheetSectionTypeConstants.igWorkingSection)
//Enter scale modification mode

Accepted by topic author freijon
‎08-26-2015 04:32 AM

Re: Iterating through sheets sometimes fails

A couple of things.

  • Your "break;" statement will exit the for loop so you're only processing the 1st sheet.
  • StartCommand() is an asynchronous operation. Your code will make the call and continue to execute.

Not sure what you're trying to accomplish but this approach will never work. If you're needing to alter the scale for each sheet then you will have to code it yourself. If it's kind of a batch operation, you will need to present the user with a modal dialog with options to alter the scale for each sheet.

Jason Newell
Applications Architect

Re: Iterating through sheets sometimes fails

[ Edited ]

Hi Jason,


I'm sorry, I didn't mean to send this post. I didn't even formulate a question.


Just FYI, the problem was not the break statement or the asynchronous StartCommand(), it was a method I called after my code snippet which always switched to the first sheet (had it there for test purposes and forgot about it) and that prevented what I tried to accomplish.


BTW, semi-automatically changing the scale for every sheet now works as intended. After our background sheet change tool, the user is now "forced" to set a scale for each sheet. In our old background sheets the scale was only a textfield and not connected to a drawing view.


Sorry again, I thought I discarded this post. Thanks anyway for your help!




Re: Iterating through sheets sometimes fails

Just goes to show how good Jason is - he can answer questions you didn't even realise you'd asked Smiley Very Happy

HP Z420 16GB RAM
Quadro K4000
ST7 MP10 on Windows 7 Pro 64.