What's new

How to rename parts within a STP file Assembly

PaulProe

Senior Member
I just imported an assembly saved as a STP file and converted it to an Alibre Assembly. It has 240+ parts in it.

Has Alibre (or this group) come up with a method to rename each of the components, short of going in and manually changing each part name then replacing each part when the assembly opens and the part is not found

Surely there's a simpler way that I'm not aware of

Thanks

Paul
 

Mibe

Alibre Super User
I just imported an assembly saved as a STP file and converted it to an Alibre Assembly. It has 240+ parts in it.

Has Alibre (or this group) come up with a method to rename each of the components, short of going in and manually changing each part name then replacing each part when the assembly opens and the part is not found

Surely there's a simpler way that I'm not aware of

Thanks

Paul

When you use "Save as" you can rename each part individually in the list before re-saving the assembly. No need to do this one by one. Or did I misunderstand your workflow?
 

Toybuilder

Senior Member
This is what I do -- but the Save As dialog does not maintain the tree order of the assemblies and parts so that it can sometimes get very difficult to figure out what item I am renaming is. I wish there was a way to either do it in the part tree or have some way to otherwise be able to more easily keep track of what is being saved.
 

HaroldL

Alibre Super User
I've had to rename parts for a STEP assembly on occasion. The steps I've taken were to first highlight/select the items in the Design Explorer and locate them in the model. As I select the items and once I know what and where they are I make a separate list (on paper) of the items. Then when I am using Save As it is easier to rename the items. Some things you need to be aware of and account for is that some items in the STEP are called out by their feature name, like Mirror or Fillet, or with a numbered name of the top level. With multiples of those items you should only rename one then rebuild the assembly after the renaming is done and replace the multiples or patterned items with the renamed item. It can be really time consuming but in the end you have a more streamlined assembly.

One more thing that can mess you up -- all original sub assemblies are likely lost so if you want or need them, well - you'll have your work cut out for you.
 

stepalibre

Alibre Super User
Hello @PaulProe

I deal with this on a regular basis. I made tools to help with this. One issue is that when you do the first import and save the parts the thumbnails are not generated so you don't know what the file looks like in explorer.

You see this:
1709967981788.png
Instead of this:
1709968022915.png

I have a program that simply opens and closes the file so the thumbnail is generated. I then use the thumbnail to help me during the rename step.

This program open files and allow me to quickly save as. It will automatically close after I click OK to rename or Cancel to skip that part. It loops through every part file in the working directory.

Code:
Public Session 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"
        For Each item In Directory.GetFiles(WorkingDir)
            Dim fileInfo As New FileInfo(item)
            If fileInfo.Extension = ".AD_PRT" Then
                Root.OpenFile(item)
                Thread.Sleep(TimeSpan.FromSeconds(0.3))
                Session = Root.TopmostSession
                Dim UpdateName = InputBox("Update Name",fileInfo.name)
                If UpdateName = ""
                    Session.Close()
                    Console.WriteLine(fileInfo.name & ": skipped")
                Else
                Console.WriteLine(fileInfo.name & " changed to " & UpdateName & ".AD_PRT")
                    Session.SaveAs(WorkingDir, UpdateName)
                    Session.Close()
                End If      
            End If
        Next
    Catch ex As ArgumentException
        MsgBox(ex.Message)
    Finally
        Session = Nothing
        Hook = Nothing
        Root = Nothing
    End Try
End Sub

The save as location can be different, in this example the location is the same.

And then a script to import the renamed files inside a new assembly:

Python:
from AlibreScript import *
import os

# Assembly initialization
Asm = Assembly("new-of-assembly")

# Folder containing the parts
parts_folder = r'C:\Users\steph\Desktop\0\1'

# List all files in the parts folder
for filename in os.listdir(parts_folder):
    full_path = os.path.join(parts_folder, filename)
    # Check if the file is a part file (e.g., .AD_PRT)
    if full_path.lower().endswith('.ad_prt'):
        # Add the part, located at the origin
        NewPart = Asm.AddPart(full_path, 0, 0, 0, 0, 0, 0, True)
        Asm.AnchorPart(NewPart)

Asm.Save(parts_folder)
Asm.Close()

The parts are inserted as is without any placement because the positions are baked into the imported step file.

This could all happen in Alibre Script but I find it too slow for the entire task. There is also more to this process that is done in C# and VB, I use Alibre Script whenever it fits the task this use is a good example. The overall process is slow and 240+ parts will take a while. I would use a csv file for larger assemblies instead of renaming one by one and/or headless mode. You can also pick out the parts that you want to rename by searching for them inside a loop. If the topology is simple it might not take long to process, however the more complex the topology the longer Alibre will take to open and save them.

edit:
I would use a csv file for larger assemblies instead of renaming one by one. Headless mode would be much faster but you'll need a way to identify the parts, you could use the thumbnails. The step files I import into Alibre (lately) I create in Rhino or in my custom tools so it's easy for me to identify each part and rename them with csv files.

If it's possible to extract the parts you want using another application before you open the file in Alibre that would also help the process. I use MoI3D to delete models from a iges, step or 3dm file before I open the file inside Alibre.
 
Last edited:

stepalibre

Alibre Super User
You don't need to use a separate file for the data, such as txt, csv, xls, or json. In general I do so to ensure a repeatable process and for reports and an audit trail.
 

stepalibre

Alibre Super User
@PaulProe I'll revisit the API, It was really slow trying to rename a part from inside the assembly using the occurrences APIs which is why I don't use it.
Hello Paul,

