public void CheckDrawingDoc() { try { _swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); _swModel = _swApp.ActiveDoc; _swDraw = (DrawingDoc)_swModel; // Получение первого листа _swSheet = _swDraw.GetCurrentSheet(); StrActiveSheetName = _swSheet.GetName(); // Узнаем имя активного листа _vSheetNames = _swDraw.GetSheetNames(); _swDraw.ActivateSheet(_vSheetNames[0]); _swSheet = _swDraw.GetCurrentSheet(); _swView = _swDraw.GetFirstView(); if (_swSheet.CustomPropertyView == "По умолчанию" | _swSheet.CustomPropertyView == "Default") { _swView = _swView.GetNextView(); } _swModel = _swView.ReferencedDocument; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void InsertBOM(SldWorks swApp) { ModelDoc2 md = (ModelDoc2)swApp.ActiveDoc; DrawingDoc dd = (DrawingDoc)swApp.ActiveDoc; ModelDocExtension ex = (ModelDocExtension)md.Extension; int bom_type = (int)swBomType_e.swBomType_PartsOnly; int bom_numbering = (int)swNumberingType_e.swNumberingType_Flat; int bom_anchor = (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft; SolidWorks.Interop.sldworks.View v = GetFirstView(swApp); BomTableAnnotation bta = null; TableAnnotation ta = null; if (dd.ActivateView(v.Name)) { bta = v.InsertBomTable4( false, Properties.Settings.Default.BOMLocationX, Properties.Settings.Default.BOMLocationY, bom_anchor, bom_type, v.ReferencedConfiguration, Properties.Settings.Default.BOMTemplatePath, false, bom_numbering, false); } if (bta != null) { ta = (TableAnnotation)bta; if (ta != null) { int deptcol = 0; List <int> rowdpt = new List <int>(); System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(BOMFilter[0]); for (int i = 0; i < ta.ColumnCount; i++) { if (ta.Text[0, i].ToUpper() == @"DEPTID") { deptcol = i; break; } } for (int i = 0; i < ta.RowCount; i++) { if (!r.IsMatch(ta.Text[i, deptcol])) { rowdpt.Add(i); } } foreach (int item in rowdpt) { ta.set_RowHidden(item, true); } } } }
public static void createSWDrawing(bool createDrawBool) { swApp = SolidWorksSingleton.swApp; string pthTemplateFolder = GUI.pthProjFolder + "\\" + "Ξ_SolidWorks Standard Library" + "\\" + "Templates" + "\\" + "RTPi DRW.DRWDOT"; pthPartAssytoOpen = GUI.pthProjFolder + "\\" + GUI.GUIProj + "\\" + GUI.PartAssySolidWorkstoOpen; //if drawing exist open it, otherwise create the drawing. if (createDrawBool == false) { swApp.OpenDoc6(GUI.pthDrwtoOpen, 3, 256, "", 0, 0); } else { //create a drawing swModel = (ModelDoc2)swApp.NewDocument(pthTemplateFolder, 0, 0, 0); //activate drawing swDraw = (DrawingDoc)swModel; createPartNumber(3); //save the part under a specific number swModel.SaveAs(saveName); } }
public void Main() { if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { using (Redbrick_Addin.CutlistData cd = new Redbrick_Addin.CutlistData(Properties.Settings.Default.ConnectionString)) { try { cd.IncrementOdometer(Redbrick_Addin.CutlistData.Functions.DrawingCollector); } catch (Exception) { //ignore } } } di = Path.GetDirectoryName((swApp.ActiveDoc as ModelDoc2).GetPathName()); DrawingData d = new DrawingData(di); pc = new PDFCollector(swApp, Properties.Settings.Default.TableHashes, d); using (m = new Message()) { Message.click_go += new Message.click_EventHandler(Message_click_go); Message.click_close += new Message.close_EventHandler(Message_click_close); DrawingDoc p = (DrawingDoc)swApp.ActiveDoc; m.ShowDialog(); } //System.Runtime.InteropServices.Marshal.ReleaseComObject(p); //System.Runtime.InteropServices.Marshal.ReleaseComObject(swApp); }
public Thumbnailer(SldWorks sw) { swApp = sw; APathSet.ShtFmtPath = @"\\AMSTORE-SVR-22\cad\Solid Works\AMSTORE_SHEET_FORMATS\zPostCard.slddrt"; swFrame = (Frame)swApp.Frame(); swModel = (ModelDoc2)swApp.ActiveDoc; swDraw = (DrawingDoc)swModel; if (swApp == null) { throw new ThumbnailerException("I know you gave me the SW Application Object, but I dropped it somewhere."); } if (swDraw == null) { throw new ThumbnailerException("You must having a drawing document open."); } swView = GetFirstView(swApp); sourcePath = swView.GetReferencedModelName().ToUpper().Trim(); if (!sourcePath.Contains("SLDASM")) { assmbly = false; } drawingPath = swModel.GetPathName().ToUpper().Trim(); }
protected override void UnsubscribeDrawingEvents(DrawingDoc draw) { draw.LoadFromStorageNotify -= OnLoadFromStorageNotify; draw.LoadFromStorageStoreNotify -= OnLoadFromStorageStoreNotify; draw.SaveToStorageStoreNotify -= OnSaveToStorageStoreNotify; draw.SaveToStorageNotify -= OnSaveToStorageNotify; }
public Thumbnailer(SldWorks sw, ArchivePDF.csproj.PathSet ps) { swApp = sw; APathSet = ps; swFrame = (Frame)swApp.Frame(); swModel = (ModelDoc2)swApp.ActiveDoc; swDraw = (DrawingDoc)swModel; if (swApp == null) { throw new ThumbnailerException("I know you gave me the SW Application Object, but I dropped it somewhere."); } if (swDraw == null) { throw new ThumbnailerException("You must having a drawing document open."); } swView = GetFirstView(swApp); sourcePath = swView.GetReferencedModelName().ToUpper().Trim(); if (!sourcePath.Contains("SLDASM")) { assmbly = false; } drawingPath = swModel.GetPathName().ToUpper().Trim(); }
public static void GetDocObject(SldWorks iswApp) { StringBuilder sb = new StringBuilder(""); ModelDoc2 SwDoc = iswApp.ActiveDoc;//获得当前激活的文档 sb.Append("文档:" + SwDoc.GetTitle() + "\r\n"); int DocType = SwDoc.GetType(); //获得激活的文档类型 if (DocType == (int)swDocumentTypes_e.swDocPART) //若类型是零件 { PartDoc SwPart = (PartDoc)SwDoc; sb.Append("文档类型:零部件\r\n"); } else if (DocType == (int)swDocumentTypes_e.swDocASSEMBLY)//若类型是装配体 { AssemblyDoc SwAssem = (AssemblyDoc)SwDoc; sb.Append("文档类型:装配体\r\n"); } else if (DocType == (int)swDocumentTypes_e.swDocDRAWING)//若类型是工程图 { DrawingDoc SwAssem = (DrawingDoc)SwDoc; sb.Append("文档类型:工程图\r\n"); } ModelDocExtension SwDocEx = SwDoc.Extension;//获得扩展文档对象 if (SwDocEx != null) { sb.Append("扩展文档:已获得"); } MessageBox.Show(sb.ToString().Trim()); }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Invoke(new MethodInvoker(() => { if (templateDrawing != null) { sldWorks.CloseDoc(((ModelDoc2)templateDrawing).GetTitle()); templateDrawing = null; } activeDocTitleBox.Enabled = true; prefixTextBox.Enabled = true; comboBox1.Enabled = true; button1.Image = Properties.Resources.play; button1.Enabled = true; })); var duration = DateTime.Now - timeStarted; Print("Run time: " + duration.ToReadableFormat()); Print("Done.", Color.Green); sldWorks.ActiveModelDocChangeNotify += SldWorks_ActiveModelDocChangeNotify; }
protected override void UnsubscribeDrawingEvents(DrawingDoc draw) { draw.AddItemNotify -= OnAddItemNotify; draw.DeleteItemNotify -= OnDeleteItemNotify; draw.DeleteItemPreNotify -= OnDeleteItemPreNotify; draw.RenameItemNotify -= OnRenameItemNotify; }
private DrawingDoc CreerPlan(String materiau, Double epaisseur, Boolean mettreAJourExistant) { String Fichier = NomFichierPlan(materiau, epaisseur); if (DicDessins.ContainsKey(Fichier)) { return(DicDessins[Fichier]); } DrawingDoc Dessin = null; ModelDoc2 Mdl = null; if (mettreAJourExistant) { Mdl = Sw.eOuvrir(Path.Combine(DossierDVP, Fichier), eTypeDoc.Dessin); } if (Mdl.IsNull()) { Dessin = Sw.eCreerDocument(DossierDVP, Fichier, eTypeDoc.Dessin, CONSTANTES.MODELE_DE_DESSIN_LASER).eDrawingDoc(); } else { Dessin = Mdl.eDrawingDoc(); return(Dessin); } Dessin.eFeuilleActive().SetName(Fichier); DicDessins.Add(Fichier, Dessin); Dessin.eModelDoc2().pAppliquerOptionsDessinLaser(AfficherNotePliage, TailleInscription); return(Dessin); }
public View GetFirstView(SldWorks sw) { ModelDoc2 swModel = (ModelDoc2)sw.ActiveDoc; View v; DrawingDoc d = (DrawingDoc)swModel; string[] shtNames = (String[])swDraw.GetSheetNames(); string message = string.Empty; //This should find the first page with something on it. int x = 0; do { try { d.ActivateSheet(shtNames[x]); } catch (IndexOutOfRangeException e) { throw new IndexOutOfRangeException("Went beyond the number of sheets.", e); } catch (Exception e) { throw e; } v = (View)d.GetFirstView(); v = (View)v.GetNextView(); x++; } while ((v == null) && (x < d.GetSheetCount())); message = (string)v.GetName2() + ":\n"; if (v == null) { throw new Exception("I couldn't find a model anywhere in this document."); } return(v); }
protected override void UnsubscribeDrawingEvents(DrawingDoc draw) { draw.ClearSelectionsNotify -= OnClearSelectionsNotify; draw.NewSelectionNotify -= OnNewSelectionNotify; draw.UserSelectionPreNotify -= OnUserSelectionPreNotify; draw.UserSelectionPostNotify -= OnUserSelectionPostNotify; }
public PageInsererNote() { try { LigneAttache = _Config.AjouterParam("LigneAttache", true, "Ligne d'attache"); ModifierHtTexte = _Config.AjouterParam("ModifierHtTexte", true, "Modifier la ht du texte"); HtTexte = _Config.AjouterParam("HtTexte", 7, "Ht du texte en mm", "Ht du texte en mm"); Reperage = _Config.AjouterParam("Reperage", true, "Reperage"); AfficherQuantite = _Config.AjouterParam("AfficherQuantite", true, "Ajouter la quantité"); Description = _Config.AjouterParam("Description", true, "Description"); PrefixeTole = _Config.AjouterParam("PrefixeTole", true, "Prefixe tole"); AjouterMateriau = _Config.AjouterParam("AjouterMateriau", true, "Ajouter le matériau"); ProfilCourt = _Config.AjouterParam("ProfilCourt", true, "Nom de profil court"); SautDeLigneMateriau = _Config.AjouterParam("SautDeLigneMateriau", false, "Saut de ligne matériau"); Dessin = MdlBase.eDrawingDoc(); Mt = (MathUtility)App.Sw.GetMathUtility(); ListeCorps = MdlBase.pChargerNomenclature(); InitSouris(); OnCalque += Calque; OnRunAfterClose += RunAfterClose; } catch (Exception e) { this.LogMethode(new Object[] { e }); } }
public void Deconnecter() { ReinitialiserFeuille(); EnleverEvenement(); MdlActif = null; DessinActif = null; }
private void ExportToDXF(DrawingDoc drawing) { Print("Finding BOM tables..."); var bomTables = drawing.GetBomTables(); if (bomTables.Count == 0) { Print("Error: Bill of materials not found.", Color.Red); return; } Print($"Found {bomTables.Count} BOM table(s)\n"); var items = new List <Item>(); foreach (var bom in bomTables) { if (worker.CancellationPending) { return; } var itemExtractor = new BomItemExtractor(bom); itemExtractor.SkipHiddenRows = true; Print($"Fetching components from {bom.BomFeature.Name}"); var bomItems = itemExtractor.GetItems(); items.AddRange(bomItems); } Print($"Found {items.Count} component(s)"); ExportToDXF(items); }
public void hidebomtable() { SldWorks swApp = default(SldWorks); ModelDoc2 swModel = default(ModelDoc2); DrawingDoc swDraw = default(DrawingDoc); SolidWorks.Interop.sldworks.View swView = default(SolidWorks.Interop.sldworks.View); TableAnnotation swTableAnn = default(TableAnnotation); Annotation swAnn = default(Annotation); object[] vTableAnns = null; int i = 0; //swApp = CreateObject("SldWorks.Application") swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swModel = swApp.ActiveDoc; swDraw = (DrawingDoc)swModel; swView = swDraw.GetFirstView(); vTableAnns = swView.GetTableAnnotations(); //vTableAnns.Length if ((vTableAnns == null) == false) { for (i = 0; i <= vTableAnns.Length - 1; i++) { swTableAnn = (TableAnnotation)vTableAnns[i]; if (swTableAnn.Type == (int)swTableAnnotationType_e.swTableAnnotation_BillOfMaterials) { //swTableAnn.MoveColumn(0, swTableItemInsertPosition_e.swTableItemInsertPosition_After, 1) swAnn = swTableAnn.GetAnnotation(); swAnn.Select3(false, null); swApp.RunCommand((int)swCommands_e.swCommands_Hide_Table, null); } } } }
public void InsertBom() { SldWorks swApp = default(SldWorks); ModelDoc2 swModel = default(ModelDoc2); SelectionMgr swSelMgr = default(SelectionMgr); FeatureManager swFeatMgr = default(FeatureManager); SolidWorks.Interop.sldworks.View swView; BomTableAnnotation swBomAnn = default(BomTableAnnotation); BomFeature swBomFeat = default(BomFeature); long anchorType = 0; long bomType = 0; string configuration = null; string tableTemplate = null; object visible = null; DrawingDoc swDraw; Sheet swSheet = default(Sheet); //swApp = DirectCast(Marshal.GetActiveObject("SldWorks.Application"), SldWorks) swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swModel = swApp.ActiveDoc; swFeatMgr = swModel.FeatureManager; swDraw = (DrawingDoc)swModel; swSheet = swDraw.GetCurrentSheet(); swModel.Extension.SetUserPreferenceString((int)swUserPreferenceStringValue_e.swDetailingLayer, (int)swUserPreferenceOption_e.swDetailingBillOfMaterial, ""); //ecли FALSE вставляются все конфигурации swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, 0, false); swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swBomTableDontAddQTYNextToConfigName, 0, true); swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swDontCopyQTYColumnNameFromTemplate, 0, true); //swDraw.SetUserPreferenceIntegerValue(swBomTableZeroQuantityDisplay, swZeroQuantityBlank); //Select View swModel.ClearSelection2(true); swView = swDraw.GetCurrentSheet().GetViews()[0]; //Insert BOM Table anchorType = (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft; bomType = (int)swBomType_e.swBomType_TopLevelOnly; swModel.ClearSelection2(true); configuration = ""; tableTemplate = "C:\\Program Files\\SW-Complex\\Template.sldbomtbt"; swBomAnn = swView.InsertBomTable2(false, -0, -0, (int)anchorType, (int)bomType, configuration, tableTemplate); swFeatMgr.UpdateFeatureTree(); swBomFeat = swBomAnn.BomFeature; var Names = swBomFeat.GetConfigurations(false, visible); visible = true; swBomFeat.SetConfigurations(true, visible, Names); }
protected override void UnsubscribeDrawingEvents(DrawingDoc draw) { draw.AutoSaveNotify -= OnAutoSaveNotify; draw.FileSaveAsNotify2 -= OnFileSaveAsNotify2; draw.FileSaveNotify -= OnFileSaveNotify; draw.FileSavePostCancelNotify -= OnFileSavePostCancelNotify; draw.FileSavePostNotify -= OnFileSavePostNotify; }
/// <summary> /// Updates the TreeView when a LVL is added. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void t_Added(object sender, EventArgs e) { DrawingDoc thisdd = (DrawingDoc)SwApp.ActiveDoc; Write(thisdd); t(); DrbUpdate(); }
public double[] GetSheetSize(DrawingDoc d) { Sheet sht = (Sheet)d.GetCurrentSheet(); double[] sp = (double[])sht.GetProperties(); double[] s_size = { sp[5], sp[6] }; return(s_size); }
public int CloseDoc(String nomFichier, int raison) { ReinitialiserFeuille(); EnleverEvenement(); MdlActif = null; DessinActif = null; return(1); }
protected override void SubscribeDrawingEvents(DrawingDoc draw) { draw.LoadFromStorageNotify += OnLoadFromStorageNotify; draw.LoadFromStorageStoreNotify += OnLoadFromStorageStoreNotify; draw.SaveToStorageStoreNotify += OnSaveToStorageStoreNotify; draw.SaveToStorageNotify += OnSaveToStorageNotify; SubscribeIdleEvent(); }
private string GetSheetFormat(ModelDoc2 m) { DrawingDoc d = (DrawingDoc)m; string[] sht_names = (string[])d.GetSheetNames(); Sheet s = d.get_Sheet(sht_names[0]); return(s.GetTemplateName()); }
private DrawingDoc CreerPlan(String materiau, Double epaisseur) { String Fichier = String.Format("{0}{1} - Ep{2}", String.IsNullOrWhiteSpace(RefFichier) ? "" : RefFichier + " - ", materiau.eGetSafeFilename("-"), epaisseur.ToString().Replace('.', ',') ).Trim(); if (DicDessins.ContainsKey(Fichier)) { return(DicDessins[Fichier]); } if (MajPlans) { var di = new DirectoryInfo(DossierDVP); var NomFichierExt = Fichier + eTypeDoc.Dessin.GetEnumInfo <ExtFichier>(); var r = di.GetFiles(NomFichierExt, SearchOption.TopDirectoryOnly); if (r.Length > 0) { int Erreur = 0, Warning = 0; DrawingDoc dessin = App.Sw.OpenDoc6(Path.Combine(DossierDVP, NomFichierExt), (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Erreur, ref Warning).eDrawingDoc(); DicDessins.Add(Fichier, dessin); return(dessin); } } DrawingDoc Dessin = Sw.eCreerDocument(DossierDVP, Fichier, eTypeDoc.Dessin, CONSTANTES.MODELE_DE_DESSIN_LASER).eDrawingDoc(); Dessin.eFeuilleActive().SetName(Fichier); DicDessins.Add(Fichier, Dessin); ModelDoc2 mdl = Dessin.eModelDoc2(); LayerMgr LM = mdl.GetLayerManager(); LM.AddLayer("GRAVURE", "", 1227327, (int)swLineStyles_e.swLineCONTINUOUS, (int)swLineWeights_e.swLW_LAYER); LM.AddLayer("QUANTITE", "", 1227327, (int)swLineStyles_e.swLineCONTINUOUS, (int)swLineWeights_e.swLW_LAYER); ModelDocExtension ext = mdl.Extension; ext.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swFlatPatternOpt_ShowFixedFace, 0, false); ext.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swShowSheetMetalBendNotes, (int)swUserPreferenceOption_e.swDetailingNoOptionSpecified, AfficherNotePliage); TextFormat tf = ext.GetUserPreferenceTextFormat(((int)(swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat)), 0); tf.CharHeight = TailleInscription / 1000.0; ext.SetUserPreferenceTextFormat((int)swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat, 0, tf); return(Dessin); }
protected override void UnsubscribeDrawingEvents(DrawingDoc draw) { if (m_DocHandler.App.IsVersionNewerOrEqual(SwVersion_e.Sw2013)) { draw.ActivateSheetPreNotify -= OnActivateSheetPreNotify; } draw.ActivateSheetPostNotify -= OnActivateSheetPostNotify; }
public static List <BomTableAnnotation> GetBomTables(this DrawingDoc drawing) { var model = drawing as ModelDoc2; return(model.GetAllFeaturesByTypeName("BomFeat") .Select(f => f.GetSpecificFeature2() as BomFeature) .Select(f => (f.GetTableAnnotations() as Array)?.Cast <BomTableAnnotation>().FirstOrDefault()) .ToList()); }
/// <summary> /// 只生成等轴测视图 /// </summary> /// <param name="swDraw"></param> /// <param name="fileName"></param> private void CreatIsometric(DrawingDoc swDraw, string fileName) { double[] outLine = new double[4]; Sheet currentSheets = (Sheet)__swDrawDoc.GetCurrentSheet(); __swDrawDoc.ActivateSheet(currentSheets.GetName()); _swView = (IView)swDraw.GetFirstView(); outLine = (double[])_swView.GetOutline();//获取图纸边界 _swView = (IView)swDraw.CreateDrawViewFromModelView3(fileName, "*等轴测", (outLine[2] - outLine[0]) / 2.0, (outLine[3] - outLine[1]) / 1.5, 0); }
private void _setupSW() { swFrame = (Frame)swApp.Frame(); swModel = (ModelDoc2)swApp.ActiveDoc; swDraw = (DrawingDoc)swModel; if (swDraw == null) { throw new GaugeSetterException("You must have a Drawing Document open."); } }
/// <summary> /// Execute a function on each page. /// </summary> /// <param name="f">Layer choosing function.</param> public void CorrectLayers(selectLayer f) { DrawingDoc d = (DrawingDoc)PropertySet.SwApp.ActiveDoc; Sheet curSht = (Sheet)d.GetCurrentSheet(); string[] shts = (string[])d.GetSheetNames(); foreach (string s in shts) { f(); } d.ActivateSheet(curSht.GetName()); }
public DrawingEventHandler(ModelDoc2 modDoc, SwAddin addin) : base(modDoc, addin) { doc = (DrawingDoc)document; }
/// <summary> /// Méthode interne. /// Initialiser l'objet eDessin. /// </summary> /// <param name="Modele"></param> /// <returns></returns> internal Boolean Init(eModele Modele) { Log.Methode(cNOMCLASSE); if ((Modele != null) && Modele.EstInitialise && (Modele.TypeDuModele == TypeFichier_e.cDessin)) { Log.Message(Modele.FichierSw.Chemin); _Modele = Modele; _SwDessin = Modele.SwModele as DrawingDoc; _EstInitialise = true; _Modele.SwModele.Extension.UsePageSetup = (int)swPageSetupInUse_e.swPageSetupInUse_DrawingSheet; } else { Log.Message("\t !!!!! Erreur d'initialisation"); } return _EstInitialise; }
/// <summary> /// Write properties to drawing document. /// </summary> /// <param name="doc">The current DrawingDoc object.</param> public void Write(DrawingDoc doc) { if (!check_itemnumber()) { string itnu = label4.Text; string cuss = cbCustomer.Text.Split(' ')[0]; PropertySet.SwApp.SendMsgToUser2( string.Format("The item number '{0}' possibly doesn't match the customer '{1}'.", itnu, cuss), (int)swMessageBoxIcon_e.swMbWarning, (int)swMessageBoxResult_e.swMbHitOk); } this.PropertySet.ReadControls(); this.PropertySet.Write(this.SwApp); this.RevSet.Write(this.SwApp); (doc).ForceRebuild(); this.dirtTracker = null; }
private static void SheetNumering(ModelDoc2 swModel, DrawingDoc swDraw) { int shi = 0; var swSheetNames = (string[])swDraw.GetSheetNames(); foreach (var swSheetName in swSheetNames) { if (shi == 1) { swDraw.ActivateSheet(swSheetName); AddTextBlock(swModel, swDraw, "Лист 1 из 2", 0.26, 0.2, 0, 0.004, 0); } else { if (shi == 2) { swDraw.ActivateSheet(swSheetName); AddTextBlock(swModel, swDraw, "Лист 2 из 2", 0.26, 0.2, 0, 0.004, 0); } } shi++; } }
public DisplayDimension GetDisplayDim(DrawingDoc swDrawing, Entity ent, SelectData swSelData) { ent.Select4(true, swSelData); return (DisplayDimension)swDrawing.AddHoleCallout2(0, 0, 0); }
private static void AddTextBlock(ModelDoc2 swModel, DrawingDoc swDraw, string txt, double tX, double tY, double tZ, double tHeight, double tAngle,MathPoint mp,bool needToExplode) { swModel.SetAddToDB(true); swDraw.ICreateText2(txt, tX, tY, tZ, tHeight, tAngle); swModel.Extension.SelectByID2("", "NOTE", tX, tY, tZ, true, 0, null, 0); //if (!needToExplode) swModel.SketchManager.MakeSketchBlockFromSelected(mp); swModel.SetAddToDB(false); swModel.ClearUndoList(); }
private static void AddTextBlock(ModelDoc2 swModel, DrawingDoc swDraw, string txt, double tX, double tY, double tZ, double tHeight, double tAngle) { AddTextBlock(swModel, swDraw, txt, tX, tY, tZ, tHeight, tAngle, null,false); }
private void ReplaceViews(object[] swViews,DrawingDoc swDrawing) { Sheet currentSheet = swDrawing.GetCurrentSheet(); double width = 0, height = 0; currentSheet.GetSize(ref width, ref height); double halfx = width / 2; double halfy = height / 2; Dictionary<string, double[]> boxes = new Dictionary<string, double[]>(); foreach (View t in swViews) { var swView = (View)t; const string expr = "^F[1-6]$"; Match isMatch = Regex.Match(swView.Name, expr, RegexOptions.IgnoreCase); if (!isMatch.Success) continue; double[] bBox = swView.GetOutline(); boxes.Add(swView.Name, bBox); } if (!boxes.ContainsKey("F1")) { return; } foreach (View t in swViews) { var swView = (View)t; if (swView.GetName2().Contains("F2")) { swView.Position = new double[] { boxes["F1"][0]/2 , 0 };//{ boxes["F1"][0] - ((boxes["F1"][2] - boxes["F1"][0]) / 2), 0 };//{ boxes["F1"][0]/2, halfy - Math.Abs(deltay) };//{ boxes["F1"][0] - ((boxes["F1"][2] - boxes["F1"][0]) / 2), halfy - Math.Abs(deltay) }; } if (swView.GetName2().Contains("F3")) { swView.Position = new double[] { boxes["F1"][2] + ((width - boxes["F1"][2]) / 2), 0 };//{ boxes["F1"][2] + ((boxes["F1"][2] - boxes["F1"][0]) / 2), 0 }; } if (swView.GetName2().Contains("F4")) { swView.Position = new double[] { 0, boxes["F1"][3] + ((height - boxes["F1"][3]) / 2) };//{ 0, boxes["F1"][3] + ((boxes["F1"][3] - boxes["F1"][1]) / 2) };//{ halfx, boxes["F1"][3] + ((height - boxes["F1"][3]) / 2) - Math.Abs(deltay) };//{ halfx, boxes["F1"][3] + ((boxes["F1"][3] - boxes["F1"][1]) / 2) - Math.Abs(deltay) }; } if (swView.GetName2().Contains("F5")) { swView.Position = new double[] { 0, boxes["F1"][1]/ 2 };//{ 0, boxes["F1"][1] - ((boxes["F1"][3] - boxes["F1"][1]) / 2) };//{ halfx, boxes["F1"][1] - ((boxes["F1"][1]) / 2) - Math.Abs(deltay) };//{ halfx, boxes["F1"][1] - ((boxes["F1"][3] - boxes["F1"][1]) / 2) - Math.Abs(deltay) }; } } }
private void LegendMaker(ModelDoc2 swModel, DrawingDoc swDraw, IEnumerable<string> type, double vScaleRatio) { foreach (var t in type) { using (var a = new GetDimensions()) { MathPoint instancePosition; if (t.Contains("8h") && t.StartsWith("8h")) { a.CreateBlock(_swApp, 2, out instancePosition, 1.45 / 15 * vScaleRatio, 0.134 / 15 * vScaleRatio); AddTextBlock(swModel, swDraw, "- отв." + "<MOD-DIAM>" + "8 несквозные", 0.1, 0.011, 0, 0.0025, 0, instancePosition,true); } if (t == "5h12") { a.CreateBlock(_swApp, 1, out instancePosition, 0.36 / 15 * vScaleRatio, 0.134 / 15 * vScaleRatio); AddTextBlock(swModel, swDraw, "- отв." + "<MOD-DIAM>" + "5h12", 0.027, 0.011, 0, 0.0025, 0, instancePosition,true); } if (t == "8") { a.CreateBlock(_swApp, 3, out instancePosition, 2.09 / 15 * vScaleRatio, 0.134 / 15 * vScaleRatio); AddTextBlock(swModel, swDraw, "- отв." + "<MOD-DIAM>" + "8 сквозные", 0.142, 0.011, 0, 0.0025, 0, instancePosition,true); } if (t == "5") { a.CreateBlock(_swApp, 0, out instancePosition, 0.85 / 15 * vScaleRatio, 0.134 / 15 * vScaleRatio); AddTextBlock(swModel, swDraw, "- отв." + "<MOD-DIAM>" + "5" + " сквозные", 0.06, 0.011, 0, 0.0025, 0, instancePosition,true); } if (t.Contains("8.11")) { a.CreateBlock(_swApp, 4, out instancePosition, 0.36 / 15 * vScaleRatio, 0.224 / 15 * vScaleRatio); AddTextBlock(swModel, swDraw, "- отв." + "<MOD-DIAM>" + "8h22", 0.027, 0.017, 0, 0.0025, 0, instancePosition,true); } } } }
/// <summary> /// Hook up events in the drawing context. /// </summary> private void ConnectDrawingEvents() { if (Document.GetType() == (int)swDocumentTypes_e.swDocDRAWING && !DrawEventsAssigned) { dd = (DrawingDoc)Document; //dd.ChangeCustomPropertyNotify += dd_ChangeCustomPropertyNotify; dd.AddItemNotify += dd_AddItemNotify; dd.DestroyNotify2 += dd_DestroyNotify2; dd.ViewNewNotify2 += dd_ViewNewNotify2; //dd.DestroyNotify += dd_DestroyNotify; DisconnectPartEvents(); DisconnectAssemblyEvents(); DrawEventsAssigned = true; } }
public void OpenDoc(int idPdm, int revision, int taskType, string filePath, string fileName) { swApp = new SldWorks() {Visible = true}; Process[] processes = Process.GetProcessesByName("SLDWORKS"); var errors = 0; var warnings = 0; #region Case switch (taskType) { case 1: Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("Выполняется: {0}\r\n", filePath)))); swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocPART, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); swModel = swApp.ActiveDoc; if (!IsSheetMetalPart((IPartDoc) swModel)) { Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.DarkBlue)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("Не листовой металл!\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("--------------------------------------------------------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } return; } swExtension = (ModelDocExtension) swModel.Extension; swModel.EditRebuild3(); swModel.ForceRebuild3(false); CreateFlattPatternUpdate(); object[] confArray = swModel.GetConfigurationNames(); foreach (var confName in confArray) { Configuration swConf = swModel.GetConfigurationByName(confName.ToString()); if (swConf.IsDerived()) continue; Area(confName.ToString()); GabaritsForPaintingCamera(confName.ToString()); } ExportDataToXmlSql(fileName, idPdm, revision); ConvertToErpt(filePath); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectionColor = Color.Black)); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += (String.Format("{0} - Выполнен!\r\n", filePath)))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("-----------------------------------------------------------------\r\n"))); Program.HostForm.richTextBoxLog.Invoke(new Action(() => Program.HostForm.richTextBoxLog.SelectedText += ("\r\n"))); break; case 2: swModel = swApp.OpenDoc6(filePath, (int) swDocumentTypes_e.swDocDRAWING, (int) swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); //if (warnings == (int)swFileLoadWarning_e.swFileLoadWarning_ReadOnly) //{MessageBox.Show("This file is read-only.");} swDraw = (DrawingDoc) swModel; swExtension = (ModelDocExtension) swModel.Extension; ConvertToPdf(filePath); break; case 3: //swModel = swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings); MessageBox.Show("3"); break; } //TODO: swApp exit swApp.CloseDoc(filePath); swApp.ExitApp(); swApp = null; foreach (Process process in processes) { process.CloseMainWindow(); process.Kill(); } #endregion }