Tuesday 9 February 2016

Item Number on Drawing Views (Reg Hasell update)

                Do you remember the “Item Number on Drawing Views” blog? It was a while back and if you need a refresh you can read it in full here, but essentially it will add the Item Number on drawing views. If you are detailing components and assemblies on same drawing then this will rename the component view description and will add the Item Number as indicated in Parts List and Balloon.

Our ilogic code looks the same now!
                I have an updated code for which all the credits go to Reg Hasell. As it usually happens “one size doesn’t fit all” and he needed a personalized code which removes orphaned views and also changes formatting of the view labels. Sometimes we need to remove views of items no longer on the Parts List and that can be done with ilogic as well.

                If you find this useful, go to autodesk forum, find him and give him kudos For questions you can start a new thread on the Inventor Customization Forum and then call me or him by adding our usernames in the post like this: @salariua @rhasell. I am sure Reg wouldn’t mind answering questions about his changes, if he has the time for it.

                I have asked Reg to give us a short description about himself, the work he does and why the need to change the code. Here he goes:

------------------------------------------------------------------------------------------------------------
Hi all,
Very briefly about me.

                I am originally from South Africa and moved to the Gold Coast Australia 5 years ago with my Wife and Daughter. I currently work for a small company that design Tension membrane structures. (EG The fabric roof over the stadiums) and most of my work is structural steel.

                I started as an Application Engineer with an Autodesk VAR about 10 years ago and have taught myself pretty much everything. I only really started to learn Inventor when I moved to an engineering firm and all of a sudden your designs are being built!

                When I moved to Australia I had to really pull out the stops when it came to 'tweaking' Inventor. All our drawing standards are Architectural based, and Inventor does not play nicely. It took me about 12 months to find my groove.

                If I follow my trend on the forums, I can see how I have grown from asking to helping. I still strive accepted solutions and Kudos. I feel I that I bring a real world experience to the forums, as all my solutions come from practical experience and lots of blood sweat and tears.

                The "Delete me code" has also grown up a little, as there was a slight bug in that it changed everything to "Delete me" Including views that I did not want to change. Depending on the drawing type, this did not pose an issue, but on smaller assembly drawings where I share the assembly detailing with component detailing this became a problem. Some larger assembly drawings have their own component detailing sheets. So it now allows me to select the views I want to change.

                I created this code because I re-use a lot of assemblies, (E.G I will make a master Sub-Assembly, and just add cleats etc for each variation, and their drawings, obviously with a few small changes. When it came to detailing the items, I use the feature of "Replace Model Reference" Sometimes it’s difficult to keep track of what is on your drawing sheet, and mistakes are made.

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

Thanks Reg for this short description / interview and for the updated code.

Enough said, here is Reg’s code, and even if you don’t use this feature I suggest you glimpse over because there is a lot of good info you could be using somewhere else.



--------------------------Start “Drawing_View_Label”--------------------------
'Set view Label
Sub Main oView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
    MessageBox.Show("At least 1 drawing view must be selected first", "iLogic")
Exit Sub
End If

'Removed 27.01.2016 Reg Hasell
'Was not really achiving anything.

'Reference to the drawing view from the 1st selected object
''Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
''oModel = ThisDoc.ModelDocument
''If oView IsNot Nothing Then
''oView.ShowLabel = True
oMenu ()
''End If
End Sub

Sub oMenu
Dim resu1t As String="Result"
Dim oLab As New ArrayList
oLab.Add("Single Assy")
oLab.Add("Mirror Assy")
oLab.Add("Extrusion - Item")
oLab.Add("Extrusion - Mirrored")
oLab.Add("")
oLab.Add("Detail Item")
oLab.Add("")
oLab.Add("Section View")
oLab.Add("Detail View")
oLab.Add("Plan View")
oLab.Add("Axonometric View")
oLab.Add("")
oLab.Add("Elevation")
oLab.Add("Flat Pattern")

'Display table and get the selection
resu1t=InputListBox("Select View Label", oLab, resu1t, _
Title := "View Label Choice", ListName := "View Label")

'Set iProperties based on the selection.
If resu1t="Single Assy" Then
Call oSingle

ElseIf resu1t="Mirror Assy" Then
Call oMirror

ElseIf resu1t="Extrusion - Item" Then
Call oExtrusion

ElseIf resu1t="Extrusion - Mirrored" Then
Call oExtrusion_M

ElseIf resu1t="Detail Item" Then
Call oDetail

ElseIf resu1t="Section View" Then
Call oViewSect

ElseIf resu1t="Detail View" Then
Call oViewDet

ElseIf resu1t="Plan View" Then
Call oViewPlan

ElseIf resu1t="Axonometric View"
Call oViewAxon

ElseIf resu1t="Elevation" Then
Call oViewelevation

ElseIf resu1t="Flat Pattern" Then
Call oViewFlat

End If
End Sub

Sub oSingle
'Set view Label
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
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringQTY & oStringTXT & oStringENG & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
'If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
'        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
'    End If
Align ()
End Sub

Sub oMirror
'Set view Label
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
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True
' set up the the project number for the drawing label
Call project

oProj=iProperties.Value("Project", "Project")
oItemValue= oProj & "_QTY"

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties   
oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"

     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringOPP = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - OPPOSITE HAND - MARK AS - </StyleOverride>"
    oStringTXTx = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'>x </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    oReturn="<Br/>"

'add to the view label
oView.Label.FormattedTextoStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
    End If
Align ()
End Sub

Sub oExtrusion ' Added by Reg 27.01.2016
'''Set view Label
''Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
''Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
''oModel = ThisDoc.ModelDocument
''If oView IsNot Nothing Then
''oView.ShowLabel = True
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringQTY & oStringTXT & oStringENG & oStringStock & oStringScale

''Else
''    MessageBox.Show("The selected object is not a drawing view", "iLogic")
''End If
'If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
'        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
'    End If
Align ()
Next
End Sub

Sub oExtrusion_M ' Added by Reg 27.01.2016
'Set view Label
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
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

Call project
'MessageBox.Show(iProperties.Value("Project", "Project"), "Title")

oProject=iProperties.Value("Project", "Project")       
        oItemValue= oProject & "_QTY"
'MessageBox.Show(oItemValue, "Title")
'Sub Set properties to create the Custom Fields, Without going into too much detail, I can't do this in one step

o_iPropID_QTY = oModel.PropertySets.Item("User Defined Properties").Item(oitemValue).PropId 'Custom QTY Field, defined above
o_iPropID_ENG = oModel.PropertySets.Item("User Defined Properties").Item("ENG").PropId

'format the model iproperties
    oStringQTY = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_QTY & "'>customPropertyName </Property></StyleOverride>"
    
     oStringENG = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'><Property Document='model' PropertySet='User Defined Properties' Property='customPropertyName' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
     & o_iPropID_ENG & "'>customPropertyName </Property></StyleOverride>"

    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringOPP = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - OPPOSITE HAND - MARK AS - </StyleOverride>"
    oStringTXTx = "<StyleOverride Underline='True' FontSize='0.5' Bold='True'>x </StyleOverride>"

    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'> OFF - AS SHOWN - MARK AS - </StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    oReturn="<Br/>"

'add to the view label
oView.Label.FormattedTextoStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringStock & oStringScale
'oStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
'If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
'        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
'    End If
Align ()
End Sub

Sub oDetail
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM <DrawingViewName/> DETAIL </StyleOverride>"
    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringStock & oStringScale
'Else
'    MessageBox.Show("The selected object is not a drawing view", "iLogic")
'End If
If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
    Next
End Sub

Sub oViewSect
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>SECTION  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale
Align ()
Next
End Sub

Sub oViewDet
'Detail view Label Reset
Dim oView As DrawingView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection

oModel = ThisDoc.ModelDocument
    For Each oView In oSSet

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>DETAIL  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale
Align ()
Next
End Sub

Sub oViewPlan
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>PLAN VIEW  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewAxon
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>AXONOMETRIC VIEW  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE N.T.S</StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewelevation
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ELEVATION  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub

Sub oViewFlat
'Detail view Label Reset
'Set view Label
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView= trycast(oSSet.item(1), DrawingView)
oModel = ThisDoc.ModelDocument
If oView IsNot Nothing Then
oView.ShowLabel = True

'format the model iproperties   
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM FLAT PATTERN  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedTextoStringTXT & oStringScale

Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
End If
Align ()
End Sub



Sub Align
Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
For Each oView In oSheet.DrawingViews
    If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
Next
End Sub

Sub Project
oProject = InputBox("Change Project Name", "Project Name", iProperties.Value("Project", "Project"))
        iProperties.Value("Project", "Project")=oProject
Return
End Sub

--------------------------End “Drawing_View_Label”--------------------------

--------------------------Start “IDW Reset Labels” Rev1--------------------------
 
'Reg
'Version 1.0
'Date: 13/10/15
 
'This code renames all the views on a drawing
'to match the item number in the model tree.
'It then formats the label correctly to suit GDI.
 
' 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
Dim oProj As String
oModel = ThisDoc.ModelDocument
 
 
'oProj = InputBox("Project number", "Title", "15046")
'oItemValue= oProj & "_QTY"
'MessageBox.Show(oProj, "Title")
'MessageBox.Show(oItemValue, "Title")
 
 
 
 
For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    For Each oView In oViews
'Show View Label if switched off
oView.ShowLabel = True
'Sub Set to create the Custom Field
oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>DELETE ME <DrawingViewName/></StyleOverride>"
    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
 
'add to the view label
oView.Label.FormattedTextoStringTXT & oStringStock & oStringScale
 
  If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
                    
                    
                    
'                                    End If  
'            Next
      Next
Next
 
--------------------------End “IDW Reset Labels” Rev1--------------------------

--------------------------Start “IDW Reset Labels” Rev2--------------------------
 
'Reg
'Version 2.0
'Date: 27/01/16
 
'This code renames all the selected views on a drawing
'to "Delete Me"
'When re-using drawings, sometimes views becomeorphaned, and they get missed.
'This is a two stage process of renaming the views, then naming them to their correct vaules.
'Anything left as a "Delete Me" label, can be deleted.
'The origional code renamed every view on the drawing. (I will note what can be commented out to re-enable this feature)
'This unfortunately re-named Valid view labels as well, and was quite tedious to rename everything back again.
 
'Change history:
'Version 2.0 (27.01.2016)
'Added the feature of renaming selected views only.
 
' 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
Dim oProj As String
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet 'Added rev 2.0 - Selection
oModel = ThisDoc.ModelDocument
 
'Check that at least one view is selected
If oSSet.count = 0 Then
MessageBox.Show("At least 1 drawing view must be selected first", "iLogic")
End If
 
For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
    oViews = oSheet.DrawingViews
    'For Each oView In oViews ' Removed by Rev 2.0
    For Each oView In oSSet ' Added in Rev2.0
 
'Nothing Fancy, a basic view label text line.
oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>DELETE ME <DrawingViewName/></StyleOverride>"
    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
'add to the view label
oView.Label.FormattedTextoStringTXT & oStringStock & oStringScale
 
'This is not really needed, but left in anyway to format the Alignment.
  If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
      Next
Next

--------------------------End “IDW Reset Labels” Rev2--------------------------

--------------------------Start “IDW Set Item Number”--------------------------

'Firstly: Credit goes to "Adrian Salariu" for all the help
' http://blog.ads-sol.com/
' https://plus.google.com/+AdrianSalariu-ADS
' He wrote the main section of the code, I just added the GDI label formats.
' using snippets regarding the type formats, I added the differnt types of views.
'Reg Hasell
'Version 2.0
'Date: 19/11/15
 
'This code renames all the views on a drawing
'to match the item number in the BOM.
'It then formats the label correctly to suit GDI.
'-----------------------------------------------------------
' 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
                
                'REG
    ' ITEM " & oItemValue & " ](REG TESTING)
    'oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM <DrawingViewName/> DETAIL </StyleOverride>"
    
    If oVIEW.Viewtype=10501 Then '(Checks for primary views only)
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>ITEM " & oItemValue & " DETAIL </StyleOverride>"
    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    'add to the view label
    oView.Label.FormattedTextoStringTXT & oStringStock & oStringScale
 
ElseIf oVIEW.Viewtype=10503 Then '(Section View Type)
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>SECTION  </StyleOverride>"
    'oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
    'add to the view label
    oView.Label.FormattedTextoStringTXT & oStringScale
 
ElseIf oVIEW.Viewtype=10502 Then '(Detail view type)
    oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>DETAIL  </StyleOverride>"
'    oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"
'    add to the view label
    oView.Label.FormattedTextoStringTXT & oStringScale
 
ElseIf oVIEW.Viewtype=10504 Then '(Isometric view Type)
    oView.ShowLabel = False ' Switch off the label Remove the comments below to enable axonommetric
        'oStringTXT = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>AXONOMETRIC VIEW  </StyleOverride>"
        'oStringStock = "<Br/><StyleOverride FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='55'>STOCK NUMBER</Property></StyleOverride>"
        'oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE N.T.S</StyleOverride>"
        'add to the view label
        'oView.Label.FormattedText =  oStringTXT & oStringScale
 
        End If
'add to the view label '(removed as it has now been replaced by the individual formats)
'oView.Label.FormattedText =  oStringTXT & oStringStock & oStringScale
'LEFT Align View Labels
If Not oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft Then
        oView.Label.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft
    End If
 
 
                End If  
            Next
      Next
Next
'All done, thanks once again to Adrian.

--------------------------End “IDW Set Item Number”--------------------------

Later,
ADS

photo credit: Codex Hammurabi, Louvre, Paris (license)

No comments:

Post a Comment