Control Drawing View Reps & Style with iLogic

ilogic drawing views

I’ve written some iLogic code to control the “View Style” and “View Representation” of drawing views. The code gathers all of the views in the drawing and presents them in a list to the user. It then presents a pre-defined set of “View Styles”, once it has done this, it then gathers all of the “View Representations” from the assembly model and presents these to the user.

The Animated GIF below shows the code in action (clicking on the GIF will open a higher resolution version in a new tab)

Drawing view styles- View Reps iLogic.gif

The user is able to select a drawing view, and then a “View Style” and “View Representation” to apply to the view. I’ve written some error handling into the code, to exit and make no changes if an initial view is not selected, and I have set defaults for instances where the user selects a view, but does not specify a “View Style” or “View Representation” The Animated GIF below shows the error handling / Default selections

iLogic Drawing Selections - Defaults.gif

The iLogic code is designed to work in drawings of Assembly models. If you run it in a Drawing of a part file the code will only give you the option to change the View Style.

Below is the iLogic Code, I have tried to comment it, so hopefully it will make sense to you. Special Thanks to Curtis Waguespack for some of the code he posted on a forum (credited in my code). Enjoy!

'iLogic code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/control-drawing-view-reps-style-with-ilogic
On Error GoTo ClintBrown3D
'------------------------------------------VIEW SELECTION + SETUP ----------------------------------------
' Iterate through drawing views & add to Array
Dim oView As DrawingView = Nothing
Dim oDrawingViews As DrawingViews = ThisApplication.ActiveDocument.Sheets.Item(1).DrawingViews
Dim NewArrayList As New ArrayList
For i = 1 To oDrawingViews.Count
oView = oDrawingViews.Item(i)
bView = oView.Name
NewArrayList.Add(bView)
Next
ClintBrown3D = InputListBox("Choose a View", NewArrayList, d0, Title := "@ClintBrown3D", ListName := "Select a view to edit from the list below")
If ClintBrown3D = "" Then : MessageBox.Show("No Selection made, Exiting", "@ClintBrown3D") : Return : End If

'Create Array & Input list box to choose view types
Dim MyArrayList As New ArrayList
MyArrayList.Add("Shaded")
MyArrayList.Add("Hidden Line")
MyArrayList.Add("Hidden Line Removed")
MyArrayList.Add("Shaded Hidden Line")
MyArrayList.Add("From Base Drawing View")
ViewStyleType1 = InputListBox("Sets the View Style - Default is Hidden Line Removed. You are Editing: " & ClintBrown3D , MyArrayList, d0, Title := "@ClintBrown3D:  " & ClintBrown3D, ListName := "Select a ''View Style'' from the list below")

If ViewStyleType1 = "Shaded" Then : ViewStyleType = 32259 : End If
If ViewStyleType1 = "Hidden Line" Then : ViewStyleType = 32257 : End If
If ViewStyleType1 = "Hidden Line Removed" Then : ViewStyleType = 32258 : End If
If ViewStyleType1 = "Shaded Hidden Line" Then : ViewStyleType = 32261 : End If
If ViewStyleType1 = "From Base Drawing View" Then : ViewStyleType = 32260 : End If
If ViewStyleType1 = "" Then : ViewStyleType = 32258 : MessageBox.Show("No selection made - ''View Style'' set to 'Hidden Line Removed'", "@ClintBrown3D") : End If
'---------------------------------------------------------------- ----------------------------------------
'------------------------------------------VIEW REP CONTROLS + Curtis ------------------------------------
'This section of Code adapted to work with drawings, based on code by Curtis Waguespack (original works in .iam files)
' on this forum >> https://forums.autodesk.com/t5/inventor-forum/ilogic-view-representations-toggling/td-p/6589121
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisDrawing.ModelDocument.ComponentDefinition
Dim oViewReps As DesignViewRepresentations
oViewReps = oAsmCompDef.RepresentationsManager.DesignViewRepresentations
Dim oViewRep As DesignViewRepresentation
Dim NameList As New ArrayList()
For Each oViewRep In oViewReps
	NameList.Add(oViewRep.Name)
Next
'---------------------------------------------------------------------------------------------------------
NameList.Remove("Master") 'You can't select Master, so it is removed from the array
If NameList.Count > 0 Then'This is to deal with drawings of parts
ViewReptoActivate = InputListBox("Sets the View Rep - No selection sets view to ''Default'' View Rep. You are Editing: " & ClintBrown3D , NameList, d0, Title := "@ClintBrown3D:  " & ClintBrown3D, ListName := "Select a View Rep from the list below")
End If
If NameList.Count = 0 Then : GoTo ApplyChanges : End If
	
'Give user feedback if nothing is selected (this is ignored in part files)
If ViewReptoActivate = "" Then
ViewReptoActivate = "Default"
MessageBox.Show("No Selection made, view rep set to default", "@ClintBrown3D")
End If
'------------------------------------------APPLY CHANGES TO DRAWING---------------------------------------
ApplyChanges:
ActiveSheet.View(ClintBrown3D).View.ViewStyle = ViewStyleType
ActiveSheet.View(ClintBrown3D).View.SetDesignViewRepresentation(ViewReptoActivate, True)
Return
'---------------------------------------------------------------------------------------------------------
ClintBrown3D :
Resume Next
MessageBox.Show("OH SNAP! Something Has Gone Terribly WRONG :(", "@ClintBrown3D", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)

 

UPDATE 28 August 2019:

The Code above only works for the views on single sheets. Jerry Berns pointed out on Twitter that if you make a small tweak to the code, that you can use it on multi-sheet drawings.

Clint,
Thanks for sharing a very useful tool.👍

I changed the oDrawingViews line of code as follows:

Dim oDrawingViews As DrawingViews = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews

This allows the active sheet views to be listed for a multi-sheet drawing.

– Jerry