public View CreerVueToleDvp(DrawingDoc dessin, Sheet feuille, PartDoc piece, String configDepliee, String Ref, String materiau, int quantite, Double epaisseur) { var NomVue = piece.eModelDoc2().eNomSansExt() + " - " + configDepliee; dessin.eModelDoc2().eEffacerSelection(); View Vue = dessin.CreateFlatPatternViewFromModelView3(piece.eModelDoc2().GetPathName(), configDepliee, 0, 0, 0, !AfficherLignePliage, false); Vue.ScaleDecimal = 1; if (Vue.IsRef()) { Vue.SetName2(NomVue); GeomVue g = AppliquerOptionsVue(dessin, piece, Vue); Vue.eSelectionner(dessin); try { Note Note = dessin.eModelDoc2().InsertNote(String.Format("qté {0} // réf {1} [{2}] (Ep{3})", quantite, Ref, materiau, epaisseur)); Note.SetTextJustification((int)swTextJustification_e.swTextJustificationCenter); Annotation Annotation = Note.GetAnnotation(); TextFormat swTextFormat = Annotation.GetTextFormat(0); // Hauteur du texte en fonction des dimensions du dvp, 2.5% de la dimension max du dvp swTextFormat.CharHeight = Math.Max(0.005, Math.Floor(Math.Max(g.Ht, g.Lg) * 0.025 * 1000) * 0.001); Annotation.SetTextFormat(0, false, swTextFormat); Annotation.Layer = "QUANTITE"; Annotation.SetLeader3((int)swLeaderStyle_e.swNO_LEADER, (int)swLeaderSide_e.swLS_SMART, true, true, false, false); // Décalage du texte en fonction des dimensions du dvp, 0.1% de la dimension max du dvp Annotation.SetPosition(g.ptCentreRectangleX, g.ptMinY - Math.Max(0.005, Math.Floor(Math.Max(g.Ht, g.Lg) * 0.001 * 1000) * 0.001), 0); g.Agrandir(Note); } catch (Exception e) { WindowLog.Ecrire(" - Erreur"); this.LogMethode(new Object[] { e }); } if (InscrireNomTole) { try { Note Note = dessin.eModelDoc2().InsertNote(Ref); Note.SetTextJustification((int)swTextJustification_e.swTextJustificationCenter); Annotation Annotation = Note.GetAnnotation(); TextFormat swTextFormat = Annotation.GetTextFormat(0); // Hauteur du texte en fonction des dimensions du dvp, 2.5% de la dimension max du dvp swTextFormat.CharHeight = TailleInscription * 0.001; Annotation.SetTextFormat(0, false, swTextFormat); Annotation.Layer = "GRAVURE"; Annotation.SetLeader3((int)swLeaderStyle_e.swNO_LEADER, (int)swLeaderSide_e.swLS_SMART, true, true, false, false); } catch (Exception e) { WindowLog.Ecrire(" - Erreur"); this.LogMethode(new Object[] { e }); } } PositionnerVue(feuille, Vue, g); return(Vue); } WindowLog.Ecrire(" - Erreur : pas de vue dvp"); return(null); }
public View CreerVueToleDvp(DrawingDoc dessin, Sheet feuille, PartDoc piece, String configDepliee, String Ref, String materiau, int quantite, Double epaisseur) { // Si des corps autre que la tole dépliée sont encore visible dans la config, on les cache et on recontruit tout foreach (Body2 pCorps in piece.eListeCorps(false)) { if ((pCorps.Name == CONSTANTES.NOM_CORPS_DEPLIEE)) { pCorps.eVisible(true); } else { pCorps.eVisible(false); } } var NomVue = piece.eModelDoc2().eNomSansExt() + " - " + configDepliee; if (MajPlans) { foreach (var vue in feuille.eListeDesVues()) { if (vue.GetName2() == NomVue) { vue.eSelectionner(dessin); dessin.eModelDoc2().Extension.DeleteSelection2((int)swDeleteSelectionOptions_e.swDelete_Advanced); break; } } } dessin.eModelDoc2().eEffacerSelection(); View Vue = dessin.CreateFlatPatternViewFromModelView3(piece.eModelDoc2().GetPathName(), configDepliee, 0, 0, 0, !AfficherLignePliage, false); Vue.ScaleDecimal = 1; if (Vue.IsRef()) { Vue.SetName2(NomVue); GeomVue g = AppliquerOptionsVue(dessin, piece, Vue); Vue.eSelectionner(dessin); { Note Note = dessin.eModelDoc2().InsertNote(String.Format("{0}× {1} [{2}] (Ep{3})", quantite, Ref, materiau, epaisseur)); Note.SetTextJustification((int)swTextJustification_e.swTextJustificationCenter); Annotation Annotation = Note.GetAnnotation(); TextFormat swTextFormat = Annotation.GetTextFormat(0); // Hauteur du texte en fonction des dimensions du dvp, 2.5% de la dimension max du dvp swTextFormat.CharHeight = Math.Max(0.005, Math.Floor(Math.Max(g.Ht, g.Lg) * 0.025 * 1000) * 0.001); Annotation.SetTextFormat(0, false, swTextFormat); Annotation.Layer = "QUANTITE"; Annotation.SetLeader3((int)swLeaderStyle_e.swNO_LEADER, (int)swLeaderSide_e.swLS_SMART, true, true, false, false); // Décalage du texte en fonction des dimensions du dvp, 0.1% de la dimension max du dvp Annotation.SetPosition(g.ptCentreRectangleX, g.ptMinY - Math.Max(0.005, Math.Floor(Math.Max(g.Ht, g.Lg) * 0.001 * 1000) * 0.001), 0); g.Agrandir(Note); } if (InscrireNomTole) { Note Note = dessin.eModelDoc2().InsertNote(Ref); Note.SetTextJustification((int)swTextJustification_e.swTextJustificationCenter); Annotation Annotation = Note.GetAnnotation(); TextFormat swTextFormat = Annotation.GetTextFormat(0); // Hauteur du texte en fonction des dimensions du dvp, 2.5% de la dimension max du dvp swTextFormat.CharHeight = TailleInscription * 0.001; Annotation.SetTextFormat(0, false, swTextFormat); Annotation.Layer = "GRAVURE"; Annotation.SetLeader3((int)swLeaderStyle_e.swNO_LEADER, (int)swLeaderSide_e.swLS_SMART, true, true, false, false); } if (ConvertirEsquisse) { String titre = Vue.GetName2(); Vue.ReplaceViewWithSketch(); Vue = feuille.eListeDesVues().Last(); Vue.SetName2(titre); g = new GeomVue(Vue); } PositionnerVue(feuille, Vue, g); return(Vue); } return(null); }
public void CreateFlattPatternUpdateCutlistAndEdrawing() { #region Сбор информации по детали и сохранение разверток SldWorks swApp = null; try { swApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); swApp = new SldWorks { Visible = true }; IModelDoc2 swModel = swApp.IActiveDoc2; swModel.Extension.ViewDisplayRealView = false; if (!IsSheetMetalPart((IPartDoc)swModel)) { MessageBox.Show("Деталь не из листового материала"); } Configuration activeconfiguration; string[] swModelConfNames; activeconfiguration = (Configuration)swModel.GetActiveConfiguration(); swModelConfNames = (string[])swModel.GetConfigurationNames(); ModelDocExtension swModelDocExt; string[] swModelConfNames2; swModelDocExt = swModel.Extension; swModelConfNames2 = (string[])swModel.GetConfigurationNames(); try { foreach (var configName in from name in swModelConfNames2 let config = (Configuration)swModel.GetConfigurationByName(name) where !config.IsDerived() select name) { swModel.ShowConfiguration2(configName); swModel.EditRebuild3(); FileInfo template = null; try { template = new FileInfo(ШаблонЧертежаРазверткиВнеХранилища); Thread.Sleep(1000); } catch (Exception exception) { MessageBox.Show(exception.ToString()); template = new FileInfo(ШаблонЧертежаРазверткиВнеХранилища); Thread.Sleep(1000); } finally { if (template == null) { template = new FileInfo(ШаблонЧертежаРазверткиВнеХранилища); } } if (swApp != null) { DrawingDoc swDraw = null; swDraw = (DrawingDoc) swApp.INewDocument2(template.FullName, (int)swDwgPaperSizes_e.swDwgPaperA0size, 0.841, 0.594); swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName(), configName, 0.841 / 2, 0.594 / 2, 0, true, false); ((IModelDoc2)swDraw).ForceRebuild3(true); #region азгибание всех сгибов try { swModel.EditRebuild3(); var swPart = (IPartDoc)swModel; Feature swFeature = swPart.FirstFeature(); const string strSearch = "FlatPattern"; while (swFeature != null) { var nameTypeFeature = swFeature.GetTypeName2(); if (nameTypeFeature == strSearch) { swFeature.Select(true); swPart.EditUnsuppress(); Feature swSubFeature = swFeature.GetFirstSubFeature(); while (swSubFeature != null) { var nameTypeSubFeature = swSubFeature.GetTypeName2(); if (nameTypeSubFeature == "UiBend") { swFeature.Select(true); swPart.EditUnsuppress(); swModel.EditRebuild3(); try { swSubFeature.SetSuppression2( (int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swAllConfiguration, swModelConfNames2); } catch (Exception) { } } swSubFeature = swSubFeature.GetNextSubFeature(); } } swFeature = swFeature.GetNextFeature(); } swModel.EditRebuild3(); } catch (Exception exception) { MessageBox.Show(exception.Message); } #endregion swModel.ForceRebuild3(false); var thikness = GetFromCutlist(swModel, "Толщина листового металла"); var errors = 0; var warnings = 0; var newDxf = (IModelDoc2)swDraw; newDxf.Extension.SaveAs( "C:\\" + Path.GetFileNameWithoutExtension(swModel.GetPathName()) + "-" + configName + "-" + thikness + ".dxf", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_UpdateInactiveViews, null, ref errors, ref warnings); swApp.CloseDoc(Path.GetFileName(newDxf.GetPathName())); } } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } try { swModel.ShowConfiguration2(activeconfiguration.Name); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } #endregion } catch (Exception exception) { MessageBox.Show(exception.ToString()); } }
private bool SavePartToDXF(PartDoc part, string partConfiguration, string savePath) { try { var partModel = part as ModelDoc2; if (partModel.IsSheetMetal() == false) { Print(partModel.GetTitle() + " - skipped, not sheet metal"); return(false); } if (templateDrawing == null) { templateDrawing = CreateDrawing(); } var sheet = templateDrawing.IGetCurrentSheet(); var modelName = Path.GetFileNameWithoutExtension(partModel.GetPathName()); sheet.SetName(modelName); Print(partModel.GetTitle() + " - Creating flat pattern."); SolidWorks.Interop.sldworks.View view; view = templateDrawing.CreateFlatPatternViewFromModelView3(partModel.GetPathName(), partConfiguration, 0, 0, 0, false, false); view.ShowSheetMetalBendNotes = true; var drawingModel = templateDrawing as ModelDoc2; drawingModel.ViewZoomtofit2(); if (HasSupressedBends(view)) { Print("A bend is suppressed, please check flat pattern!", Color.Red); } if (HideModelSketches(view)) { // delete the current view that has sketches shown drawingModel.SelectByName(0, view.Name); drawingModel.DeleteSelection(false); // recreate the flat pattern view view = templateDrawing.CreateFlatPatternViewFromModelView3(partModel.GetPathName(), partConfiguration, 0, 0, 0, false, false); view.ShowSheetMetalBendNotes = true; } if (viewFlipDecider.ShouldFlip(view)) { Print(partModel.GetTitle() + " - Flipped view", Color.Blue); view.FlipView = true; } drawingModel.SaveAs(savePath); Print(partModel.GetTitle() + " - Saved to \"" + savePath + "\"", Color.Green); drawingModel.SelectByName(0, view.Name); drawingModel.DeleteSelection(false); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }