Update file prefix when active document changes.
This commit is contained in:
49
ExportDXF/DrawingInfo.cs
Normal file
49
ExportDXF/DrawingInfo.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace ExportDXF
|
||||||
|
{
|
||||||
|
public class DrawingInfo
|
||||||
|
{
|
||||||
|
public string JobNo { get; set; }
|
||||||
|
|
||||||
|
public string DrawingNo { get; set; }
|
||||||
|
|
||||||
|
public string Source { get; set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Format("{0} {1}", JobNo, DrawingNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return obj.ToString() == ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return ToString().GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DrawingInfo Parse(string input)
|
||||||
|
{
|
||||||
|
const string pattern = @"(?<jobNo>[34]\d{3})\s?(?<dwgNo>[ABEP]\d+)";
|
||||||
|
|
||||||
|
var match = Regex.Match(input, pattern);
|
||||||
|
|
||||||
|
if (match.Success == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var dwg = new DrawingInfo();
|
||||||
|
|
||||||
|
dwg.JobNo = match.Groups["jobNo"].Value;
|
||||||
|
dwg.DrawingNo = match.Groups["dwgNo"].Value;
|
||||||
|
dwg.Source = input;
|
||||||
|
|
||||||
|
return dwg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,6 +87,7 @@
|
|||||||
<Compile Include="BendDirection.cs" />
|
<Compile Include="BendDirection.cs" />
|
||||||
<Compile Include="BendOrientation.cs" />
|
<Compile Include="BendOrientation.cs" />
|
||||||
<Compile Include="Bounds.cs" />
|
<Compile Include="Bounds.cs" />
|
||||||
|
<Compile Include="DrawingInfo.cs" />
|
||||||
<Compile Include="Item.cs" />
|
<Compile Include="Item.cs" />
|
||||||
<Compile Include="IViewFlipDecider.cs" />
|
<Compile Include="IViewFlipDecider.cs" />
|
||||||
<Compile Include="ViewFlipDecider.cs" />
|
<Compile Include="ViewFlipDecider.cs" />
|
||||||
|
|||||||
37
ExportDXF/Forms/MainForm.Designer.cs
generated
37
ExportDXF/Forms/MainForm.Designer.cs
generated
@@ -28,24 +28,25 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
this.activeDocTitleBox = new System.Windows.Forms.TextBox();
|
||||||
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
|
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
this.textBox2 = new System.Windows.Forms.TextBox();
|
this.prefixTextBox = new System.Windows.Forms.TextBox();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// textBox1
|
// textBox1
|
||||||
//
|
//
|
||||||
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
this.activeDocTitleBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.textBox1.BackColor = System.Drawing.Color.White;
|
this.activeDocTitleBox.BackColor = System.Drawing.Color.White;
|
||||||
this.textBox1.Location = new System.Drawing.Point(130, 13);
|
this.activeDocTitleBox.Location = new System.Drawing.Point(130, 13);
|
||||||
this.textBox1.Name = "textBox1";
|
this.activeDocTitleBox.Name = "textBox1";
|
||||||
this.textBox1.ReadOnly = true;
|
this.activeDocTitleBox.ReadOnly = true;
|
||||||
this.textBox1.Size = new System.Drawing.Size(400, 25);
|
this.activeDocTitleBox.Size = new System.Drawing.Size(400, 25);
|
||||||
this.textBox1.TabIndex = 2;
|
this.activeDocTitleBox.TabIndex = 2;
|
||||||
|
this.activeDocTitleBox.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
|
||||||
//
|
//
|
||||||
// richTextBox1
|
// richTextBox1
|
||||||
//
|
//
|
||||||
@@ -80,12 +81,12 @@
|
|||||||
//
|
//
|
||||||
// textBox2
|
// textBox2
|
||||||
//
|
//
|
||||||
this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
this.prefixTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.textBox2.Location = new System.Drawing.Point(130, 44);
|
this.prefixTextBox.Location = new System.Drawing.Point(130, 44);
|
||||||
this.textBox2.Name = "textBox2";
|
this.prefixTextBox.Name = "textBox2";
|
||||||
this.textBox2.Size = new System.Drawing.Size(400, 25);
|
this.prefixTextBox.Size = new System.Drawing.Size(400, 25);
|
||||||
this.textBox2.TabIndex = 2;
|
this.prefixTextBox.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
@@ -107,8 +108,8 @@
|
|||||||
this.Controls.Add(this.label2);
|
this.Controls.Add(this.label2);
|
||||||
this.Controls.Add(this.label1);
|
this.Controls.Add(this.label1);
|
||||||
this.Controls.Add(this.richTextBox1);
|
this.Controls.Add(this.richTextBox1);
|
||||||
this.Controls.Add(this.textBox2);
|
this.Controls.Add(this.prefixTextBox);
|
||||||
this.Controls.Add(this.textBox1);
|
this.Controls.Add(this.activeDocTitleBox);
|
||||||
this.Controls.Add(this.button1);
|
this.Controls.Add(this.button1);
|
||||||
this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||||
@@ -123,11 +124,11 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Button button1;
|
private System.Windows.Forms.Button button1;
|
||||||
private System.Windows.Forms.TextBox textBox1;
|
private System.Windows.Forms.TextBox activeDocTitleBox;
|
||||||
private System.Windows.Forms.RichTextBox richTextBox1;
|
private System.Windows.Forms.RichTextBox richTextBox1;
|
||||||
private System.Windows.Forms.Label label1;
|
private System.Windows.Forms.Label label1;
|
||||||
private System.Windows.Forms.Label label2;
|
private System.Windows.Forms.Label label2;
|
||||||
private System.Windows.Forms.TextBox textBox2;
|
private System.Windows.Forms.TextBox prefixTextBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,8 +169,7 @@ namespace ExportDXF.Forms
|
|||||||
private void SetActiveDocName()
|
private void SetActiveDocName()
|
||||||
{
|
{
|
||||||
var model = sldWorks.ActiveDoc as ModelDoc2;
|
var model = sldWorks.ActiveDoc as ModelDoc2;
|
||||||
|
activeDocTitleBox.Text = model == null ? "<No Document Open>" : model.GetTitle();
|
||||||
textBox1.Text = model != null ? model.GetTitle() : "<No Document Open>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DetermineModelTypeAndExportToDXF(ModelDoc2 model)
|
private void DetermineModelTypeAndExportToDXF(ModelDoc2 model)
|
||||||
@@ -226,7 +225,7 @@ namespace ExportDXF.Forms
|
|||||||
|
|
||||||
private void ExportToDXF(PartDoc part)
|
private void ExportToDXF(PartDoc part)
|
||||||
{
|
{
|
||||||
var prefix = textBox2.Text;
|
var prefix = prefixTextBox.Text;
|
||||||
var model = part as ModelDoc2;
|
var model = part as ModelDoc2;
|
||||||
var dir = UserSelectFolder();
|
var dir = UserSelectFolder();
|
||||||
|
|
||||||
@@ -262,7 +261,7 @@ namespace ExportDXF.Forms
|
|||||||
private void ExportToDXF(IEnumerable<Item> items)
|
private void ExportToDXF(IEnumerable<Item> items)
|
||||||
{
|
{
|
||||||
var savePath = UserSelectFolder();
|
var savePath = UserSelectFolder();
|
||||||
var prefix = textBox2.Text;
|
var prefix = prefixTextBox.Text;
|
||||||
|
|
||||||
if (savePath == null)
|
if (savePath == null)
|
||||||
{
|
{
|
||||||
@@ -604,7 +603,22 @@ namespace ExportDXF.Forms
|
|||||||
{
|
{
|
||||||
get { return Path.Combine(Application.StartupPath, "Templates", "Blank.drwdot"); }
|
get { return Path.Combine(Application.StartupPath, "Templates", "Blank.drwdot"); }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var model = sldWorks.ActiveDoc as ModelDoc2;
|
||||||
|
var isDrawing = model is DrawingDoc;
|
||||||
|
|
||||||
|
if (!isDrawing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var drawingInfo = DrawingInfo.Parse(activeDocTitleBox.Text);
|
||||||
|
|
||||||
|
if (drawingInfo == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
prefixTextBox.Text = string.Format("{0} {1} PT", drawingInfo.JobNo, drawingInfo.DrawingNo);
|
||||||
|
prefixTextBox.SelectionStart = prefixTextBox.Text.Length;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user