Showing posts with label part. Show all posts
Showing posts with label part. Show all posts

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, 1 February 2016

Window Selection in Parts

Don’t you just hate that there is no window selection for part environment? If you need to select more than one item at a time you need to hunt and pick instead of making a window selection.

The other day I have received a 3D building from our client so we can finalize the plant layout. I import that into a single part multiple-body environment for sake of simplicity and because I don’t want to manage, vault, multiple files.

                Revit export, the model has about 750 bodies and in some cases, in parts like this, the bodies are grouped in a sequential order so you can select multiple (with SHIFT) and take off Visibility. I usually select around 50 at a time and do a SHIFT selection in the browser and turn off several at a time.
~750 bodies.
                This particular model had way too many bodies (walls, doors, windows) and the ones for my plant room were all over in the structure tree making it ready difficult to do a browser selection.

                Thought to go clever and fudge an ilogic code I had around to rename browser nodes. As long as you keep selecting bodies the code will turn them off. This worked out pretty good but it quickly turned into a “sharp shooter” point and click game and I looked for a better solution. I was a real pain to select  small bodies (door handle for example) and large ones (sectional walls) at same time.

Point and click but way too slow.
                Here is the code if you ever need it:

Dim comp As Object
Try
    While True
        comp = ThisApplication.CommandManager.Pick(
            SelectionFilterEnum. kPartBodyFilter,
            "Select a component")
        comp.Visible = False

    End While
Catch ' do nothing if error

End Try

                And here is the better solution.

                Create a new Design View Representation because the Default is locked and you can’t change it.

                Place the part in an assembly and change selection filter to Bodies.
Change your filter selection first.
Activate the unlocked design view representation for that part.
Activate the correct Design View Representation.
 Now you can do window selections and turn visibility off for several at once. When you do that remember to choose Modify Design View Representation because you want to change the part as well.
               
Window selection speeds things up.
                And that’s it, simple trick, but it saved a lot of time.

Later,

ADS.


photo credit: Snail climbs window pane (license)

Monday, 25 January 2016

Authoring empty parts

                This was really scheduled to go out on Friday but I was just given a major-major project with strict deadlines and huge penalties on our side for any delay so I had to put in the extra hours and effort to get it moving. I hope I haven’t ruined your weekend by giving you nothing to read on your Sunday coffee or whenever it is that you catch up with the past week news, blogs, forums and CAD news altogether. Helps to start work with a bit of laugh and irony.

Part two on publishing dumb parts is all about authoring empty parts. A lot of the times you don’t have the final model because it’s a complicated part to model, you don’t have enough time or information, you are waiting for a different department to model and certify the part. So meanwhile you do as best you can to overcome this, constraining and moving components around to account for the missing elements.
Empty on all sides

                You might take it a step forward and create a similar shape body or surface outline to guide you as of what the occupied volume is so you can avoid any clashes and interferences when the final model will come in place. This applies to everything from valves to skids and other equipment like heat exchangers for which a model doesn’t exist and it’s in the process of being finalized.

When I am dealing with this type of situations I usually create an empty part, author it as Tube and Pipe to serve me in my routing and drop the final model when ready over it with place fitting command.

TIP: The he assembly replace command will not work and you need to use place fitting instead. With the place fitting command you can drop any T&P authored part on top of a different one to create a replace.

                In my last post here, I’ve shown you how to better/faster create work features and if you haven’t seen it go check it out and then quickly come back because we are going to use that same techniques here.

                In order to author a T&P fitting you need a work point for the connection and an axis for the direction of the engagement. You might need another plane to setup the engagement distance but that depends on the type of connection.
               
                You probably did these points instinctually when authoring T&P fittings although you don’t need to. On an empty part you can’t do without work features but on a model with circular edges you don’t need any work features at all; will have to detail this at a different time.

                If you can’t use the origin planes and axes then you need to create your custom work features and I recommend that you rename then work features in the browser to help you find them on later edits.

