changing Author Property using C# - save failes..

Hi,

I'm trying to convert all the files in my folder so I'll be the Author of them.

reading the file Author properties is OK, yet when I'm changing the Author value to "polk" and saving:

1. property.GetType().InvokeMember("Value", System.Reflection.BindingFlags.SetProperty, null, property, new object[] 

                            {"polk"});

2. propertySets.Save();

 

In the debugger I see that after passing line 1 the value was updated correctly.

Yet it seems that line 2 has no effect since when opening the file again the author didn't changed..

 

When I try to save with "properties.Save();" I get exception.

 

What am I doing wrong?

 

P.S:

Based my code according to Jason in this post: http://www.jasonnewell.net/Community/Forums/tabid/55/aft/1437/Default.aspx

 

 

Posted by: joseph polk
Post date: 10/25/2011 6:47:10 PM

2 REPLIES

RE: changing Author Property using C# - save failes..

Hi,

 

try to acces and modify the author by using the SummaryInfo object of the SolidEdgeDcoument object instead of using the file properties.

 

 

Posted by: Wolfgang Kunert
Post date: 10/26/2011 10:29:33 PM

RE: changing Author Property using C# - save failes..

Thanks Wolfgang!

That helped

 

for the case that others will stumble upon the same issue my code below - any remarks or code refinements are welcomed

 

 

using System;

using System.Runtime.InteropServices;

namespace MyMacro

{

    class Program

    {

        static void Main(string[] args)

        {

            SolidEdgeFramework.Application application = null;

            SolidEdgeFramework.SolidEdgeDocument document = null;

            SolidEdgeFramework.SummaryInfo summInfo = null;

            Type type = null;

            try

            {

 

                // Get the type from the Solid Edge ProgID

                type = Type.GetTypeFromProgID("SolidEdge.Application");

                // Start Solid Edge

                application = (SolidEdgeFramework.Application)Activator.CreateInstance(type);

                // Make Solid Edge visible

                application.Visible = true;

                // Turn off alerts. Weldment environment will display a warning

                application.DisplayAlerts = false;

 

                string sDestinationFile = @"C:\htuli2.par";

                SolidEdgePart.PartDocument _objDoc = (SolidEdgePart.PartDocument)application.Documents.Open(sDestinationFile);

 

                // Get a reference to the active document

                document = (SolidEdgeFramework.SolidEdgeDocument) application.ActiveDocument;

                summInfo = document.SummaryInfo;

                // Setting Author to new value

                summInfo.Author = "zZzZz Polk";

                // Updating file status to inWork...

                document.Status = SolidEdgeFramework.DocumentStatus.igStatusInWork;

                document.Save();

                //document.SaveAs(sDestinationFile);

            }

            catch (System.Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

            finally

            {

                if (application != null)

                {

                    Marshal.ReleaseComObject(application);

                    application = null;

                }

            }

        }

    }

}

 

 

Posted by: joseph polk
Post date: 10/27/2011 12:46:08 PM