Wednesday, 29 October 2014

Tube and Pipe: multiple selection change size

Edit:
Thank you all for your votes, the idea was accepted and expect this to work with all CC center files. So from V2016 you should be able to select multiple CC files and do change size it should work for all
End Edit.

It's been a terrible week but I've managed to have anther post on the Inventor Idea Station so if you like it maybe you will cast a vote and get it promoted as new functionality.

Original post:
Haven't found this on the idea station. I am trying to get something similar as "replace should replace all selected components" but for tube and pipe elements.
When you do a run sometimes you need to change size of multiple fittings and pipes.
I don't mean change the style.
On a 2" run I can have a drain or sample valve and I need to change just those end fittings and pipes without affecting the whole run or without doing another separate run.

If you select multiple elements (content center items) there is no change size option. I have "CS" as change size shortcut but it only changes the first element selected.





 Again, if you like this maybe you will vote the change.

ADS.

Route centerlines for visible items only

I have searched and couldn't find a way of showing "Route Centerlines" just for visible components, not the whole runs, going up and down several floors.
So If you feel you have this problem maybe you want to vote for this on the idea station.

http://forums.autodesk.com/t5/inventor-ideastation/include-route-centerlines-for-visible-items-only/...

Here is a short description:

When doing a drawing with tube and pipe runs you can right click on the runs in the browser and select "include route centerlines" so you can dimension your drawing. Unfortunately it brings in all the centerlines instead of centerlines just for visible components. You then need to hunt and pick each centerline that you don't want and do right click "Visibility" to turn it off.

Can we have centerlines just for visible components please.

  
 
 So, if you have this problem maybe you want to give this a vote in the idea station and hopefully Autodesk will solve it.

ADS

Thursday, 23 October 2014

Browser name prompted entry

I just realized that my previous post on Part Tagging might not mean anything to you. I use the browser name as component tags but it might interest you that the code will actually rename the browser name of the parts.

So if you need to rename the occurrence name (browser name) of the parts in the assembly and you to be asked for the name of each one then use the code from here.



ADS.

Monday, 20 October 2014

Part tagging

If you have read my previous post on tagging components in the drawing you will like this one. The following code lets you select parts in the assembly and prompt for occurrence name (used as tags for our equipment).

You can select as many parts as you want and it will prompt for a new value and change it for all of them in the order you have selected them.





The dialog shows the current occurrence value and if you click cancel even after the value was changed it reverts the occurrence name to default with the first available index number.



No you can use the Component Tags Post to show them in the drawing.

Here is the code, you need to have part selection filter in the assembly first active.

' Declare current assembly
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

' Set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

'Get the selection set
Dim selSet As SelectSet
selSet = oAsmDoc.SelectSet

'loop trough each selected part
For Each obj In selSet
            oTagOcc = InputBox("Enter Tag No: ", "Tag Prompt", obj.Name)
            obj.Name = oTagOcc

Next

EDIT:

I have updated the code, here's the new code:

Dim comp As Object

Try
    While True
        comp = ThisApplication.CommandManager.Pick(
            SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, 
            "Select a component") 
        oTagOcc = InputBox("Enter Tag No: ", "Tag Prompt", comp.Name)
            comp.Name = oTagOcc
    End While
Catch ' do nothing if error
MessageBox.Show("Tag exists or user canceled", "iLogic")


End Try

END EDIT:

ADS.

Sunday, 19 October 2014

Item Number on drawing views

 EDIT Jul 15 2016:


If you have more than one PartsList on the drawing  you might want to read this.

END EDIT Jul 15 2016

------------------------------------------------------------------------------------------------------------



 EDIT Nov 28 2014:


Question from the Autdesk Inventor Forum:
Can I have the Item Number on just the main views?
You need to look into identifying the main views. I have a new blog on how to identify the view type here.
But, if you edit the Item Number on Drawing Views code and replace:



oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"


 with



If oView.ViewType = 10501 Then
  oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & oItemValue & " </StyleOverride>"
Else
  oStringItem = "<StyleOverride Underline='True' FontSize='0.35'></StyleOverride>"
End If

 it will add the label on just the main views. You can also use kProjectedDrawingViewType instead of 10501.


