Saving User Defined Properties in a Drawing

Saving User Defined Properties in a Drawing

mowag
Enthusiast Enthusiast
214 Views
2 Replies
Message 1 of 3

Saving User Defined Properties in a Drawing

mowag
Enthusiast
Enthusiast

Hi,

i've wrote an addin to change some User Defined Properties in a drawing.

 

Screenshot_BEW.png

 

        public Bewerkingen()
        {
            InitializeComponent();
        }
        public Bewerkingen(Application inventor)
        {
            InitializeComponent();
            this.Shown += CreateUI;

            Machinings = new string[5];
            this.inventor = inventor;
            DrawingDocument oDrawDoc = (DrawingDocument)inventor.ActiveDocument;
            PropertySets oPropSets = oDrawDoc.PropertySets;
            PropertySet oPropSet = oPropSets["User Defined Properties"];
            Enumerator = oPropSet.GetEnumerator();
            Enumerator.Reset();
            Machinings[0] = "";
            Machinings[1] = "";
            Machinings[2] = "";
            Machinings[3] = "";
            Machinings[4] = "";

            while (Enumerator.MoveNext())
            {
                prop = (Property)Enumerator.Current;

                if (prop.DisplayName == "Bewerking1") Machinings[0] = prop.Expression ?? " ";
                if (prop.DisplayName == "Bewerking2") Machinings[1] = prop.Expression ?? " ";
                if (prop.DisplayName == "Bewerking3") Machinings[2] = prop.Expression ?? " ";
                if (prop.DisplayName == "Bewerking4") Machinings[3] = prop.Expression ?? " ";
                if (prop.DisplayName == "Bewerking5") Machinings[4] = prop.Expression ?? " ";
                if (prop.DisplayName == "Aantal") Aantal = Int32.Parse(prop.Expression);
            }
            textboxAantal.Text = Aantal.ToString();
        }

i create the UI programatically

 

        public void CreateUI(object sender, EventArgs e)
        {
            this.Size = new Size(805, 650);

            for (int i = 0; i < 5; i++)
            {
                GroupBox groupbox = new GroupBox();
                groupbox.Name = "Bewerking" + (i + 1);
                groupbox.Text = "Bewerking " + (i + 1);
                groupbox.Location = new System.Drawing.Point(30 + (i * 150), 30);
                groupbox.Size = new Size(130, 530);

                for (int j = 0; j < 14; j++)
                {
                    Button button = new Button();
                    button.Name = groupbox.Text + "button" + (j + 1);
                    button.Text = MachiningsNames[j];
                    button.Location = new System.Drawing.Point(10, 30 + j * 35);
                    button.Size = new Size(100, 30);
                    button.BackColor = System.Drawing.Color.FromArgb(200, 220, 220, 220);
                    button.ForeColor = System.Drawing.Color.FromArgb(200, 20, 20, 20);
                    button.Click += new EventHandler(NewButton_Click);
                    groupbox.Controls.Add(button);

                }

                this.Controls.Add(groupbox);
            }
            SetBackgroudButtons();

            Label label = new Label();
            label.Text = "Aantal : ";
            label.Location = new System.Drawing.Point(30, 574);
            label.Size = new Size(100, 50);
            label.Font = new Font("Microsoft Sans Serif", 16, FontStyle.Bold);
            label.ForeColor = System.Drawing.Color.FromArgb(200, 20, 20, 20);
            this.Controls.Add(label);


            textboxAantal.Location = new System.Drawing.Point(130, 570);
            textboxAantal.Size = new Size(75, 50);
            textboxAantal.Font = new Font("Microsoft Sans Serif", 16, FontStyle.Bold);
            textboxAantal.ForeColor = System.Drawing.Color.FromArgb(200, 20, 20, 20);
            textboxAantal.TextChanged += new EventHandler(AantalChanged);
            this.Controls.Add(textboxAantal);

        }

We have two workstations. On my workstation this works flawlessly (saving drawing as well). But on the other station, the properties get changed aswell, but when saving the drawing all properties gets cleared ?? 

How can the save action be responsible for 'clearing' the User Defined Properties ??

 

Johan

0 Likes
215 Views
2 Replies
Replies (2)
Message 2 of 3

tyler.warner
Advocate
Advocate

On the other workstation, I'm guessing you just have the add-in Dll's & not running thru the solution. Though not typically a great procedure when creating an add-in, you can add message boxes to allow you to step thru the code on the other workstation.

 

You could also change the values of Machining[0], etc. to something other than "" (after reset) or  " " (when null expression) to see if the values are actually being cleared or if they are being set with the empty stings.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes
Message 3 of 3

mowag
Enthusiast
Enthusiast

Hi Tyler,

 

Yeah, on the other station just the addin dll's !  But i'm able to run it tru the solution, wich i'll do !. Good tip to set the Machining[] to something other then " " so i can see what's happening. 

 

Johan

0 Likes