//Layerliste in csv exportieren public void Export() { myCAD.MyLayer objLayer = myCAD.MyLayer.Instance; string curDwg = HostApplicationServices.WorkingDatabase.Filename; SaveFileDialog ddSaveFile = new SaveFileDialog() { DefaultExt = "csv", Filter = "Layerliste|*.csv", InitialDirectory = curDwg.Substring(0, curDwg.LastIndexOf('\\')), FileName = curDwg.Substring(curDwg.LastIndexOf('\\') + 1, curDwg.LastIndexOf('.')) }; if (ddSaveFile.ShowDialog() == DialogResult.OK) { StreamWriter sw = new StreamWriter(ddSaveFile.FileName, false, Encoding.Default); foreach (_AcDb.LayerTableRecord objLTR in objLayer.LsLayerTableRecord) { string Zeile = objLTR.Name + ";"; Zeile += objLTR.Color.ToString() + ";"; sw.WriteLine(Zeile); } sw.Close(); } }
//Layer für MP generieren private void CheckBasislayer() { int cnt = 0; myCAD.MyLayer objLayer = myCAD.MyLayer.Instance; string Basislayer = _config.GetAppSettingString("Basislayer"); Basislayer = Basislayer.Substring(0, Basislayer.Length - 2); cnt += objLayer.Add(Basislayer + Global.Instance.LayNummer); cnt += objLayer.Add(Basislayer + Global.Instance.LayHöhe); cnt += objLayer.Add(Basislayer + Global.Instance.LayDatum); cnt += objLayer.Add(Basislayer + Global.Instance.LayCode); if (cnt > 0) { MessageBox.Show("Layer für " + Basislayer + " wurden erstellt!"); } }
public DiaSettings() { InitializeComponent(); //Init Configuration //Basislayer value = _config.GetAppSettingString("Basislayer"); if (value == String.Empty) { _config.SetAppSetting("Basislayer", "MP-P"); } //Header value = _config.GetAppSettingString("useHeader"); if (value == String.Empty) { _config.SetAppSetting("useHeader", "False"); } cB_Header.Checked = Convert.ToBoolean(value); value = _config.GetAppSettingString("Header"); if (value == String.Empty) { _config.SetAppSetting("Header", "PNr, X,Y,Z"); } tb_Header.Text = value; //3dImport value = _config.GetAppSettingString("3dImport"); if (value == String.Empty) { _config.SetAppSetting("3dImport", "False"); } cb_3dImport.Checked = Convert.ToBoolean(value); //Output File value = _config.GetAppSettingString("OutputFile"); if (File.Exists(value)) { tb_PunktExport.Text = value; cB_ExportFile.Enabled = File.Exists(value); value = _config.GetAppSettingString("useOutputFile"); if (value == String.Empty) { _config.SetAppSetting("useOutputFile", "False"); } cB_OutputFile.Checked = Convert.ToBoolean(value); } else { tb_PunktExport.Text = " "; } //Separator & Decimal value = _config.GetAppSettingString("Separator"); if (value == String.Empty) { _config.SetAppSetting("Separator", ";"); } tB_Separator.Text = value; value = _config.GetAppSettingString("Decimal"); if (value == String.Empty) { _config.SetAppSetting("Decimal", "."); } cb_Decimal.SelectedItem = value; cb_Decimal.Refresh(); value = _config.GetAppSettingString("decimals"); if (value == "") { value = "3"; _config.SetAppSetting("decimals", value); } numUD_Kommastellen.Value = Convert.ToInt32(value); //import Exportfile value = _config.GetAppSettingString("importExportfile"); if (value == String.Empty) { cB_ExportFile.Checked = false; } else { cB_ExportFile.Checked = Convert.ToBoolean(value); } //Treenode TreeNode root = treeView1.Nodes.Add("CAS 2019"); //root.Nodes.Add("general"); root.Nodes.Add("Import"); root.Nodes.Add("Export"); root.ExpandAll(); treeView1.SelectedNode = root.FirstNode; //Basislayer myCAD.MyLayer objLayer = myCAD.MyLayer.Instance; objLayer.Refresh(); try { foreach (_AcDb.LayerTableRecord ltr in objLayer.LsLayerTableRecord) { string layName = ltr.Name; if (layName.Length > 2) { if (layName.Substring(layName.Length - 2, 2) == "-P") { cbBasislayer.Items.Add(layName); } } } } catch { } cbBasislayer.SelectedIndex = cbBasislayer.FindStringExact(_config.GetAppSettingString("Basislayer")); if (cbBasislayer.SelectedIndex == -1) { if (cbBasislayer.Items.Count > 0) { DialogResult res = MessageBox.Show(_config.GetAppSettingString("Basislayer") + " nicht gefunden! Soll dieser Layer erstellt werden?", "", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { objLayer.Add(_config.GetAppSettingString("Basislayer")); } } else { string Basislayer = _config.GetAppSettingString("Basislayer"); CheckBasislayer(); cbBasislayer.Items.Add(Basislayer); cbBasislayer.SelectedItem = cbBasislayer.Items[0]; } } //Blöcke aus Protoypzeichnung lesen _AcAp.Document myDWG; _AcAp.DocumentLock myDWGlock; Database db = HostApplicationServices.WorkingDatabase; _AcDb.TransactionManager myTm = null; myTm = db.TransactionManager; Transaction myT = db.TransactionManager.StartTransaction(); string ProtoDWG = CAS.myUtilities.Global.Instance.PrototypFullPath; lb_Prototypzeichnung.Text = ProtoDWG; if (File.Exists(ProtoDWG)) { try { myDWG = _AcAp.Application.DocumentManager.MdiActiveDocument; myDWGlock = myDWG.LockDocument(); using (Database srcDb = new Database(false, false)) { srcDb.ReadDwgFile(ProtoDWG, FileShare.Read, true, ""); ObjectIdCollection blockIds = new ObjectIdCollection(); _AcDb.TransactionManager srcT = srcDb.TransactionManager; try { using (Transaction protoT = srcT.StartTransaction()) { BlockTable bt = (BlockTable)protoT.GetObject(srcDb.BlockTableId, OpenMode.ForRead, false); foreach (ObjectId btrid in bt) { BlockTableRecord btr = (BlockTableRecord)protoT.GetObject(btrid, OpenMode.ForRead, false); if (!btr.IsAnonymous && !btr.IsLayout) { blockIds.Add(btrid); cbBlock.Items.Add(btr.Name); } btr.Dispose(); } protoT.Commit(); protoT.Dispose(); } } catch { } finally { myT.Commit(); myT.Dispose(); } //Blöcke in aktuelle Zeichnung einfügen IdMapping mapping = new IdMapping(); srcDb.WblockCloneObjects(blockIds, db.BlockTableId, mapping, DuplicateRecordCloning.Replace, false); srcDb.Dispose(); myDWGlock.Dispose(); } } catch { } } else { MessageBox.Show("Achtung!!! Prototypzeichnung nicht gefunden!"); } if (cbBlock.Items.Count > 0) { try { cbBlock.SelectedIndex = cbBlock.FindStringExact(_config.GetAppSettingString("Block")); //Block aus settings.xml suchen } catch { cbBlock.SelectedItem = cbBlock.Items[0]; //sonst ersten Block wählen } } else { MessageBox.Show("Keine Blöcke gefunden!"); } //Header cB_Header.Checked = _config.GetAppSettingBool("useHeader"); tb_Header.Text = _config.GetAppSettingString("Header"); //Output File cB_OutputFile.Checked = _config.GetAppSettingBool("useOutputFile"); tb_PunktExport.Text = _config.GetAppSettingString("OutputFile"); }