Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
A.Acheson
in reply to: cadman777

Here is two rules I am using for drawings with view reps. They seem to work well. You may need to do some customizing  of rule 1 as  there is a filter to only create views with certain names. "If oDesView.Name.Contains("SP") Then", so simply remove the if statement for all view reps. 

 

  1. Views created from view reps
'https://forums.autodesk.com/t5/inventor-customization/ilogic-drawing-view-height-and-size-problem/td-p/9256794
'https://forums.autodesk.com/t5/inventor-forum/place-all-design-views-on-an-idw/td-p/6035731

Sub Main
	CreateViewForEachRep()
End Sub
Public Sub CreateViewForEachRep()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
     oDrawDoc = ThisApplication.ActiveDocument
    
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
     oSheet = oDrawDoc.ActiveSheet
    
    Dim viewScale As Double
     viewScale = 1/20
    
    Dim ptx As Long
     ptx = 0
	 
    'this assumes that view1 is of the full assembly - a view must have been placed in a drawing before running this
    Dim assyDocName As String
     assyDocName = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.FullDocumentName
        
    Dim assyDoc As AssemblyDocument
    'open assembly doc invisibly
     assyDoc = ThisApplication.Documents.Open(assyDocName, False)
        
    Dim oAssyCompDef As AssemblyComponentDefinition
     oAssyCompDef = assyDoc.ComponentDefinition
    
    Dim oRepMgr As RepresentationsManager
     oRepMgr = oAssyCompDef.RepresentationsManager
    
    Dim oDesView As DesignViewRepresentation
    
    For Each oDesView In oRepMgr.DesignViewRepresentations
     
           If oDesView.Name.Contains("SP") Then
			   
            Dim oPoint1 As Point2d
             oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(ptx, 11)
            
            Call PlaceBaseView(oSheet, assyDoc, oPoint1, oDesView.Name,viewScale)
              
        End If
        ptx = ptx + 6
		'ptx = ptx + 2 +(VWidth/2)
    Next
      
      'close assembly doc
      assyDoc.Close (False)
      
End Sub

Public Sub PlaceBaseView(ByRef sheet As Inventor.Sheet, _
                        ByRef assyDoc As AssemblyDocument, _
                        ByRef oPoint1 As Point2d, _
                        ByRef viewName As String, _
						ByRef viewScale As Double)

    'define view orientation
    Dim vieworient1 As ViewOrientationTypeEnum
     vieworient1 = ViewOrientationTypeEnum.kFrontViewOrientation

    'define view style
    Dim viewstyle1 As DrawingViewStyleEnum
     viewstyle1 = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle
   
    Dim oFaceView As DrawingView
	
     oFaceView = sheet.DrawingViews.AddBaseView(assyDoc, oPoint1, viewScale, vieworient1, viewstyle1, viewName)'viewScale
	 
	 'Set view reps associative so they update when model changes. Othewise they are a static image
	oFaceView.SetDesignViewRepresentation(viewName,True)
End Sub

 

2. Set View Labels based on ViewRep

AAcheson_0-1637022477887.png

 

'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-math-function-to-see-what-lenght-fits-the-best/td-p/10511825
Sub Main
	
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDrawing.Document
Dim oModel As AssemblyDocument
oModel = ThisDoc.ModelDocument
Dim NameQty As New Dictionary(Of String, Double)
Dim sViewRepNames As New ArrayList
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim MFGQTY As String
Dim sViewRepName As String 

oSheets = oDrawDoc.Sheets
Dim i As Integer = 0

Call TraverseBOM(oModel, NameQty)

For Each oSheet In oSheets
	oViews = oSheet.DrawingViews
	
    For Each oView In oViews
		'make view label visible
		 oView.ShowLabel = True
		Try
		sViewRepName = oView.ActiveDesignViewRepresentation.ToString
		'MessageBox.Show(sViewRepName, "Title")
		sViewRepNames.Add(sViewRepName)
		Catch
			MessageBox.Show("View Rep not associative" , "Title")
		End Try
		
		For Each pair As KeyValuePair(Of String, Double) In NameQty
		If pair.Key = sViewRepName Then
			If pair.Value = 1 Then
				
				sString1 = "<DrawingViewName/>"
				sString2 = sViewRepName 
				'sString3 = "QTY: " & pair.Value 
				
				'add lines to the view label
				'break line using:  "<Br/>" 
			    oView.Label.FormattedText = _
			    sString1 & "<Br/>" & _
			    sString2 & "<Br/>" '& _
				'sString3 & "<Br/>"	
					
			ElseIf pair.Value > 1 Then
				sString1 = "<DrawingViewName/>"
				sString2 = sViewRepName 
				sString3 = "QTY: " & pair.Value 
				
				'add lines to the view label
				'break line using:  "<Br/>" 
			    oView.Label.FormattedText = _
			    sString1 & "<Br/>" & _
			    sString2 & "<Br/>" & _
				sString3 & "<Br/>"	
			End If
		End If
	
		Next
	Next
	
Next
d0 = InputListBox("Prompt", NameQty, d0, Title := "Title", ListName := "List")
d0 = InputListBox("Prompt", sViewRepNames, d0, Title := "Title", ListName := "List")
End Sub

Public Sub TraverseBOM(oModel, NameQty )

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oModel.ComponentDefinition

'[Traverse the BOM
'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-get-properties-from-bom/td-p/9204275
For Each oBOMView As BOMView In oAsmCompDef.BOM.BOMViews
	'Logger.Info("looping through BOM")
	If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
		On Error Resume Next
		For Each oBOMRow As BOMRow In oBOMView.BOMRows
			Dim oDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
			'Logger.Info(oDoc.DisplayName)
			Dim oDTP As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
			'Dim oItemNum As String = oBOMRow.ItemNumber
			Dim oPN As String = oDTP.Item("Part Number").Value.ToString
				
			Dim oDesc As String = oDTP.Item("Description").Value.ToString
			Dim Qty As String = oBOMRow.TotalQuantity
			
			'Deal with non numeric qty in BOM
			numericCheck = IsNumeric(Qty)
			If numericCheck = True Then
				'Add to dictionary of string,double
				'Note, the string part is so we can return a reference later.
				NameQty.Add(oPN, Qty)
			 
			Else
			'MessageBox.Show("Input is NOT numeric.", "iLogic")
			End If
		Next
		']
	    	
	End If
Next

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan