Author Topic: CTD when enumerating a list of AcSmSheet  (Read 262 times)

0 Members and 1 Guest are viewing this topic.


  • Mosquito
  • Posts: 2
CTD when enumerating a list of AcSmSheet
« on: January 13, 2021, 10:40:42 AM »
Hi all. As the subject states I am experiencing a crash to desktop (AutoCad) when enumerating a list of AcSmSheet I have constructed. By CTD I mean it even skips the fatal error dialog box. I'm trying to understand the behavior because it is very strange to me and I've been trying to determine the source of the problem for months to no avail. I apologize if my explanation is long, but I hope more information will help us solve the problem.

I have a form that allows the user to select a desired sheet set file and manage the task to be ran on the drawings. It iterates through and collects AcSmSheets, IAcSmSheets2, and extracts file paths, revision data, file names, layout names, and stores them all in their own lists. I can enumerate through the list of AcSmSheets while in the form and list all of the filepaths using
Code: [Select]
foreach (AcSmSheet sh in SheetSet.smSheets)
     string path = sh.GetLayout().GetFileName();
     if (!string.IsNullOrEmpty(path))
          label1.Text += path + "\n";
          checkedListBox1.Items.Add((object)path, true);
          //OpenDoc(path); //alternatively, run these methods
This works as expected and it returns the file paths properly. Great. Now I'm lead to (falsely) believe that my code should work properly.

In another class, I want to take that same data and iterate over it, opening each dwg from the file paths to run some task and save and close.
I will use the same code, outside the form, and it will not work. It will enter the foreach loop, get the first path, open, do the task, save and close, move on to the next enumerable, and crash to desktop at the "string path = sh.GetLayout().GetFileName();" line. In one instance it properly gets all of the file paths. In the other instance, it only gets the first one.

My understanding is that autocad will CTD when it tries to evaluate something that is null. I was wondering if the data was being thrown away after the first .dwg is opened, but it is not. I am using CommandFlags.Session, and have found an alternative way to make the code work, but it is not ideal. It works if I use the same code but with
Code: [Select]
foreach (string path in SheetSet.pathList)
But this only allows me to enumerate the path, when I want to work on more than just the path (revision data, layout information).

So the data is not being cleared with the document open. What is making the AcSmSheet go to null, if it is?

Thanks in advance to any responses.