Message 1 of 3
Copy an iProp to item number column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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