TIP: If the directional axis matches one of the origin axis then you don’t need to create them AT ALL. The directional axis doesn’t need to be in line (coincident) with the work point and here’s to prove that:

Add caption


I know there’s nothing fancy here but a lot of people are unaware that you can author empty parts and it’s really the foundation for authoring dumb parts as we will discuss next time.

Later,
ADS

               



Thursday, 4 June 2015

Drawing curves to match model



HOW TO SET DRAWING LINE COLORS AS MODEL APPEARANCE?

I wasn’t sure if to post this at all because it didn’t seem to provide any good and positive solution. If at all I would have post it under “food for thought" or under “let’s see if we can find a better solution”. By “we” I mean one of you showing me how to properly do it.
But just the other day this showed up as a question on the forum and seeing that none came with a better-closer solution I decided to share it as a full blog. It doesn’t mean that you cannot correct me, in fact I am hoping one of you will do.

After posting my answer  the guys on the forum went quiet so I take it that either my info was more than they expected (yeah right!) or I am so far out that they are embarrassed to tell me. I think it’s the later, I’ve been there more than dozen times.
Before I continue here is the forum post.
             
Following text is an expanded adaptation of the answer provided there.

I've been playing with this on my last project. Because it was a large assembly and the pipes in the drawing ended up looking like steaming spaghetti I decided to show each run with a different colour matching the appearance set in the model.
I did a brief scan on the net to see what others have done and I got excited, almost making me think it was done before. So it was, just not the way I needed because the solutions were getting the colour of the part and I needed the colour of the run that is an assembly and the solutions are processing the curves ONE AT A TIME which it’s like watching a painting being done in real time…… a really large one…..with a small brush.
There are not many options here but if it’s a small assembly or just a part that you need processing then presto get the VB or iLogic codes bellow and get them running.
Just like my solution these need a manual update. Now, imagine that I had to add and remove views, sheets, sections, change appearances, change design views, etc. How many paintings can you watch being done in a day? That’s why I have a camera, a fast point and shoot type as well!

First solution: 
Brian Ekins has aVB code but it's processing all lines (curves) one at time and that takes forever. It creates layers with each colour but unfortunately the layers are called as the RBG code of the colour (very hard to identify and edit)

Another solutionon the mCAD forum:

Third solution was on the Inventor forum:

In my case these didn't work because I had a large assembly. This is just one sheet out of six and quite a simple one.


You can change your selection to part filter select your component (or select it in the browser) and then right click properties to change it's colour (override).

This is a partial solution because it's hard to select parts and manually update them all the time (as the assembly changes). But it’s a fast one, almost instant and it changes all line type (hidden, visible, tangent, etc.)

Because I only had visible and tangent lines (small to an ignore number) I decided to setup layers to which I would assign my runs.

So I end up creating copies of Visible layer calling them Run1, Run2, etc. and changed the colour of each one as per the assembly (manual unfortunately).Then right click on a part (or assembly in my case) in the browser, choose "select as edges" and then in the Annotate tab, Format, Layer, choose the layer you previously created.


Hey that’s pretty cool! Or not, because you need to do it for each sheet. You can expand the views in the browser and select a model (my run) in all the views before using select as edges but still to many manual operations. At least once done you can just change the colour of the layer and all sheets update.

Side Note:
Haven't tested but this seems to affect performance and increase the drawing file size. My drawing now has around 50 MB.

So now what?
Will try and put a nice ilogic together to process your browser selection to change its colour from the model on all sheets as per the appearance of your selected object.
This should not process the drawing curve-by-curve. We only have one life. It needs to get the collection of curves and change properties (override) all at the same time. Somehow that’s what using the properties on a model or using the select as edges does. Surely it can be done with iLogic or VB.

Great stuff! When can we have the code?

As soon as I have it, but the way things are going with work overload and no extra time … I might never get to do it.

Later,
ADS.