Hi,
i could never figure out why Inventor isnt more intuitive when it comes to sheets. We all need to place a view of either the Front, Side, Top or Iso etc and yet, the settings allow us to merely place a single word for base views & projected views. This frustrated me so i made a tool and i have added it below for anyone who would find this useful.
There is a small draw back. it doesnt dynamically add the scale to the view label ( <SCALE> ) as i cant find a way to include that in my code. Nevertheless though, you only have to click your button once and it updates ayway so its no major draw back.
What it does
it loops through all of the views on the drawing and changes or adds the vew label to the view that it is i.e. Front, Left, Right etc etc. it adds the scale underneath. If the view is a section or a detail, it will be skipped.
Code
Public Sub GetTheViews() Dim oDoc As DrawingDocument Set oDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim iView As Integer Dim iViewText As String Dim Ret As Long Ret = MsgBox("Would you like to add the Scale too?", vbYesNo) Set oSheets = oDoc.Sheets For Each oSheet In oSheets Set oViews = oSheet.DrawingViews For Each oView In oViews iView = oView.Camera.ViewOrientationType Select Case iView Case 10764 iViewText = "FRONT ELEVATION" Case 10763 iViewText = "CUSTOM VIEW" Case 10754 iViewText = "PLAN ELEVATION" Case 10757 iViewText = "BOTTOM ELEVATION" Case 10758 iViewText = "LEFT ELEVATION" Case 10755 iViewText = "RIGHT ELEVATION" Case 10756 iViewText = "BACK ELEVATION" Case 10759 iViewText = "TOP RIGHT ISO VIEW" Case 10760 iViewText = "TOP LEFT ISO VIEW" Case 10761 iViewText = "BOTTOM RIGHT ISO VIEW" Case 10762 iViewText = "BOTTOM LEFT ISO VIEW" Case Else End Select Select Case oView.ViewType Case 10502 To 10503 'do nothing to skip sections & details Case Else Select Case Ret Case 6 oView.Label.FormattedText = iViewText & vbCrLf & "SCALE - " & GetFraction(oView.Scale) oView.ShowLabel = True oView.Label.ConstrainToBorder = True Case Else oView.Label.FormattedText = iViewText End Select End Select Next Next End Sub Function GetFraction(ByVal Num As Double) As String If Num = 0# Then GetFraction = "None" Else Dim WholeNumber As Integer Dim DecimalNumber As Double Dim Numerator As Double Dim Denomenator As Double Dim a, b, t As Double WholeNumber = Fix(Num) DecimalNumber = Num - Fix(Num) Numerator = DecimalNumber * 10 ^ (Len(CStr(DecimalNumber)) - 2) Denomenator = 10 ^ (Len(CStr(DecimalNumber)) - 2) If Numerator = 0 Then GetFraction = WholeNumber Else a = Numerator b = Denomenator t = 0 While b <> 0 t = b b = a Mod b a = t Wend If WholeNumber = 0 Then GetFraction = CStr(Numerator / a) & ":" & CStr(Denomenator / a) Else GetFraction = CStr(WholeNumber) & " " & CStr(Numerator / a) & ":" & CStr(Denomenator / a) End If End If End If End Function
simply add the code to a new module and add the button to the ribbon using the Customisation toolbar. I will make this into an addin but i need to finish my iProperties tool first along with a few other neat tools 🙂
there is a quick video demo attached to see it in action
Thanks
Nigel
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Nigel, this looks awesome. Thanks for the effort.
I added it and on running it and selecting YES to the scale question I get an Run-time error '6': Overflow and when I debug its the line shown below :-
I don't know much about VB so I can't track down what the problem is.
FYI I work in metric so I don't know if this is a problem with the scales.
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi
updated code that now collects the correct view scale based on whatever was selected or set in the place view dialog box. the conversion function is no longer required. If i can find the actual stored view value, i'll revise the code again and post but this updated code works great 🙂
Thanks
Public Sub SetViewLabels() Dim oDoc As DrawingDocument On Error GoTo SetViewLabels_Error Set oDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim iView As Integer Dim iViewText As String Dim Ret As Long Ret = MsgBox("Would you like to add the Scale too?", vbYesNo) Set oSheets = oDoc.Sheets For Each oSheet In oSheets Set oViews = oSheet.DrawingViews For Each oView In oViews iView = oView.Camera.ViewOrientationType Select Case iView Case 10764 iViewText = "FRONT ELEVATION" Case 10763 iViewText = "ISOMETRIC VIEW" Case 10754 iViewText = "PLAN ELEVATION" Case 10757 iViewText = "BOTTOM ELEVATION" Case 10758 iViewText = "LEFT ELEVATION" Case 10755 iViewText = "RIGHT ELEVATION" Case 10756 iViewText = "BACK ELEVATION" Case 10759 iViewText = "TOP RIGHT ISO VIEW" Case 10760 iViewText = "TOP LEFT ISO VIEW" Case 10761 iViewText = "BOTTOM RIGHT ISO VIEW" Case 10762 iViewText = "BOTTOM LEFT ISO VIEW" Case Else End Select Select Case oView.ViewType Case 10503 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "SECTION '<DrawingViewName/> - <DrawingViewName/>'" Case 10502 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "DETAIL '<DrawingViewName/>'" Case 10499 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "AUXILIARY VIEW - '<DrawingViewName/>'" Case Else End Select Select Case Ret Case 6 oView.Label.FormattedText = iViewText & vbCrLf & "SCALE - " & oView.ScaleString oView.ShowLabel = True oView.Label.ConstrainToBorder = True Case Else oView.Label.FormattedText = iViewText End Select Next Next On Error GoTo 0 Exit Sub SetViewLabels_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SetViewLabels of Module mod_GetViewNames" End Sub
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi
i have uploaded a video to show how easy it is to use 🙂
Thanks
Nigel
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Nigel, thanks for the update.
I deleted the old code and added the new. On running it I get nothing. No view pop-up asking about Scales and no view labels. I see that it's working in your video so I think the problem is at my end. I restarted Inventor to make sure the new VBA code was loaded, but still no labels when I run it. Any ideas?
Hi
As a first thought, im going to guess that you deleted ALL of the code. if that was the case, Inventor might remove the button link in the ribbon. i would right click the ribbon and select customise. then select Macro from the dropdown in the top left corner. select what ribbon menu you want the button to be place in (drop down menu top right)
then click the routine 'SetViewLabels' and the click the >> button. click apply and it should work.
Usually, if you delete code, it would disassociate with the button. If your existing button is already there, remove it then re-add it.
let me know how you get on 🙂
Nigel
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi
Updated Code. this now changes the scale when the view is updated. This means that you only need to run the tool once to change the text 🙂
Public Sub SetViewLabels() Dim oDoc As DrawingDocument On Error GoTo SetViewLabels_Error Set oDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets Dim oSheet As Sheet Dim oViews As DrawingViews Dim oView As DrawingView Dim iView As Integer Dim iViewText As String Dim Ret As Long Dim mBar As ProgressBar Ret = MsgBox("Would you like to add the Scale too?", vbYesNo) oSheets = oDoc.Sheets For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews iView = oView.Camera.ViewOrientationType Select Case iView Case 10764 iViewText = "FRONT ELEVATION" Case 10763 iViewText = "ISOMETRIC VIEW" Case 10754 iViewText = "PLAN ELEVATION" Case 10757 iViewText = "BOTTOM ELEVATION" Case 10758 iViewText = "LEFT ELEVATION" Case 10755 iViewText = "RIGHT ELEVATION" Case 10756 iViewText = "BACK ELEVATION" Case 10759 iViewText = "TOP RIGHT ISO VIEW" Case 10760 iViewText = "TOP LEFT ISO VIEW" Case 10761 iViewText = "BOTTOM RIGHT ISO VIEW" Case 10762 iViewText = "BOTTOM LEFT ISO VIEW" Case Else End Select Select Case oView.ViewType Case 10503 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "SECTION '<DrawingViewName/> - <DrawingViewName/>'" Case 10502 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "DETAIL '<DrawingViewName/>'" Case 10499 'TREAT THE SECTION TEXT TO LINE UP CORRECTLY iViewText = "AUXILIARY VIEW - '<DrawingViewName/>'" Case Else End Select Select Case Ret Case 6 oView.Label.FormattedText = iViewText & vbCrLf & "SCALE - <DrawingViewScale/>" '& oView.ScaleString oView.ShowLabel = True oView.Label.ConstrainToBorder = True Case Else oView.Label.FormattedText = iViewText End Select Next Next On Error GoTo 0 Exit Sub End Sub
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Nigel, you were right. I removed the button and made a new link to the macro and got better results.
If I choose NO to the pop-up about Scale then I get no view labels. I have tried both this code and the code on your other posting here and they both do the same. No view label if I select NO to the Scale question.
Here is a link to a short video of this problem.
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
It is working good but one question please. Is it there way in multi sheets this code to work separate on each sheet. Sometimes i do not need labels on all sheets. Thank you
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi
i have made a tool to suit your needs and posted it here with full instruction 🙂
http://forums.autodesk.com/t5/Inventor-Customization/New-VBA-Drawing-View-Labels-tool/td-p/4936348
Thanks
Nigel
Nacho
Automation & Design Engineer
Inventor Programmer (C#, VB.Net / iLogic)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.