System Error working with assemblies

Hi Guys,

I've been working on a plugin for Solidwords for some time now and have figured out most of what I need to know (and some things I would rather not know..)

The purpose of the plugin is to drive a CNC machine (for wood)  based on process steps we define in Solidworks.  We also do assembly level work with it so we can resize/reconfigure our pseudo standard cabinet assemblies / subassemblies.

Here is where it gets tricky.  We have two routines we need to perform.  1) generate individual programs for each part. 2) generate nested programs that are many parts on sheets.

All parts are parametrically drive from the top down.

For option 1 we traverse the assemblies (in order) get the geometry we need, gen our programs and close the components as we go.  All good...

For option 2 we get the list of components and go at the parts that way. Each gets its configuration shown and we try to close the parts when we are done.  Some parts will be opened several times with different configurations.

For smaller assemblies under 100 parts, both work fine...

Larger assemblies approx.140+ starts giving problems and Solidworks/API start balking on file opens.....

2013-06-16T13:27:09: System.NullReferenceException: Object reference not set to an instance of an object.

   at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie)

   at SolidWorks.Interop.sldworks.DPartDocEvents_EventProvider.add_NewSelectionNotify(DPartDocEvents_NewSelectionNotifyEventHandler )

   at SolidWorks.Interop.sldworks.DPartDocEvents_Event.add_NewSelectionNotify(DPartDocEvents_NewSelectionNotifyEventHandler )

   at homagAddin.PartEventHandler.AttachEventHandlers()

   at homagAddin.SwAddin.AttachModelDocEventHandler(ModelDoc2 modDoc)

   at homagAddin.SwAddin.AttachEventsToAllDocuments()

   at homagAddin.SwAddin.SldWorks_FileOpenPostNotify(String FileName)

( we see this on attaching the newselectionnotify and the destroy notify )

Since we need all the part geometry (of all parts) to be able to nest the parts, we are no longer working in a 'in order traversal'.

We have tried the 2011 SP0 - regkey to release GDI at close etc.  No help...

Does anyone have any ideas ???

SolidworksApi macros