C# create a new product with a specific name

Martin Janus

C# create a new product with a specific name

Hi,

 

So I'm fairly new with the CATIA V5 libraries (couldn't find any official documentation, if you know some please let me know so I can study it)

 

What I'm trying to achieve is to simplify working with standards at work, and I'm creating a program that will stitch the name and either create a file or insert directly to catia.

Thing is, I found some codes that do this, however none of them are working for me, I've read on this forum that the library type is also strict to which catia version I'm using, is that true?

 

Here's the method I want to use:

 

using System;
using ProductStructureTypeLib;
using Microsoft.VisualBasic;
using Application = INFITF.Application;
namespace CATFR
{
public class Insert
{
public static void InsertNewProduct(string productName)
{
Application catia;
try
{
catia = (Application)Interaction.GetObject(Class: "CATIA.Application");
}
catch (Exception)
{
catia = (Application)Interaction.CreateObject("CATIA.Application");
}
// create new product using productName as name
var newProduct = (ProductDocument)catia.Documents.Add("Product");
newProduct.Product.Products.AddNewProduct(productName);
}
}
}

 

This is a separate project from the main that runs at Framework 4.8, main runs at .NET Core 6.0

 

any help or links would be appreciated,

 

Thanks