API Help
EPLAN API / User Guide / API DataModel / Working with parts
In This Topic
    Working with parts
    In This Topic

    Analogous to other master data, all of the necessary information on parts required for independent work with a project are stored in the project itself. There are always two parts databases (redundant data management): the central parts database for all projects and the project's internal parts database, which only contains parts placed into the project. The central parts database (system parts) may either be an .mdb or an SQL database. The following image represents this situation: 

     

    Within a project, the parts from the parts project database are referenced, i.e., a part that is used 10 times - by a Function, a Connection, or as a project part by the project itself - is stored only once, and is referenced 10 times in the project (via the part number). Parts data can therefore be easily changed or synchronized via the central parts database. 

     

    How does it work in API ?                   

    In P8 API, the part, which is stored in the project's internal parts database, is represented by the Eplan.EplApi.DataModel.Article class. The reference to a particular part on a Function, a Connection or the Project, is represented by the Eplan.EplApi.DataModel.ArticleReference class. You can get the ArticleReference objects by the ArticleReferences property on the before-mentioned classes. 

    In order to add a new reference to a part, you can use the AddArticleReference methods on Project, Function, or Connection. Please mind, that AddArticleReference just adds the reference to a part which is already stored in a project. 

     

    In general, articles stored in a P8 project are created explicitly.Therefore you use the method void Article.Create(string partnr, string variant). This method creates an Article object. If there is already a part (Article) with that partnr and variant, an exception will be thrown. After calling the Create method the Article object is completely empty. Only part number and variant are set, but no other property is filled. 

    To fill an Article with properties of the master data please use the explicit function bool Article::LoadFromMasterdata. Using the current part data source, all (the configured) article data of the master data is loaded to the embedded part. If the article (partnr + variant) can't be found in the master data Article::LoadFromMasterdata will return false. On Success true is returned. 

     

    Adding Parts and referencing them

    Following example shows how to add and reference Article in Project, Function and Connection: 

    C#
    Copy Code
        Article oArticle = new Article();
        oArticle.Create(oProject, "KUKA.KR30-3", "1");            //empty Article is created in a Project
        bool bResult = oArticle.LoadFromMasterdata();             //Article is filled with data from system parts database
    
        oProject.AddArticleReference("KUKA.KR30-3", "1", 1);      //reference to the Article is created on a Project
        oFunction.AddArticleReference("KUKA.KR30-3", "1", 1);     //reference to the Article is created on a Function
        oConnection.AddArticleReference("KUKA.KR30-3", "1", 1);   //reference to the Article is created on a Connection