filename without extension in the BOM

filename without extension in the BOM

eladm
Collaborator Collaborator
2,552 Views
17 Replies
Message 1 of 18

filename without extension in the BOM

eladm
Collaborator
Collaborator

Hi All

I need to add file name column in BOM / Part list . The default is with the file extension ipt/iam

I need only the file name 

this rule:

File_Name = iProperties.Value("Project", "Part Number")
    
 iProperties.Value("Custom", "File Name" ) = Split(File_Name, ".")(0)

 create iproperties in the main file with my goal ,

How I can run this code from the assembly to all the parts and sub-assembly

best regards

0 Likes
2,553 Views
17 Replies
Replies (17)
Message 2 of 18

bradeneuropeArthur
Mentor
Mentor

You don't need coding for this.

Create a user defined property

FileName   with =<Part Number>

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 18

eladm
Collaborator
Collaborator

Hi

Part number not equal to file name

0 Likes
Message 4 of 18

bradeneuropeArthur
Mentor
Mentor

how does your partnumber look like.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 18

eladm
Collaborator
Collaborator

After save the file I change the part number field to other value , not all the file (bolts for example) but the part number is change

regards

0 Likes
Message 6 of 18

bradeneuropeArthur
Mentor
Mentor

Hi,

For VBA:

Public Sub main()
Dim a As Application
Set a = ThisApplication

Dim b As AssemblyDocument
Set b = a.ActiveDocument
loopass (b)
End Sub

Public Sub loopass(b As AssemblyDocument)


Dim o As ComponentOccurrence
Dim doc As Document
Dim c As PartDocument
Dim File_Name As String
Dim FileName As String

For Each o In b.ComponentDefinition.Occurrences
MsgBox o.Name
doc = o.Definition.Document

File_Name = doc.PropertySets.Item(3).Item("Part Number").Value

If doc.DocumentType = kPartDocumentObject Then
On Error Resume Next
doc.PropertySets.Item(4).Add Split(File_Name, ".")(0), "File Name"

doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0)
ElseIf doc.DocumentType = kAssemblyDocumentObject Then
On Error Resume Next doc.PropertySets.Item(4).Add Split(File_Name, ".")(0), "File Name" doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0) loopass (doc) End If o.Definition.Document Next End Sub

For i-logic:

Public Sub main()
Dim a As Application
a = ThisApplication

Dim b As AssemblyDocument
b = a.ActiveDocument
loopass (b)
End Sub

Public Sub loopass(b As AssemblyDocument)


Dim o As ComponentOccurrence
Dim doc As Document
Dim c As PartDocument
Dim File_Name As String
Dim FileName As String

For Each o In b.ComponentDefinition.Occurrences
MsgBox o.Name
doc = o.Definition.Document

File_Name = doc.PropertySets.Item(3).Item("Part Number").Value

 

If doc.DocumentType = kPartDocumentObject Then

try

doc.PropertySets.Item(4).Add (Split(File_Name, ".")(0), "File Name")

Catch exception


doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0)

end try


ElseIf doc.DocumentType = kAssemblyDocumentObject Then

try

doc.PropertySets.Item(4).Add (Split(File_Name, ".")(0), "File Name")

catch exception

doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0)
end try
loopass (doc)
End If

o.Definition.Document
Next

End Sub

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 18

eladm
Collaborator
Collaborator

Hi , sorry  ,I-logic not working

1515.PNG

0 Likes
Message 8 of 18

bradeneuropeArthur
Mentor
Mentor
Public Sub Main()
Dim a As Application
 a = ThisApplication

Dim b As AssemblyDocument
 b = a.ActiveDocument
loopass (b)
End Sub

Public Sub loopass(b As AssemblyDocument)


Dim o As ComponentOccurrence
Dim doc As Document
Dim c As PartDocument
Dim File_Name As String
Dim FileName As String

For Each o In b.ComponentDefinition.Occurrences

doc = o.Definition.Document

File_Name = doc.PropertySets.Item(3).Item("Part Number").Value

If doc.DocumentType = kPartDocumentObject Then
'MsgBox(doc.PropertySets.Item(4).Item("File Name").Value)
doc.PropertySets.Item(4).Add (Split(File_Name, ".")(0), "File Name")
On Error Resume Next
doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0)
ElseIf doc.DocumentType = kAssemblyDocumentObject Then
doc.PropertySets.Item(4).Add (Split(File_Name, ".")(0), "File Name")

doc.PropertySets.Item(4).Item("File Name").Value = Split(File_Name, ".")(0)
On Error Resume Next
loopass (doc)
End If


Next
 
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 9 of 18

eladm
Collaborator
Collaborator

Hi

The result is part number , I need the file name

the file ilogic_test.ipt have part number eeee , the result of the rule is part number

Capture.PNG

 

if part added to the assembly or the part number changed , run rule failed

Error in rule: Rule0, in document: Assembly1

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Message 10 of 18

bradeneuropeArthur
Mentor
Mentor

Hi,

 

You gave us this:

 

File_Name = iProperties.Value("Project", "Part Number")
    
 iProperties.Value("Custom", "File Name" ) = Split(File_Name, ".")(0)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 11 of 18

eladm
Collaborator
Collaborator

Hi

 

Sorry , it was just of an example i found in the internet, the goal is too get a column in BOM of filename without extension and some of the files the file name and part number is not equal

best regards

0 Likes
Message 12 of 18

bradeneuropeArthur
Mentor
Mentor

Hope that this is what you need.

Are you a bit familiar with coding?

 

