Yes! This is the problem with CAD neutral formats. For my files I make subassemblies which helps reduce the load times. If you know which parts are instances you can use the same AD_PRT file when inserting them into a AD_ASM. This requires some work and can be solved several ways. The standoffs you have highlighted could be made into instances by using one for each of the other matching parts. So au72x4018blp_23<1> would be used in 6 places; au72x4018blp_23<6>.
Using headless mode you could match parts based on their volume, bounding box or topology. The tricky part is that this only works if they are unique in size and shape. Parts might have left and right part numbers, for general usage it may work fine.
I'm trying to find solutions with the API. Here is a work in progress program that will allow you to view and save as to rename a part file and insert it into a new assembly. This works but has issues I need to fix. The code can be expanded to replace components. The transforms would need to be applied to the instanced parts so they are in the correct place. This version is different from the other example I posted. In this version a new assembly is made and the renamed part files are added to the new assembly. You can review the part files before commiting to a new name and skip a component altogether.
Code:
Public Session As IADSession
Public AssemblySession As AlibreX.IADAssemblySession
Public NewAssemblySession As IADAssemblySession
Public newSession As IADSession
Public Hook As IAutomationHook
Public Root As IADRoot
Sub Main()
Try
Hook = GetObject(, "AlibreX.AutomationHook")
Root = Hook.Root
Dim WorkingDir = "C:\Users\steph\Desktop\0\2"
For Each item In Directory.GetFiles(WorkingDir)
Dim fileInfo As New FileInfo(item)
If fileInfo.Extension = ".AD_ASM" Then
Root.OpenFile(item)
Thread.Sleep(TimeSpan.FromSeconds(0.2))
Session = Root.TopmostSession
AssemblySession = Session
AssemblySession.AutoRegenerate = True
newSession = Root.CreateEmptyAssembly("NewAssembly-001")
NewAssemblySession = CType(newSession,IADAssemblySession)
Console.WriteLine(AssemblySession.Name)
For Each item2 As IADOccurrence In AssemblySession.ActiveOccurrence.Occurrences
item2.ParentAssemblySession.ConstituentFilePaths.Clear()
item2.DesignSession.ConstituentFilePaths.Clear()
Dim UpdateName = InputBox("New Name?", item2.name)
If UpdateName = ""
Console.WriteLine(item2.name & ": skipped")
Else
Console.WriteLine(item2.name & " changed to " & UpdateName)
item2.DesignSession.SaveAs(WorkingDir, UpdateName)
Dim RootOccurrence As AlibreX.IADOccurrence
RootOccurrence = NewAssemblySession.RootOccurrence()
Dim NewAssemblyOccurrences As AlibreX.IADOccurrences
NewAssemblyOccurrences = RootOccurrence.Occurrences()
Dim GeometryFactory As AlibreX.IADGeometryFactory
GeometryFactory = newSession.GeometryFactory
Dim Transformation As AlibreX.IADTransformation
Dim TransformationArrayData(15) As Double
TransformationArrayData(0) = 1
TransformationArrayData(1) = 0
TransformationArrayData(2) = 0
TransformationArrayData(3) = 0
TransformationArrayData(4) = 0
TransformationArrayData(5) = 1
TransformationArrayData(6) = 0
TransformationArrayData(7) = 0
TransformationArrayData(8) = 0
TransformationArrayData(9) = 0
TransformationArrayData(10) = 1
TransformationArrayData(11) = 0
TransformationArrayData(12) = 0
TransformationArrayData(13) = 0
TransformationArrayData(14) = 0
TransformationArrayData(15) = 1
Transformation = GeometryFactory.CreateTransform(TransformationArrayData)
Dim filepath = Path.Combine(WorkingDir, UpdateName & ".AD_PRT")
Console.WriteLine(filepath)
Dim NewPartOccurrence As AlibreX.IADOccurrence
NewPartOccurrence = NewAssemblyOccurrences.Add(filepath, Transformation)
NewPartOccurrence.IsAnchored = True
Console.WriteLine(NewPartOccurrence.Name)
End If
Next
AssemblySession.RegenerateDesign(True)
AssemblySession.SaveAll(WorkingDir)
End If
Next
Catch ex As ArgumentException
MsgBox(ex.Message)
Finally
Hook = Nothing
Root = Nothing
Session = Nothing
AssemblySession = Nothing
End Try
End Sub
Because all my tools are built around custom code and now Rhino 8 I haven't spent much time finding a true solution with the Alibre API. The code I shared in this thread is a starting point.
I almost forgot something:
When you open a step file that has only one body/lump, Alibre will use the file name as the part name for example McMaster Carr parts:
This is why I export bodies with the correct part name as individual files (one body step files) before I insert them inside of an assembly.
The csv file could have this information and can include the assembly files and other data:
Part File,Insertion Point/Transform, New Part File, New Insertion Point/Transform
C:\Users\steph\Desktop\0\Solid558.AD_PRT, xyz, C:\Users\steph\Desktop\0\Part-0001.AD_PRT, xyz
C:\Users\steph\Desktop\0\Solid550.AD_PRT, xyz, C:\Users\steph\Desktop\0\Part-0001.AD_PRT, xyz
C:\Users\steph\Desktop\0\Solid530.AD_PRT, xyz, C:\Users\steph\Desktop\0\Part-0001.AD_PRT, xyz
C:\Users\steph\Desktop\0\Solid533.AD_PRT, xyz, C:\Users\steph\Desktop\0\Part-0001.AD_PRT, xyz