Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
in reply to: Anonymous

This github library makes it easy to work with content center and assemblies

https://github.com/HYMMA/InventorToolBox

 

 

 

//connect to inventor
var app = App.Start();

//generate file name
var partName = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "PartFileName.ipt");
var assyName =System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "AssemblyFileName.iam");
PartDocument part;
AssemblyDocument assembly;
//make a new part document or open it if already exists
            try
            {
                part = app.NewPart(partName);
            }
            catch (Exception)
            {
                part = app.Open(partName, false) as PartDocument;
            }

            //make a new assembly document or open it if already exists
            try
            {
                assembly = app.NewAssembly(assyName);
            }
            catch (Exception)
            {
                assembly = app.Open(assyName) as AssemblyDocument;
            }

//set the part number proprety of the part
part.AsDocument().SetProperty(kDocumnetProperty.PartNumber, "S/S6758");

//add the part that was created to the assembly
var partOccurance = assembly.AddMemeber(part.AsDocument(), new[] { 0d, 0d, 1d }, new[] { 10d, 10d, 0d });

var contentCenterDesc = new ContentCenterItemDescriptor(row: 3, "Structural Shapes", "Angles", "BS 4848"){ CustomValue = new KeyValuePair<string, object>("B_L", 658) };

var contentCenterOccurance = assembly.AddMemeber(contentCenterDesc, new[] { 0d, 0d, 1d }, new[] { 10d, 10d, 0d });