Friday 15 July 2016

Item Number on Drawing Views (multiple Parts Lists)

                If you remember, a while back I have created an ilogic code to add item number on drawing views (original post). Some companies like to detail parts along with assembles on same drawing or even on same sheet.

                I was doing a drawing for a frame and because there were mostly standard shapes that this frame was build out of I decided to document the rest of the components on same sheet. This was not an issue for my code but on frame generator drawings I don’t use a Parts list but rather a Material List.

                The difference is that it doesn’t have an “ITEM” column and so the code would fail to work. You can manually add a Parts List on the drawing outside the sheet but the code will still not work because it looks at the first PartsList on the sheet and in this case it was my Material List.

                Don’t get confused, Parts List, Material Lists, Cut-To-Length lists are all the same, just customized to show different info.

Parts List style
                Material Lists contains, total length, stock number, Description, Material and individual items are merged to show total quantity rather than number of each item.

Cumulated lengths 
                This is setup to work with Tube and Pipe members as well. Remember that Frame Generator use G_L as length and Pipes use PL for length and if you check the column settings for Quantity you will see that if the member is pipe (PL parameter exists) then it will use it as quantity.

Works with TP pipes.

                Now that we got that out of the way and familiarized ourself with the different type of Parts Lists let’s discuss the change in code.
                The original code was looking at the first parts list
        'oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)

                and we need it to search for a specific one “Parts List” so the code became
        For i=1 To oPartsLists.Count
               If oPartsLists.Item(i).Title = "PARTS LIST" Then
                       oPartsList = oPartsLists.Item(i)
                       Exit For
               Else
                'do nothing
               End If
        Next
 
                Here is the full code again version 1.3 (download link here)
-------------------------------------------------------------------------------------------------------------
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
 
Dim oSheets As Sheets
oSheets = oDrawDoc.Sheets
Dim oSheet As Sheet'Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
 
For Each oSheet In oSheets
    'declare the PartsLists 
    oPartsLists = oSheet.PartsLists
 
            'try and get the parts list form the table of this sheet
            Try
                'this doesn't work when you have a material list like on frame drawings
                'oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
                'place a parts list on the drawing and search for it 
                'rather than using an id number
                
                For i=1 To oPartsLists.Count
                    If oPartsLists.Item(i).Title = "PARTS LIST" Then
                        'MessageBox.Show("found table", "ilogic")
                        oPartsList = oPartsLists.Item(i)
                        Exit For
                    Else
                        'do nothing
                    End If
                Next
                
            Catch 'on error try and search all sheets for first found parts list            
                'iterate trough each sheet
                Dim j As Long
                For j = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(j).PartsLists.Count > 0 Then Exit For
                Next
                            
                'this doesn't work when you have other parts lists like a 
                '"material list" like on frame drawing
                'oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'place a parts list on the drawing and search for it 
                'rather than using an id number to locate the first
            
                For i=1 To oPartsLists.Count
                    If oPartsLists.Item(i).Title = "PARTS LIST" Then
                        'MessageBox.Show("found table", "ilogic")
                        oPartsList = oPartsLists.Item(i)
                        Exit For
                    Else
                        'do nothing
                    End If
                Next
                'MessageBox.Show("parts list found on: " & j, "Title")
            End Try
            
    oViews = oSheet.DrawingViews            
    
    For Each oView In oViews
    
        'Get the full filename Of the view model
        Dim oModelFileName As String
        oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        'MessageBox.Show("view model name" & oModelFileName, "Title")
                
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartsList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartsList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                Try ' try and get the full file name of the PL item
                    oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                Catch 'on error go to next item
'                    Dim oCellValue As String
'                    oCellValue = oRow.Item("Item").Value
'                    MessageBox.Show("Error Processing item: " & oCellValue, "Title")
                    Continue For
                End Try
                'compare the filenames
                'Performs a text comparison, based on a case-insensitive text sort order
                'If strings equal returns 0
                If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then 
                    'Get the value of Item from the Parts List
                    'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    oCell  = oPartsList.PartsListRows.Item(j).Item("Item") 
'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    'get the value of text in cell
                    Dim oItemValue As String
                    oItemValue = oCell.Value
                    
                    'Show the view label
                    oView.ShowLabel = True
                    'format the text first line
                    oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
                    'format the text second line
                    oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
                    
                    'add to the view label
                    oView.Label.FormattedText =  oStringItem & oStringScale
                End If  
            Next
      Next
Next