Public Sub Main()
Dim a As Application
 a = ThisApplication

Dim b As AssemblyDocument
 b = a.ActiveDocument
loopass (b)
End Sub

Public Sub loopass(b As AssemblyDocument)


Dim o As ComponentOccurrence
Dim doc As Document
Dim c As PartDocument
Dim File_Name As String
Dim FileName As String

For Each o In b.ComponentDefinition.Occurrences

doc = o.Definition.Document

'File_Name = doc.FileName(False)

If doc.DocumentType = kPartDocumentObject Then
'MsgBox(doc.PropertySets.Item(4).Item("File Name").Value)
doc.PropertySets.Item(4).Add (doc.FileName(False), "File Name")
On Error Resume Next
doc.PropertySets.Item(4).Item("File Name").Value = doc.FileName(False)
ElseIf doc.DocumentType = kAssemblyDocumentObject Then
doc.PropertySets.Item(4).Add (doc.FileName(False), "File Name")

doc.PropertySets.Item(4).Item("File Name").Value = doc.FileName(False)
On Error Resume Next
loopass (doc)
End If


Next
 
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 13 of 18

eladm
Collaborator
Collaborator

Hi

I know only basic thing

the code not working

Error in rule: Rule0, in document: del.iam

Public member 'FileName' on type 'PartDocument' not found.

0 Likes
Message 14 of 18

tonythm
Advocate
Advocate

Hello,

 

Please try for VBA:

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

       oDoc.DisplayName

 

If you get full file name, please try: oDoc.FullFileName

 

 

0 Likes
Message 15 of 18

k14348
Advocate
Advocate

Hi,

    Hope your issue resolved.

 

-Karth

Option Explicit

Sub CustomProp()
    
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oRefDoc As DocumentsEnumerator
    Set oRefDoc = oDoc.AllReferencedDocuments
    
    Dim oPartDoc As PartDocument
    Dim i As Integer
    For i = 1 To oRefDoc.Count

    Dim oDisp As String
    oDisp = oRefDoc.Item(i).DisplayName
    
    Dim textValue As Variant
    textValue = oDisp
    Dim oFile As String
    oFile = "FileName"
    
    Dim oCProp As PropertySet
    Set oCProp = oRefDoc.Item(i).PropertySets.Item("Inventor User Defined Properties")
    
    Dim oProp As Property
    Set oProp = oCProp.Add(textValue, oFile)
    Next
    
End Sub
0 Likes
Message 16 of 18

WCrihfield
Mentor
Mentor

Here is the short & simple code I use for this in an external iLogic rule.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCustPropSet As PropertySet
Dim oPropName As String = "File Name Without Extension"
Dim oPropValue As String
Dim oExists As Boolean = False
Dim oProp As [Property]
For Each oRefDoc As Inventor.Document In oADoc.AllReferencedDocuments
	oCustPropSet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
	oPropValue = IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
	For Each oProp In oCustPropSet
		If oProp.Name = oPropName Then oExists = True
		oOverwrite = MsgBox("Property already exists. Overwrite its value?", vbYesNo + vbQuestion, "PROPERTY EXISTS")
		If oOverwrite = vbNo Then Return
		oProp.Value = oPropValue
	Next
	If oExists = False Then
		oProp = oCustPropSet.Add(oPropValue, oPropName)
	End If
Next

You can put this external iLogic rule in the Event Triggers dialog / Assemblies tab / Before Save Document (and/or under Any Model parameter Change, if they effect which components are present.)  Then those properties will always be available in your assemblies, right after you click save.  Then all you have to do is open your BOM, then click the "Add Custom iProperty Column", and select this new property.  Or you can simply save this BOM columns customization within your Assembly template file.

Hope this helps.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 18

WCrihfield
Mentor
Mentor

Correction:  a line of code didn't get copied over when I posted before.

Also, it it seems some folks may have trouple with the two question lines, so I added an additional declaration to help cover that possible error.

You'll also notice that I commented out the question lines (that's how I usually use it), because it's really annoying when you have a ton of components in the assembly, and you don't care if it overwrites that data.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCustPropSet As PropertySet
Dim oPropName As String = "File Name Without Extension"
Dim oPropValue As String
iProperties.Value("Custom",oPropName) = IO.Path.GetFileNameWithoutExtension(oADoc.FullFileName)
Dim oExists As Boolean = False
Dim oProp As [Property]
Dim oOverwrite As MsgBoxResult
For Each oRefDoc As Inventor.Document In oADoc.AllReferencedDocuments
	oCustPropSet = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
	oPropValue = IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
	For Each oProp In oCustPropSet
		If oProp.Name = oPropName Then oExists = True
'		oOverwrite = MsgBox("Property already exists. Overwrite its value?", vbYesNo + vbQuestion, "PROPERTY EXISTS")
'		If oOverwrite = vbNo Then Return
		oProp.Value = oPropValue
	Next
	If oExists = False Then
		oProp = oCustPropSet.Add(oPropValue, oPropName)
	End If
Next

If this solves your problem, or answers your question, please click 'Accept As Solution'.

Or if this helps anyone out, towards reaching your goals, pleas click 'Likes' 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 18 of 18

maxim.teleguz
Advocate
Advocate
c = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select component")

If c Is Nothing Then
		Exit Sub
	Else
		'get the path and file name of the selected item
		d = Component.InventorComponent(c.name).Definition.Document.FullFileName
		f = IO.Path.GetFileNameWithoutExtension(d)
		MsgBox(f)
		'exit sub
	End If

this should solve it for everyone going forward, the easiest way possible

0 Likes