Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sheets - View Label descriptions (Code)

15 REPLIES 15
Reply
Message 1 of 16
NachitoMax
636 Views, 15 Replies

Sheets - View Label descriptions (Code)

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)


EESignature


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.


15 REPLIES 15
Message 2 of 16

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 :-

 

debug.jpg

 

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.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 3 of 16

Hi

Yeah I get the same error on the same line. I work in metric too as in 1:10 - 1:20 etc. when I collect the scale from inventor, it comes as a decimal which is why I have the conversion function. I have slightly updated my code to now include the sections and detail views which is much better. I'll see if I can improve the scale conversion or if I can collect the actual scale that the view is initially placed in.

Any updates will be put here.

I did the code because it takes too long to manually change or add the view itself and relying purely on the inventor part of setting a generic name isn't enough for my clients.

Glad you like the code 🙂



Nigel

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 4 of 16
NachitoMax
in reply to: NachitoMax

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)


EESignature


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.


Message 5 of 16
NachitoMax
in reply to: NachitoMax

Hi

 

i have uploaded a video to show how easy it is to use 🙂

 

Drawing Views Label Text

 

 

Thanks

 

 

Nigel

 

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 6 of 16

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?

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 7 of 16

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

 

macro.JPG

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 8 of 16
NachitoMax
in reply to: NachitoMax

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)


EESignature


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.


Message 9 of 16

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.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

Message 10 of 16

Hi

Try this. The oView.ShowLabel = True wasn't present in the code. It's visible by default on my machine but could be turned off on yours. This is in the select case Ret where case else does everything if the message of choice is not "yes"


Let me know how you get on please

Public Sub SetViewLabels()

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

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
oView.ShowLabel = True
oView.Label.ConstrainToBorder = True
End Select

Next
Next
Exit Sub
End Sub

Cheers

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 11 of 16
GosponZ
in reply to: NachitoMax

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

Message 12 of 16
NachitoMax
in reply to: GosponZ

Hi

Yes. You can comment out 2 lines-

For Each Sheet in oSheets

And

The 'Next' at the bottom of the page. I'm making this into a tool to make it easier to use too 🙂



Thanks

Nigel

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 13 of 16
GosponZ
in reply to: NachitoMax

i tried but no working 😞

Message 14 of 16
NachitoMax
in reply to: GosponZ

Ok

Let me take a look and post a single sheet version 🙂


Nigel

Nacho

Automation & Design Engineer

Inventor Programmer (C#, VB.Net / iLogic)


EESignature


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.


Message 15 of 16
GosponZ
in reply to: NachitoMax

Smiley HappyYou are the man.

Message 16 of 16
NachitoMax
in reply to: GosponZ

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)


EESignature


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.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report