Anonymous
in reply to:
Anonymous
10-17-2021
11:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
10-17-2021
11:03 PM
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 });