------------------------------------------------------------------------------------------------------------
EDIT: 11/08/16
if you would rather be prompted to select views rather than processing all of them , here is the code.
------------------------------------------------------------------------------------------------------------

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
 
Dim oSheets As Sheets
oSheets = oDrawDoc.Sheets
Dim oSheet As Sheet'Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
 
For Each oSheet In oSheets
    'declare the PartsLists 
    oPartsLists = oSheet.PartsLists
 
            'try and get the parts list form the table of this sheet
            Try
                'this doesn't work when you have a material list like on frame drawings
                'oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
                'place a parts list on the drawing and search for it 
                'rather than using an id number
                
                For i=1 To oPartsLists.Count
                    If oPartsLists.Item(i).Title = "PARTS LIST" Then
                        'MessageBox.Show("found table", "ilogic")
                        oPartsList = oPartsLists.Item(i)
                        Exit For
                    Else
                        'do nothing
                    End If
                Next
                
            Catch 'on error try and search all sheets for first found parts list            
                'iterate trough each sheet
                Dim j As Long
                For j = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(j).PartsLists.Count > 0 Then Exit For
                Next
                            
                'this doesn't work when you have other parts lists like a 
                '"material list" like on frame drawing
                'oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'place a parts list on the drawing and search for it 
                'rather than using an id number to locate the first
            
                For i=1 To oPartsLists.Count
                    If oPartsLists.Item(i).Title = "PARTS LIST" Then
                        'MessageBox.Show("found table", "ilogic")
                        oPartsList = oPartsLists.Item(i)
                        Exit For
                    Else
                        'do nothing
                    End If
                Next
                'MessageBox.Show("parts list found on: " & j, "Title")
            End Try
            
    oViews = oSheet.DrawingViews            

        'get view from user
        While True
            oView = ThisApplication.CommandManager.Pick( _
            SelectionFilterEnum.kDrawingViewFilter, "Select a View") 
        
            'Get the full filename Of the view model
            Dim oModelFileName As String
            oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
            'MessageBox.Show("view model name" & oModelFileName, "Title")
                
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartsList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartsList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                Try ' try and get the full file name of the PL item
                    oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                Catch 'on error go to next item
'                    Dim oCellValue As String
'                    oCellValue = oRow.Item("Item").Value
'                    MessageBox.Show("Error Processing item: " & oCellValue, "Title")
                    Continue For
                End Try
                'compare the filenames
                'Performs a text comparison, based on a case-insensitive text sort order
                'If strings equal returns 0
                If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then 
                    'Get the value of Item from the Parts List
                    'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    oCell  = oPartsList.PartsListRows.Item(j).Item("Item") 
                'Row name needs to be case sensitive or use 1 for first 2 for second etc.
                    'get the value of text in cell
                    Dim oItemValue As String
                    oItemValue = oCell.Value
                    
                    'Show the view label
                    oView.ShowLabel = True
                    'format the text first line
                    oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
                    'format the text second line
                    oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
                    
                    'add to the view label
                    oView.Label.FormattedText =  oStringItem & oStringScale
                End If  
            Next
      End While
Next
------------------------------------------------------------------------------------------------------------
Later,
ADS
               

                

Monday 4 July 2016

Fitting Engagement Distance


This has been in my drafts way to long. I only allowed myself to publish new posts if there is one ready to go in my drafts. Even though I am not back to normal I feel this might help me move towards normality even if I might never get there again.


Can fittings have both male/female connections and different engagement distance?



My friend asking this was referring to elements like bushings, and reducers as in the image bellow where the right side connection can fit 2 sizes, one inside (female) and one outside (male). These will need different engagement distances as well.

3 connections on same fitting.
Library or stand alone?


There is no gender on the fittings; they are all connected by points and axes but how you author it depends on what you intend to do with the file. Is this for an ipart to be published to Content Center, or is it a standalone library file?

More than likely this will be used in content center but if this is a standalone library then you need to author this in a weird way with 3 connections instead of 2. When you place the fitting press Spacebar until it shows the correct position.

While this is possible I think most of you will need this in Content Center. For that you will create two identical shape members with different connections.

Even though these members will have identical part number, stock number and whatever fields you use to identify this, the filename needs to be unique. This is one rare occasion when I allow filename to be different than the part number.

How do we create a dynamic engagement distance? You create an offset work plane and you control the offset value from the ipart table.
 
offset plane
 
ipart table

In the author fitting window choose Engagement, To Plane, Point and choose our plane.

 
Authoring, To Plane / Point
Later,


ADS.


photo credit: parts (license)