is there a rule you are using for renaming? like "myrenamed_step_part_"+ an increasing number like 1, 2, 3 ... up to 240? and what is the purpose for the new names?

Regards
Stefan
I think he's referring to Alibre's default naming of parts generated by Alibre on opening a step file. It will be sequential number but the name it adds is not consistent. It would be Solid<seq-number> or Solid1, Soild2 and so on, I use a csv file to rename them based on this information.
 

stepalibre

Alibre Super User
In my case I know what the new names (the actual names) should be because I made it. If you have a parts list or a BOM for the assembly then you'll use that or your own names to identify important parts. I do this whenever importing from suppliers but only rename parts I need to easily find, some assemblies are up to 1000 parts.
 

stepalibre

Alibre Super User
@idslk your question about the naming is what I often fight myself over. I hate to work with files named Solid495.AD_PRT, but it is often acceptable to leave as is, until you need to add it to a document or package.
 

HaroldL

Alibre Super User
@stepalibre, how do you handle multiples of parts in an assembly, like patterns of fasteners or standoffs, which could account for many of the total number of parts in the STEP file from a supplier?

Here's an example of a few standoffs:
1710023628758.png

Renaming only one of them, then replacing the pattern in a rebuilt assembly is a lot of manual work but does reduce the number of parts needed to be renamed.
 

stepalibre

Alibre Super User
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.

1710030559748.png


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
 

HaroldL

Alibre Super User
I don't have access to SolidWorks since I retired but I recall that the same issue existed with SW when importing large STEP assemblies. Neutral formats are great for single part files that need to be referenced or modified but multi-part assemblies are a real treat. I don't recall SW having any "special" tools to handle the renaming issues so many of them just got place holder names when checking the file in to the Enovia vault system.
 

stepalibre

Alibre Super User
Yes, I have SolidWorks(2014) and Solid Edge(2024), this is indeed a common challenge. Other CAD packages have tools to help rename, replace and make parts and assemblies lightweight to reduce compute times.
 

DavidJ

Administrator
Staff member
Multiple parts are easier to deal with once the assembly is open - use 'replace', or if it's obvious how the items are arranged using an assembly pattern may be quicker.
 

bolsover

Senior Member
I just imported an assembly saved as a STP file and converted it to an Alibre Assembly. It has 240+ parts in it.

Has Alibre (or this group) come up with a method to rename each of the components, short of going in and manually changing each part name then replacing each part when the assembly opens and the part is not found

Surely there's a simpler way that I'm not aware of

Thanks

Paul
Interesting problem and one I considered when working on a 'Data Browser' (see Utilities for Alibre). I wanted a way of giving all my files consistent part numbers but did not want to go through all the files numbering individually. There is some more information on the part numbering feature here.. Data Browser. I did consider providing some sort of Part Rename feature - but as far as I know, this would break links in an assembly - so did not implement.
David
 

stepalibre

Alibre Super User
The reason I "save as" (to rename a component) and then insert the renamed parts into a new assembly is because I couldn't find a function to do so inside the assembly (in-place). You cannot rename a part that's in use inside an assembly. You can save as to rename and then add that renamed part into the CurrentAssembly(), however the performance was brutally slow for STEP files converted to Alibre parts, experiences may vary.

Breaking links is fine as long as you store the paths from the ConstituentFilePaths object. You could then reconstruct the assembly yourself. For STEP assemblies I generate the AD_PRT files, then split them up into sub-assemblies.

Renaming Alibre parts/assemblies is not a simple task because they could be used in other places and the system won't allow it. You have to traverse every assembly that reference the file and update them or they will be broken. I create new assemblies and insert the newly renamed parts along with the rest of the assembly files. Traversing assemblies to find and replace/rename parts is exactly what happens in a PDM system. You scan the database for places where that file is being used and replace it everywhere or make a new revision leaving the rest as-is. You must always update potential references as a step in the rename/replace process. Often when you need to replace/rename a file, this would trigger a revision on the assembly even for one to one substitutions. This is not important to this thread but is related to how things may work and is related to this conceptually.

STEP assemblies:
A simpler solution is to use another program (if you have one) that allow renaming of bodies/solids while preserving the names on export to STEP or IGES. This is what I'm automating.

1710123212854.png
1710123225592.png


Edit:
Saving a file under a new name (rename/replace) to add into a new assembly won't carry over assembly features such as constraints and patterns. This would need to happen before any assembly features are created.
 
Last edited:

stepalibre

Alibre Super User
@stepalibre, how do you handle multiples of parts in an assembly, like patterns of fasteners or standoffs, which could account for many of the total number of parts in the STEP file from a supplier?
Rhino and moi3d is used to group the parts into subassemblies. As a general rule I union as much of the assembled parts as I can to help simplify the file. I don't know if it matters that much to turn multiples into instances in every case. Using subassemblies works well in my projects. This all depends on the complexity of the parts and assemblies and how you plan to use them in your projects. Because the imported STEP geometry is using world space coordinates you can't simply swap them out. You would need to transfer the world space coordinates from the originals to each instance. I do this using Rhino. You could do what @DavidJ suggested use assembly patterns and other assembly tools to replace them. I want an automated workflow.
 

HaroldL

Alibre Super User
Multiple parts are easier to deal with once the assembly is open - use 'replace', or if it's obvious how the items are arranged using an assembly pattern may be quicker.

You could do what @DavidJ suggested use assembly patterns and other assembly tools to replace them.

I think that's what I indicated was done.

Renaming only one of them, then replacing the pattern in a rebuilt assembly is a lot of manual work but does reduce the number of parts needed to be renamed.
 
Top