0 Replies Latest reply on Aug 19, 2013 6:31 PM by Anshul Pandeys

    View components issues

    Anshul Pandeys

      All,

      I am a tyring again as my original question went unanswered.

       

      I am looking for some pointers on following 2 line items.

       

      1. ) There are times when I had a working view – (view is shown in drawing, can select it and other operations can be done.) but on querying view.getvisibleComponents will return null.

       

      1. ) Can you help me understand under how does a view goes from valid to invalid state. ? There are times when the  I do checks like following but the line highlighted in yellow still throws an exception.

       

              

                     Object[] vDrawChildCompArr2 = GetComponentsInView(ref model, viewName); // get the drawing docs in the document.see call below.

                        foreach (var c1 in vDrawChildCompArr2)

                      {

                          Component2 comp2 =null;

                          DrawingComponent comp = c1 as DrawingComponent;

                          if (comp is DrawingComponent)

                          {

                              comp2 = comp.Component;

                              if (comp2 != null)

                              {

                                  String compName = comp2.Name2;

                                  sb2.AppendLine(compName );

                              }

                          }

                          else if (c1 is Component2)

                          {

                              String compName  = (c1 as Component2).Name2;

                              sb2.AppendLine(compName );

                          }

                      }

       

       

      public static object[] GetComponentsInView(ref ModelDoc2 swModel, string viewName)

                          {

                                    try

                                    {

                                              SolidWorks.Interop.sldworks.View swView = GetActivatedView(ref swModel, viewName);

                                              DrawingComponent swRootDrawComp = (DrawingComponent)swView.RootDrawingComponent;

                                              object[] vDrawChildCompArr = (object[])swRootDrawComp.GetChildren();

                                              swModel.ClearSelection2(true);

                                              return vDrawChildCompArr;

                                    }

                                    catch (System.Exception ex)

                                    {

                                              throw ex;

                                    }

       

                          }