Exemple #1
0
        private void GetData(DrawingDoc swDraw)
        {
            // var swDraw = (DrawingDoc) swModel;

            //  var ModelDoc

            var getFirstView = (View)swDraw.GetFirstView();

            MessageBox.Show(getFirstView.ReferencedDocument.GetTitle());


            swDraw.ResolveOutOfDateLightWeightComponents();
            swDraw.ForceRebuild();

            // Движение по листам
            var vSheetName = (string[])swDraw.GetSheetNames();

            foreach (var name in vSheetName)
            {
                swDraw.ResolveOutOfDateLightWeightComponents();
                var swSheet = swDraw.Sheet[name];
                swDraw.ActivateSheet(swSheet.GetName());

                if ((!swSheet.IsLoaded()))
                {
                    continue;
                }

                var sheetviews1 = (object[])swSheet.GetViews();
                var firstView1  = (View)sheetviews1[0];
                var baseView1   = firstView1.IGetBaseView();
                var dispData1   = (IModelDoc2)baseView1.ReferencedDocument;
                MessageBox.Show(dispData1.GetTitle());

                try
                {
                    var sheetviews = (object[])swSheet.GetViews();
                    var firstView  = (View)sheetviews[0];
                    firstView.SetLightweightToResolved();

                    var baseView = firstView.IGetBaseView();
                    var dispData = (IModelDoc2)baseView.ReferencedDocument;

                    MessageBox.Show(dispData.GetTitle());
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
Exemple #2
0
        public string PdfLoad(string filepath, bool deep, string pathpdf)
        {
            try
            {
                SwModel = SolidWorksAdapter.SldWoksAppExemplare.OpenDoc6(filepath, (int)swDocumentTypes_e.swDocDRAWING,
                                                                         (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0);
                SwDraw = (DrawingDoc)SwModel;

                SwDraw.ResolveOutOfDateLightWeightComponents();
                SwDraw.ForceRebuild();

                var vSheetName = (string[])SwDraw.GetSheetNames();


                foreach (var name in vSheetName)
                {
                    if (name != null)
                    {
                        SwDraw.ResolveOutOfDateLightWeightComponents();
                        var swSheet = SwDraw.Sheet[name];

                        SwDraw.ActivateSheet(swSheet.GetName());

                        if ((swSheet.IsLoaded()))
                        {
                            var sheetviews = (object[])swSheet.GetViews();

                            if (sheetviews != null)
                            {
                                var firstView = (View)sheetviews[0];

                                firstView.SetLightweightToResolved();
                            }
                        }

                        if (!deep)
                        {
                            continue;
                        }
                        var views = (object[])swSheet.GetViews();

                        if (views != null)
                        {
                            foreach (var drwView in views.Cast <View>())
                            {
                                drwView.SetLightweightToResolved();
                            }
                        }
                    }
                }

                var errors   = 0;
                var warnings = 0;
                var newpath  = pathpdf + "\\" + Path.GetFileNameWithoutExtension(SwModel.GetPathName()) + ".pdf";
                //var newpath = Path.GetFullPath(SwModel.GetPathName().Replace("slddrw".ToUpper(), "pdf"));// + Path.GetFileNameWithoutExtension(SwModel.GetPathName()) + ".pdf";
                SwModel.Extension.SaveAs(newpath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings);
                SolidWorksAdapter.SldWoksAppExemplare.CloseDoc(Path.GetFileNameWithoutExtension(new FileInfo(newpath).FullName));
                //SolidWorksAdapter.KillProcsses("SLDWORKS");

                return(newpath);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }