Reply
Solved! Go to solution

property.get_Value() doesn't work in C#

Using ST7 and Visual Studio 2017:

 

In VB, 

seProp.Value

works.

 

In C#, 

seProp.get_Value()

does not work.

 

Please help.

Thanks,

Terry Tyson
Software Automation Designer
19 REPLIES

Re: property.get_Value() doesn't work in C#

Hello Terry,

 

to get file property, you can do this: (C#)

 

class Program
    {
        [STAThread]                         // Work with file properties
        static void Main(string[] args)
        {
            // Declare your main variables
            SolidEdgeFramework.Application seApplication = null;
            SolidEdgeFramework.Documents seDocuments = null;

            // Declare your document variables
            SolidEdgePart.PartDocument sePartDoc = null;

            // Declare variables about file properties collection
            SolidEdgeFramework.PropertySets propertySets = null;

            // Declare variable about Summary Information properties
            SolidEdgeFramework.Properties propertiesSummary = null;
            SolidEdgeFramework.Property title = null;
            SolidEdgeFramework.Property subject = null;
            SolidEdgeFramework.Property author = null;
            SolidEdgeFramework.Property comments = null;

            // Declare variable about Project Information properties
            SolidEdgeFramework.Properties propertiesProject = null;
            SolidEdgeFramework.Property documentNumber = null;
            SolidEdgeFramework.Property revision = null;
            SolidEdgeFramework.Property projectName = null;

            try
            {
                // Register
                OleMessageFilter.Register();

                // Connect your Solid Edge
                seApplication = SolidEdgeUtils.Connect(true);

                // Get your Document Collection
                seDocuments = seApplication.Documents;

                // Get Active Document
                sePartDoc = (PartDocument)seApplication.ActiveDocument;

                // Get collection of Property Sets
                propertySets = (PropertySets)sePartDoc.Properties;

                // Get collection of Sumary Information properties
                propertiesSummary = propertySets.Item("SummaryInformation");

                // Get properties
                title = propertiesSummary.Item("Title");
                subject = propertiesSummary.Item("Subject");
                author = propertiesSummary.Item("Author");
                comments = propertiesSummary.Item("Comments");

                // Write the value of each property
                title.set_Value("Write here the new title");
                subject.set_Value("Write here the text to subject");
                author.set_Value("Write here the author");
                comments.set_Value("Write the comment of your part document");

                // Now, the same thing to project properties
                propertiesProject = propertySets.Item("ProjectInformation");

                // Get properties
                documentNumber = propertiesProject.Item("Document Number");
                revision = propertiesProject.Item("Revision");
                projectName = propertiesProject.Item("Project Name");

                // Define the text of each property
                documentNumber.set_Value("012345");
                revision.set_Value("A");
                projectName.set_Value("Your project name");

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                // Ungister
                OleMessageFilter.Unregister();
            }
        }
    }

For step-by-step, see this video:

 



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com

Re: property.get_Value() doesn't work in C#

To get value as a string, do it:

 

                string titleString = (string)title.get_Value();
                string documentNumberString = (string)documentNumber.get_Value();

                Console.WriteLine(titleString);
                Console.WriteLine(documentNumberString);


==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com

Re: property.get_Value() doesn't work in C#

Kabir, thanks for the reply. I'm still getting a "Member not found" error. No matter how I try to use it, the .get_Value() method throws this error. What version of SE are you using?

Terry Tyson
Software Automation Designer

Re: property.get_Value() doesn't work in C#

Also, I'm trying to get the data from the Custom properties if that makes a difference. I've had no problem with this in VB, only in C#.
Terry Tyson
Software Automation Designer

Re: property.get_Value() doesn't work in C#

Are you can send images of the problem?



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com

Re: property.get_Value() doesn't work in C#

I've switched to using the SolidEdgeFileProperties class instead to bypass opening Solid Edge but I'm still having issues with C#. The VB code works just fine:

Sub Main()
        Dim sePropSets As SolidEdgeFileProperties.PropertySets = Nothing

        Try
            sePropSets = New SolidEdgeFileProperties.PropertySets
            sePropSets.Open("C:\Users\ttyson\Documents\ERP\Thermal\LowerFrameTestModels\Asm1.asm", True)
            Dim seCustomProps As SolidEdgeFileProperties.Properties = sePropSets.Item("Custom")
            For Each seProp As SolidEdgeFileProperties.Property In seCustomProps
                Console.WriteLine(seProp.Name + ": " + seProp.Value)
            Next
        Catch ex As Exception

        End Try
        Console.ReadLine()
    End Sub

But I can't get anywhere with the C# code. As you can see, the PropertySets object doesn't even have an Item property exposed.

PropertySets.JPG

Not only that but I get this error even trying to run the previous line.

PropertySetsError.JPG

There is nothing wrong with the file, I can open it and use it in Solid Edge and the VB code runs on it every time giving me what I'm looking for. I may just have to do this project in VB.

VB outputVB output

Terry Tyson
Software Automation Designer

Re: property.get_Value() doesn't work in C#

Try this:

 

using SolidEdgeFileProperties;

// (...)

PropertySets filePropertySets;
Properties fileProperties;
filePropertySets = new  PropertySets();

try
{
  filePropertySets.Open(fileFullPath, System.IO.FileShare.ReadWrite);
}
catch (System.Runtime.InteropServices.COMException e)
{
 return e.Message + e.ToString();
}

fileProperties = (Properties)filePropertySets["Custom"]; // Use ["Custom"]

 

If it still does not work, see this post:

https://community.plm.automation.siemens.com/t5/Solid-Edge-Developer-Forum/Document-properties-unava...



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com

Re: property.get_Value() doesn't work in C#

The file must not be open in Solid Edge.



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com
Solution
Solution
Accepted by topic author terry_tyson
‎03-28-2017 04:03 PM

Re: property.get_Value() doesn't work in C#

[ Edited ]

For get_Value(), try this instead:

string value = ((dynamic)seProp).Value;

Where seProp is of type SolidEdgeFramework.Property

 

You can set a value with ((dynamic)seProp).Value = "New Value";

Siemens PLM Software, Inc.
Project Test Engineer (Automation)