SAVING FILES BASED ON ITEM NUMBER IN PARTSLIST?

SAVING FILES BASED ON ITEM NUMBER IN PARTSLIST?

michael.bouwer
Contributor Contributor
264 Views
0 Replies
Message 1 of 1

SAVING FILES BASED ON ITEM NUMBER IN PARTSLIST?

michael.bouwer
Contributor
Contributor

hi

we had a rule created for us that numbers view  and indicates which sheet the detail is on in the parts list
i would like this rule to save the part files into another folder and have them numbered

could some one please help
at the moment it'll open the correct part but not save it

i added the "mykdoc" parts

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document
Dim oSheet As Sheet
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisDrawing.ModelDocument
Dim oPartsList As PartsList
oPartslist=oDrawDoc.Sheets.Item(1).PartsLists.Item(1)
SheetIndexMax = oDrawDoc.sheets.count
SheetIndex = 1
dim mykdoc as document

On Error Resume Next

'Clear REF column

     BOMcolumnindex=1
    BOMcolumnindexMax=oPartslist.partslistcolumns.count
    Do While BOMcolumnindex<BOMcolumnindexMax+1
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="REF." Then
    oColumnREF=BOMcolumnindex
    BOMcolumnindex = BOMcolumnindexMax
    End If
    BOMcolumnindex=BOMcolumnindex+1
    Loop

    BOMIndex=1
    BOMIndexMax=oDrawDoc.Sheets.Item(1).PartsLists.Item(1).partslistrows.count
    Do While BOMIndex<BOMIndexMax+1
    oPartslist.Partslistrows.item(BOMIndex).item(oColumnREF).Value = "-"
    BOMIndex=BOMIndex+1
    Loop

Do While SheetIndex<SheetIndexMax+1
oSheet=oDrawDoc.Sheets.Item(SheetIndex) 'Define the sheet we are working with
    If oSheet.DrawingViews.count=0 Or oDrawDoc.Sheets.Item(1).PartsLists.count=0 Then 'If there are no drawingviews or no partslists on the sheet then do nothing
    Else
        ViewIndexMax=oSheet.Drawingviews.count 'Count how many views are on the sheet
        ViewIndex=1
        BOMIndexMax=oDrawDoc.Sheets.Item(1).PartsLists.Item(1).partslistrows.count 'Count how many rows there are in the partslist
  
      
    BOMcolumnindex=1
    BOMcolumnindexMax=oPartslist.partslistcolumns.count
    Do While BOMcolumnindex<BOMcolumnindexMax+1
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="DESCRIPTION" Then
    oColumnDescription=BOMcolumnindex
    End If
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="QTY" Then
    oColumnQTY=BOMcolumnindex
    End If
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="LENGTH" Then
    oColumnLENGTH=BOMcolumnindex
    End If
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="ITEM" Then
    oColumnITEM=BOMcolumnindex
    End If
    If oPartslist.partslistcolumns.item(BOMcolumnindex).Title="REF." Then
    oColumnREF=BOMcolumnindex
    End If
    BOMcolumnindex=BOMcolumnindex+1
    Loop
  
            Do While ViewIndex<ViewIndexMax+1 'Loop through all the views
                    If oSheet.Drawingviews.item(ViewIndex).parentview Is Nothing Then 'This line looks for a baseview, because if a view has a parent then it is not a base view
                       If oSheet.Drawingviews.item(ViewIndex).ReferencedDocumentDescriptor.ReferencedDocumentType = 12290 Then
                    oPartDocNameSheet = oSheet.Drawingviews.item(ViewIndex).ReferencedDocumentDescriptor.FullDocumentName 'Looks for the assembly/part filename that the view is made from
                    mykdoc = oPartDocNameSheet
					BOMIndex = 1
                    BOMItemfound = 0
                        Do While BOMIndex<BOMIndexMax+1 'cycles through each line of the partslist
                        oPartDocNameBom = oDrawDoc.Sheets.Item(1).PartsLists.Item(1).partslistrows.item(BOMIndex).ReferencedRows.item(1).bomrow.componentdefinitions.item(1).Document.FullFileName
                            If oPartDocNameSheet = oPartDocNameBom Then'If the view matches that line in the partslist then change view name to that item number
                              
                                'oPartDescriptionBom = oDrawDoc.Sheets.Item(1).PartsLists.Item(1).partslistrows.item(BOMIndex).ReferencedRows.item(1).bomrow.ReferencedfileDescriptor.Description
    
    'oSheet=oDrawDoc.Sheets.Item(1)
    'If  oDrawDoc.Sheets.Item(1).PartsLists.count=0 Then
    'Else

    'BOMrowindexMax=oPartslist.partslistrows.count
    'BOMrowindex=1
    'Do While BOMrowindex<BOMrowindexMax+1
    oPartDescriptionBom = oPartslist.Partslistrows.item(BOMIndex).item(oColumnDescription).Value
    oPartLENGTHBom = oPartslist.Partslistrows.item(BOMIndex).item(oColumnLENGTH).Value
    oPartQTYBom = oPartslist.Partslistrows.item(BOMIndex).item(oColumnQTY).Value*iProperties.Value("Custom", "QTY REQ'D")
    oPartITEMBom = oPartslist.Partslistrows.item(BOMIndex).item(oColumnITEM).Value


    'oPartslist.Partslistrows.item(BOMrowindex).item(oColumnT_MASS).Value = oPartMassBom*oPartQTYBom
    'BOMrowindex=BOMrowindex+1
    'Loop
    'End If
    
    
    
    


                            oSheet.Drawingviews.item(ViewIndex).Name = "ITEM " & oPartITEMBom 'D" 'change view name to that item number
                            oSheet.Drawingviews.item(ViewIndex).showlabel=True 'Show view label

                             oPartslist.Partslistrows.item(BOMIndex).item(oColumnREF).Value = "SHT " & SheetIndex 'Change value in BOM to show sheet number
                             mykdoc = oPartDocNameSheet
							 mykdoc = ThisApplication.Documents.Open(oPartDocNameSheet)
							 mykdoc.Document.SaveAs("C:\1155\item - " & SheetIndex & ".ipt" , True)
							 mykdoc.close(True)
                            BOMIndex=BOMIndexMax 'Exit this loop
                            BOMItemfound =1
                            End If
                            BOMIndex=BOMIndex+1 'Try next row
                            Loop
                    
                    If BOMItemfound = 0 And oSheet.Drawingviews.item(ViewIndex).showlabel=True Then
                    oSheet.Drawingviews.item(ViewIndex).Name = "NOT FOUND IN BOM"
                    End If
                    
                    Else
                    End If
                    End If
                ViewIndex=ViewIndex+1 ' Try next view
                Loop
    End If
SheetIndex=SheetIndex+1 

Loop

iLogicVb.UpdateWhenDone=True
'1


 

 

0 Likes
265 Views
0 Replies
Replies (0)