Tuesday, 25 October 2016

iLogic - Set view labels and Add Selection to SelectSet

Had a little spare time today, so I thought I would play around with one of my iLogic rules.

When creating drawings, I more often than not need to rename the view label.

For a while now I have had code which does that, but the one troubling thing was I had to select the view before running the code, not an issue just painfull, because if I forget to select the view, I have to backout of the code, select the view, run the code again.

My code uses the "Selectset" and I was struggling to find the correct method to ADD to the selectset. I eventually found it in the "Programming/API help" So using the CommandManager.Pick method, I can add to the set.

Anyway here is my code to rename the view labels.

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


'Revision 2
'Date: 25.10.2016
'Notes:
'Added the ability to select a view if none are selected.
'It will also allow you to select another view when completed.

'Set view Label
Sub Main oView
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count = 0 Then
    MessageBox.Show("Please select a view first", "iLogic")
'Exit Sub ' Removed rev2
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View") 'Added Rev2
'Added rev2
'Add the selected view to the SelectSet
'Doing this will leave the rest of the code unaltered, as "oSSet.count=1"
oSSet.select(oView)
End If
oMenu ()
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")
oLab.Add("Custom Label")

'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

ElseIf resu1t="Custom Label" Then
Call oViewCUST

End If
End Sub

Sub oSingle
'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

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.FormattedText =  oStringQTY & 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.FormattedText =  oStringQTY & 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 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.FormattedText =  oStringQTY & oStringTXT & oStringENG & oStringStock & oStringScale
Next
Align ()
End Sub

Sub oExtrusion_M ' Added by Reg 27.01.2016
'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

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.FormattedText =  oStringQTY & oStringTXT & oStringENG & oReturn & oStringQTY & oStringOPP & oStringENG & oStringTXTx & oStringStock & oStringScale
Else
    MessageBox.Show("The selected object is not a drawing view", "iLogic")
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.FormattedText =  oStringTXT & oStringStock & oStringScale
    Next
    Align ()
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>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale
Next
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>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale
Next
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>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & 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'
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE N.T.S</StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & 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>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & 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>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringTXT & oStringScale

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

Sub oViewCUST
'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

oLabel = InputBox("Enter Custom Label", "Title", "FRONT ELEVATION")
    oStringCUST = "<StyleOverride Underline='True' FontSize='0.5' Bold='False'>"& oLabel &"</StyleOverride>"
    oStringScale = "<Br/><StyleOverride FontSize='0.25'>SCALE <DrawingViewScale/></StyleOverride>"

'add to the view label
oView.Label.FormattedText =  oStringCUST & 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
oAgain=MessageBox.Show("Do you wish to select another view?", "Rinse and Repeat",MessageBoxButtons.YesNo, MessageBoxIcon.Question) 'Added rev2
If oAgain=vbYes
AGAIN ()
End If
End Sub

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

Sub AGAIN ' added rev2
Main
End Sub

No comments:

Post a Comment