Code:
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
// text in textboxen anzeien
InitializeComponent();
//einträge anzeigen
// Connect to a running instance of Inventor.
// Watch out for the wrapped line.
Inventor.Application invApp = null;
invApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
// Get the active document.
Inventor.Document doc = invApp.ActiveDocument;
GetCustomiProperty(doc, "prop1", textBox1.Text);
GetCustomiProperty(doc, "prop2", textBox2.Text);
GetCustomiProperty(doc, "prop3", textBox3.Text);
GetCustomiProperty(doc, "prop4", textBox4.Text);
GetCustomiProperty(doc, "prop5", textBox5.Text);
GetCustomiProperty(doc, "prop6", comboBox1.Text);
GetCustomiProperty(doc, "prop7", textBox7.Text);
GetCustomiProperty(doc, "prop8", textBox8.Text);
GetCustomiProperty(doc, "prop9", textBox6.Text);
GetCustomiProperty(doc, "prop10", textBox9.Text);
GetCustomiProperty(doc, "prop11", comboBox2.Text);
GetCustomiProperty(doc, "prop12", comboBox3.Text);
}
private void button1_Click(object sender, EventArgs e)
{
// Löschen ?
// Connect to a running instance of Inventor.
// Watch out for the wrapped line.
Inventor.Application invApp = null;
invApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
// Get the active document.
Inventor.Document doc = invApp.ActiveDocument;
// Löschen ?
// Update or create the custom iProperty.
UpdateCustomiProperty(doc, "prop1", textBox1.Text);
UpdateCustomiProperty(doc, "prop2", textBox2.Text);
UpdateCustomiProperty(doc, "prop3", textBox3.Text);
UpdateCustomiProperty(doc, "prop4", textBox4.Text);
UpdateCustomiProperty(doc, "prop5", textBox5.Text);
UpdateCustomiProperty(doc, "prop6", comboBox1.Text);
UpdateCustomiProperty(doc, "prop7", textBox7.Text);
UpdateCustomiProperty(doc, "prop8", textBox8.Text);
UpdateCustomiProperty(doc, "prop9", textBox6.Text);
UpdateCustomiProperty(doc, "prop10", textBox9.Text);
UpdateCustomiProperty(doc, "prop11", comboBox2.Text);
UpdateCustomiProperty(doc, "prop12", comboBox3.Text);
Form1.ActiveForm.Close();
}
private void UpdateCustomiProperty(Inventor.Document Doc,
String PropertyName,
Object PropertyValue)
{
// Get the custom property set.
// Watch out for the wrapped line.
Inventor.PropertySet customPropSet;
customPropSet = Doc.PropertySets["Inventor User Defined Properties"];
// Get the existing property, if it exists.
Inventor.Property prop = null;
Boolean propExists = true;
try
{
prop = customPropSet[PropertyName];
}
catch (Exception ex)
{
propExists = false;
}
// Check to see if the property was successfully obtained.
if (!propExists)
{
// Failed to get the existing property so create a new one.
prop = customPropSet.Add(PropertyValue, PropertyName, null);
}
else
{
// Change the value of the existing property.
prop.Value = PropertyValue;
}
}
// lese iprop
private void GetCustomiProperty(Inventor.Document Doc,
String PropertyName,
Object PropertyValue)
// string war object bei value
{
// Get the custom property set.
// Watch out for the wrapped line.
Inventor.PropertySet customPropSet;
customPropSet = Doc.PropertySets["Inventor User Defined Properties"];
// Get the existing property, if it exists.
Inventor.Property prop = null;
Boolean propExists = true;
try
{
prop = customPropSet[PropertyName];
}
catch (Exception ex)
{
propExists = false;
}
// Check to see if the property was successfully obtained.
if (!propExists)
{
// Failed to get the existing property so create a new one.
prop = customPropSet.Add(PropertyValue, PropertyName, null);
}
else
{
// get the value of the existing property.
PropertyValue = customPropSet[PropertyName].Value;
}
}