Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello together,

i've got a problem with this Code.

I cant get the material property out of a part in a assembly.

Could anyone help me pls to fix this?
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Reflection;
using SolidEdgeFramework;
using SolidEdgeFileProperties;
using SolidEdgeAssembly;
using SolidEdgePart;
using SolidEdgeFrameworkSupport;

namespace Stuecklisten_Tool_V_1_00
{
    class Program
    {
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application=null;
            SolidEdgeFramework.Documents documents = null;
            SolidEdgeAssembly.AssemblyDocument assembly = null;
            SolidEdgeAssembly.Occurrences occurrences = null;
            //SolidEdgeAssembly.Occurrence objOccurrence =null;
            SolidEdgePart.PartDocument objSEDocument =null;
            //SolidEdgeFileProperties.PropertySets propertySets =null;
            //SolidEdgeFileProperties.Properties properties= null;
            //SolidEdgeFileProperties.Property property =null;


            // define Bom-Array
            string[][] BOM;

            // counter vars
            int i;  //BOM-row-number
            int j;  //fill assembly information in array

                       

            // Connect to a running instance of Solid Edge
            application = (SolidEdgeFramework.Application)
                Marshal.GetActiveObject("SolidEdge.Application");

            // Ausgabe der Verbindungsbestätgung in der Console.
            Console.WriteLine("Mit SolideEdge verbunden!");
            Console.ReadLine();

            // Get a Reference to the documents collection
            documents = application.Documents;

            // Get a Reference to the ActiveDocument 
            // and show the name
            
            assembly= (SolidEdgeAssembly.AssemblyDocument)
                 application.ActiveDocument;

            // Get reference to the occurrences collection
            occurrences = assembly.Occurrences;

            // count all occurrences
            // define size of Bom-array

            i = occurrences.Count;
            BOM = new string[i][];

            //fill Bom with assemblyinformation of all occurences
            for (j = 1; j <= i; j++)
            {
                BOM[j-1] = new string[6];
                //write occurence name in array --> ROW 1
                BOM[j-1][1] = occurrences.Item(j).Name;
                //write occurence number in array --> ROW 2
                BOM[j-1][2] = Convert.ToString(occurrences.Item(j).Quantity);
                // write path in array --> ROW 3
                BOM[j-1][3] = occurrences.Item(j).OccurrenceFileName;
                // write material in array --> ROW 4
                objSEDocument = (SolidEdgePart.PartDocument)
                    occurrences.Item(j).OccurrenceDocument;

                BOM[j-1][4] = objSEDocument.Properties("MechanicalModeling").Item("Material").value;
            }
        }
    }
Posted
Updated 22-May-14 7:37am
v2
Comments
Bernhard Hiller 22-May-14 6:09am    
Any error messages? NullReferenceException???
What's SolidEdgePart.PartDocument - where is it defined? Source code available?
[no name] 22-May-14 8:17am    
What error do you exactly get? What is SolidEdgeFramework? Provide any Links.
gggustafson 22-May-14 14:06pm    
Do as Manikandan10 suggests. Without knowing what the various SolidEdge namespaces are, we are not going to be able to help you. No code - just references. Also is ther some kind of error message? If so, please provide it.
Member 10836349 23-May-14 4:16am    
Hello,

thx for your answers.

The error message is:

COMExeption was unhandled:

{"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"}

I dont realy know wich kind of references you mean. All i can get you is an arcticle about solideEdge.

"Solid Edge Core Type Libraries

The Solid Edge core COM type libraries are the APIs that are available to automate the Solid Edge
application. These APIs can be used by any programming or scripting language that supports COM.
You can find these type libraries in the installation path of Solid Edge under the “Program” folder. For
example: “%PROGRAMFILES%\Solid Edge VXX\Program”.

Table of core APIs

Name Description Type Library
SolidEdgeFramework Solid Edge Framework Type Library framewrk.tlb
SolidEdgeFrameworkSupport Solid Edge FrameworkSupport Type Library fwksupp.tlb
SolidEdgePart Solid Edge Part Type Library part.tlb
SolidEdgeGeometry Solid Edge Geometry Type Library geometry.tlb
SolidEdgeAssembly Solid Edge Assembly Type Library assembly.tlb
SolidEdgeDraft Solid Edge Draft Type Library draft.tlb
SolidEdgeConstants Solid Edge Constants Type Library constant.tlb
"
Here is the link to the document: --> page. 11

http://www.plm.automation.siemens.com/zh_cn/Images/Solid_Edge_API_tcm78-125829.pdf

I hope this could help.

thx
gggustafson 23-May-14 13:07pm    
I have scanned the referenced document. One of the better ones I've seen. Have you gotten past the Getting Started examples of chapter 4 before you started with your code?

Note that all of the examples that I read included a try-catch block. You need to do the same. Surround your existing code in a try block and add a catch block as follows:

try
{
your existing code
}
catch ( Exception ex )
{
MessageBox.Show ( ex.Message + ex.StackTrace );
}

That way you will be informed where the error occurred. You may need to skip over the initial trace lines (they have to do with where the error was detected in the COM assemblies). Once identified, examine that line to see what you did wrong.

Code recommendations (Use the Improve Question link):

BOM usually stands for Byte Order Mark so choose a more meaningful name. See Identifier Spelling in http://www.codeproject.com/Articles/236430/Minimalist-Coding-Guidelines.

Fix your for statement. It should read for ( j = 0; ( j < i ); j++) then you don't need the ugly ( j - 1 ) stuff.

Remove all commented lines. They only add confusion. Also, get rid of totally meaningless comments. They tell the reader what you meant to do not what you did.

1 solution

Ok. Thx.

I'll try to use all your hinds and send my new Code after i changed it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900