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

STEP export using Partnumber for name instead of Filename

alexander.duell
Contributor

STEP export using Partnumber for name instead of Filename

alexander.duell
Contributor
Contributor

Hello,

 

I wonder if there is a possibility when exporting an STEP of an assembly, changing the name of all subassemblies, and parts to the "Part Number" property instead of the file name, perhaps using ilogic?

 

Must all subassemblies and parts be exported in order for this to work, or is there a possibility to solve this for the export of the top assembly?

 

See attached picture from an Exported step opened in NAVIS.

 

I hope you understand what I mean and would really appreciate help too this, 

 

Best Regards

Alexander Duell

0 Likes
Reply
Accepted solutions (1)
1,353 Views
5 Replies
Replies (5)

WCrihfield
Mentor
Mentor

Just to be clear:

  • Are you wanting to just export the main assembly as a single STEP file, or do you also want to export each sub assembly and sub-part, in all sub-layers, individually out to their own STEP files?
    • You know that when you export an assembly as a STEP file, that it includes all the sub-assemblies and sub-parts right?  And you know that when you open that STEP file in Inventor and click Save, it will re-populate a target folder with all those sub-assemblies and parts,  right?
  • Do you want all the components (and sub-components) within the assembly to still remain renamed  as their Part Numbers instead of their file names, after the export process is done, or do you want the original assembly (and all its sub-components) to remain named as they were originally (by file name)?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

alexander.duell
Contributor
Contributor

Hello,

 

Exporting the main assembly as a single step file.

 

I would like the components to have their partnumber instead of file name shown just for the export to STEP. In my inventor model i would like them still to have their original filenames. 

 

For examlpe we share our Inventor models to for infromation, then we do that as STEP files or NWD (NAVIS).

 

the STEP file are usedin ex. NAVIS my idea was to be able to connect/ see the relationship between the part/subassembly and partnumber  (drawingnumber) instead of filename, as my attachment showed. 

 

Perhaps this a bit more tricky than i anticipated. Or is there a way to manipulate the .STP file in the text editor?

 

I hope im making my self understood. 

 

Best Regards

Alexander Duell

 

 

0 Likes

WCrihfield
Mentor
Mentor

Yes. I believe I understand what you want now.

But like you said, it will be much more complicated to accomplish than it sounds.  Because there is no setting or option for that sort of thing when exporting to STEP.

So the solution code would need to include 'recursive' subroutine(s) that will dig down through all levels, and rename every component and sub-component, while somehow recording and keeping track of all their original component names, then run all the code to export the STEP, then go back through all levels of the assembly again attempting to set all their names back to what they were originally.

Another idea, would be to use a SaveAs or SaveCopyAs (just make sure you end up in the 'copied' version) to create a temporary copy of this top/main assembly, then do all the component name modifications to that copy, then export the STEP file, then delete the copied version of the assembly at the end, to avoid having to go back and rename them all, in all levels.  I know that component names are different from file names and part numbers, but I'm not 100% sure if this would permanently modify the component names within the sub-assemblies though, or if these changes would only effect the top assembly, so I would proceed with caution and maybe test on test files first, if proceeding to try this. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

I created an iLogic rule that will attempt to rename every component on every level of the assembly, to the component's Part Number.  And if there are multiple the same component within an assembly, it attempts to add the ":" and an Integer to the end of the component name.

Here's the code:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	
	'Start a Transaction to bundle all the name changes into a single item in the 'Undo' menu.
	Dim oTransaction As Transaction = ThisApplication.TransactionManager.StartTransaction(oADoc, "Rename Components")
		
	'rename all comps in top level first
	For Each oOcc In oADef.Occurrences
		RenameOcc(oOcc)
	Next
	'now try to rename comps at deeper levels
	For Each oOcc In oADef.Occurrences
		If oOcc.SubOccurrences.Count > 0 Then 'it is a sub-assembly
			'run 'recursive' sub here
			'and supply the SubOccurrences to it
			Iterate(oOcc.SubOccurrences)
		End If
	Next
	'end the Transaction
	oTransaction.End
End Sub

Sub RenameOcc(oComp As ComponentOccurrence)
	'create new variable to enable 'Intellisense' recognition
	Dim oCO As ComponentOccurrence = oComp
	'get the PN
	Dim oCODoc As Document = oCO.Definition.Document
	Dim oPN As String = oCODoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	'check if PN is empty (not filled in)
	If oPN = "" Or oPN = " " Then
		MsgBox("Occurrence '" & oCO.Name & "' has an 'Empty' Part Number." & vbCrLf & _
		"Leaving original component name as it was.", , "")
		'oPN = oCO.Name
		Exit Sub
	End If
	
	'attempt to rename the component
	Dim oWorked As Boolean = False
	Try
		oCO.Name = oPN
	Catch
		Dim oInt As Integer = 0
		Do Until oWorked = True
			oInt = oInt + 1
			Try
				oCO.Name = oPN & ":" & oInt
				oWorked = True
			Catch
				oWorked = False
			End Try
		Loop
	Catch
		MsgBox("Failed to rename:  " & oCO.Name,,"")
	End Try
End Sub

Sub Iterate(oOccs As ComponentOccurrencesEnumerator)
	'create new variable to enable 'Intellisense' recognition
	Dim oComps As ComponentOccurrencesEnumerator = oOccs
	Dim oCO As ComponentOccurrence
	'try to rename all comps at this level first
	For Each oCO In oComps
		RenameOcc(oCO)
	Next
	'now loop through again checking for SubOccurrences, then Iterate
	For Each oCO In oComps
		If oCO.SubOccurrences.Count > 0 Then 'it is a sub-assembly
			Iterate(oCO.SubOccurrences)
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

If you have time, please... Vote For My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

alexander.duell
Contributor
Contributor

Hello.

 

This is great it was what i was looking for!

 

Best Regards

0 Likes