END EDIT Nov 28 2014

------------------------------------------------------------------------------------------------------------

EDIT Nov 25 2014:

This is growing legs, and that's good. I have been told that it has an error processing virtual parts. I like to add virtual parts like grout, grease, oil, etc. so it has a problem getting the filepath of those items.

Here's a quick update that will skip rows with error (delete the comment ' symbol to see which rows have error):

Item_no_on_Drawing_Views_v1.2

I fyou replace:

oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName

with

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
   Continue For
End Try

you should be fine.

END EDIT Nov 25 2014

------------------------------------------------------------------------------------------------------------

EDIT Nov 10 2014:

Thanks to Brendan Henderson that tested the code and found an error. I have updated the code.

It should work like this (for each sheet in the drawing):

Look for a parts list inside current sheet ( in case you have multiple subassemblies on same drawing, hopefully each on it's own sheet along with any detail views of components)
If found, update the all views in the current sheet with Item Number based on that Parts list
If there is no parts list in the current sheet, will search in all the sheets and use the first one it finds (for those that have main assembly and parts list on first sheet and component details on separate sheets).

If you have multiple parts lists make sure that all the views that you want updated for that parts list are on the same sheet with the parts list.
here is the code.
Item Number on Drawing Views V1.1

END EDIT Nov 10 2014.

------------------------------------------------------------------------------------------------------------

For all of you out there that like to add part views on assembly layouts this might be handy. A question was posted the other day on Inventor forum and the user there needed the Item number from the parts list to show up in the drawing view info.

Because his company has very few duplicates and lots of new parts he ended up with 10 digits part numbers that was in no way usable, either as a call out balloon or in parts list.

One way was to create a custom iproperty to hold that value and then to call it in the view label. This might work fine as long as you don't reuse the part.

There is another solution however that will give us just that, the parts list item number on the drawing view.

It's ilogic of course and here's a short description of how that works. It compares the model referenced in the view with the model of each row entry in the parts list. When match is found it gets the parts list item number, turns the view label on and adds this text with a little formatting (underline and size) in the drawing view.

The code asks you to select a views to process because you don't want to process all views (assembly views especially). We could find a value like Part Number in the table but there was no Part Number column and it could have been a problem if he had "Enable Part Row Merge" in the BOM. I decided to use filename with complete path because there might have been multiple parts with same filename but windows doesn't allow files with same name in the same place.

Here is the code, I hope it makes sense (the original code in text is attached here):

EDIT:
This code had a bug, and I have updated the code, will keep the old one in here in case someone needs just parts of the code.
END EDIT.



' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

'view selection code
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
MessageBox.Show("You must select a drawing view first", "iLogic")
Exit Sub
End If


'start processsing all selections
Dim i As Long
For i = 1 To oSSet.Count

'Reference to the drawing view from the current selected object
Dim oView As DrawingView = trycast(oSSet.item(i), DrawingView)
If oView IsNot Nothing Then
'Get the full filename Of the view model
Dim oModelFileName As String
oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
' Iterate through the contents of the parts list.
Dim j As Long
For j = 1 To oPartList.PartsListRows.Count
' Get the current row.
Dim oRow As PartsListRow
oRow = oPartList.PartsListRows.Item(j)
'get filename of model in row
Dim oRowFileName As String
oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
'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 = oPartList.PartsListRows.Item(j).Item("Item")
'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
Else
MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Next


NEW IMPROVED 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
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    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")

        Dim oPartList As PartsList
            'try and get the parts list form the table of this sheet
            Try
                oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
            Catch 'on error try and search all sheets for first found parts list           
                'iterate trough each sheet
                Dim i As Long
                For i = 1 To oDrawDoc.Sheets.Count
                    If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
                Next   
                oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
                'MessageBox.Show("parts list found on: " & i, "Title")
            End Try
               
            ' Iterate through the contents of the parts list.
            Dim j As Long
            For j = 1 To oPartList.PartsListRows.Count
                ' Get the current row.
                Dim oRow As PartsListRow
                oRow = oPartList.PartsListRows.Item(j)
                'get filename of model in row
                Dim oRowFileName As String
                oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
                '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  = oPartList.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