Copy an iProp to item number column

Copy an iProp to item number column

g.grajdeanu
Participant Participant
588 Views
2 Replies
Message 1 of 3

Copy an iProp to item number column

g.grajdeanu
Participant
Participant

Hello,

I am trying to do modify  a vba code  in order to copy an existing custom prop. in Item number column from BOM in  each assembly.

In my mind will be like this:

1-Open ref doc (only those who have SBG or ET at stock number),

2 - copy Position to item number 

3-save and close

(Silent runs for everyone)

 

I have part of code listed below if someone able to help me.

 

Sub Main()

    doc = ThisDoc.Document
	
    Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
    Dim oBOM As BOM = oAssyDef.BOM

    oBOM.StructuredViewEnabled = True

	oBOM.StructuredViewFirstLevelOnly = True

    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")

    Dim oBOMRow As BOMRow
    Dim oCompDef As ComponentDefinition

    For Each oBOMRow In oBOMView.BOMRows

      oCompDef = oBOMRow.ComponentDefinitions.Item(1)
      
      Call SetRowProps(oCompDef, oBOMRow.ItemNumber)
      
      If Not oBOMRow.ChildRows Is Nothing
          Call RecurseBOMRow(oBOMRow)
      End If
    Next
	
	oBOM.StructuredViewFirstLevelOnly = False

'	MessageBox.Show("Completed!", "iLogic",)
	
End Sub

Sub RecurseBOMRow(oBOMRow As BOMRow)
   For Each oBOMRow In oBOMRow.ChildRows
     Dim oCompDef As ComponentDefinition
     oCompDef = oBOMRow.ComponentDefinitions.Item(1)

     Call SetRowProps(oCompDef, oBOMRow.ItemQuantity)

     If Not oBOMRow.ChildRows Is Nothing
          Call RecurseBOMRow(oBOMRow)
     End If
   Next
End Sub

Sub SetRowProps(oCompDef As ComponentDefinition, Stückzahl As String)
 Dim CompFullDocumentName As String = oCompDef.Document.FullDocumentName
 Dim CompFileNameOnly As String
 Dim index As Integer = CompFullDocumentName.LastIndexOf("\")
 
 CompFileNameOnly = CompFullDocumentName.Substring(index + 1)
 
 Dim indexFileExt As Integer = CompFileNameOnly.LastIndexOf(".")
 
 CompFileNameExtension = CompFileNameOnly.Substring (indexFileExt +1)
 
'MessageBox.Show(CompFileNameExtension, "CompFileNameExtensionn")
	
If CompFileNameExtension = "iam" Then
	
' MessageBox.Show(CompFileNameOnly,Position)

Dim File_Attr As Long

File_Attr = System.IO.File.GetAttributes(CompFullDocumentName)

If File_Attr = 1 Or File_Attr = 33 Then

'	MsgBox("the file is Read only")

 Else	


	Position = iProperties.Value(CompFileNameOnly, "Inventor User Defined Properties", "Position")
	
Dim StockNumber As String
Dim PartName As String

StockNumber = iProperties.Value(oBaseName,"Project", "Stock Number")

PartName = iProperties.Value(oBaseName, "Project", "Part Number")
If (oBaseExtension = ".ipt") Then
		
		oNoOfIptFiles += 1
            		
		If StockNumber <> "PT" And StockNumber <> "BL" Then
	
				End
		
		Else
			
		End If
		
	Else
		
		If (oBaseExtension = ".iam") Then
			
			oNoOfIamFiles += 1
			
			If StockNumber <> "BG" And StockNumber <> "SBG" And StockNumber <> "ET" Then
		
				GoTo NoW4Comp
			
			Else
			
			End If


 	 
 
End If

 
Else
	
End If
 
End Sub

 

 

0 Likes
589 Views
2 Replies
Replies (2)
Message 2 of 3

g.grajdeanu
Participant
Participant
LE:
I tryed to split the code:
'Copy item number from BOM parts view to an iproperty in each component
'iproperty is named 'Position'
'assumptions:
'active doc is assembly
'LOD is master

Dim oAssDoc As AssemblyDocument
Dim oAssDef As AssemblyComponentDefinition
Dim oBOM As BOM
Dim oCompDef As ComponentDefinition
Dim oCustomProps As PropertySet
Dim oBOMNoProperty As Inventor.Property
Dim sItemNo As String
Const sPropName As String = "Position"

oAssDoc = ThisDoc.Document
oAssDef = oAssDoc.ComponentDefinition
oBOM = oAssDef.BOM

oBOM.StructuredViewEnabled = True

oBOM.StructuredViewFirstLevelOnly = True

Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")

For Each oBOMRow In oBOMView.BOMRows
oCompDef = oBOMRow.ComponentDefinitions(1)
sItemNo = oBOMRow.ItemNumber
oCustomProps = oCompDef.Document.PropertySets("User Defined Properties")
Try
oBOMRow.ItemNumber = oCustomProps.Item(sPropName)
'oBOMRow.ItemNumber = sItemNo
Catch
oBOMRow.ItemNumber = iProperties.Value(CompFileNameOnly, "Inventor User Defined Properties", "Position") = Position
End Try
Next
0 Likes
Message 3 of 3

g.grajdeanu
Participant
Participant
Hello,

I did some research and i did find this post.

https://forums.autodesk.com/t5/inventor-customization/how-to-override-bom-itemnumber-without-parent-...

Based on it , is not posible, in 2021 to copy a custom prop into Item number column ?
Can anyone help me with this?


Dim Pos As String
Pos = oBOMRowPO.ItemNumber

iProperties.Value(CompFileNameOnly, "Custom", "#Pos") = Pos
0 Likes