discover sheet-reorder APIs

discover sheet-reorder APIs

t_fransman
Advocate Advocate
231 Views
8 Replies
Message 1 of 9

discover sheet-reorder APIs

t_fransman
Advocate
Advocate

is there a way to get access to sheet order i am exporting single parts ( fab's ) from a master drawing and i'd like to reorder them automatically based on the 1st item number on the first bill in order of sheet than the next sheet first to last etcc. until all ( fab'd) parts are on the doc in matching orders. 

Accepted solutions (2)
232 Views
8 Replies
Replies (8)
Message 2 of 9

t_fransman
Advocate
Advocate

t_fransman_0-1789499492568.png

 

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @t_fransman.  It is not super clear what you are looking for, but yes, it is possible to reorder sheets in a drawing.  We just can't change the 'sheet number' without reordering the sheets, because the sheet number value is automated by Inventor, outside of our control, going by the order they appear in the model browser tree.  It is a bit more difficult than it should be though, because there is no built-in or native 'Method' specifically for moving Sheets in a drawing.  So, we have to do it though the model browser tree and its methods defined in the Inventor API.  You may already be familiar with the following lines of code, but I will post them here, just in case the help some.  They help us separate the Sheet.Name value into the true SheetName and SheetNumber values.  In the following example, it is assumed that the 'oSheet' variable is a Sheet Type variable that has already been assigned a value.

Dim oSheetNameParts() As String = oSheet.Name.Split(":")
Dim sSheetName As String = oSheetNameParts.First()
Dim sSheetNumber As String = oSheetNameParts.Last()
Dim iSheetNumber As Integer = Integer.Parse(sSheetNumber)

The main method involved in the model browser tree route is the BrowserPane.Reorder method.  But to use it, you must first get the 'Model' BrowserPane, then get the BrowserNode object for the two Sheet objects that you want to reorder.  And due to how that method works, we can only reorder that one/two Sheets at a time.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

dalton_northwind
Enthusiast
Enthusiast
Accepted solution

Try this:

https://forums.autodesk.com/t5/inventor-programming-forum/changing-sheet-order-of-dwg-with-ilogic/td...

 

Dim oDDoc As DrawingDocument = ThisDoc.Document

Dim oSheet1 As Sheet = oDDoc.ActiveSheet

Dim oPartsList As PartsList = oSheet1.PartsLists(1)

'create a list of the part list rows
Dim oPartsListRows As List(Of PartsListRow) = oPartsList.PartsListRows.Cast(Of PartsListRow).ToList()
'create a list of the parts list rows' filename
Dim PartsListRowsName = oPartsListRows.Select(Function(x) x.ReferencedRows(1).BOMRow.ReferencedFileDescriptor.ReferencedFile.FullFileName).ToList()

'create a list of all sheets
Dim oSheets As List(Of Inventor.Sheet) = oDDoc.Sheets.Cast(Of Sheet).ToList()
oSheets.Remove(oSheet1)

'sort sheet list by other list
Dim oSheetsSorted As List(Of Inventor.Sheet) = oSheets.OrderBy(Function(item) _
PartsListRowsName.IndexOf(item.DrawingViews.Item(1).ReferencedDocumentDescriptor.ReferencedDocument.FullDocumentName)).ToList()

Dim oPane As BrowserPane = oDDoc.BrowserPanes.ActivePane
Dim oPreviousNode As BrowserNode = oPane.GetBrowserNodeFromObject(oDDoc.Sheets.Item(2))

For Each oSheet As Inventor.Sheet In oSheetsSorted
	Dim oSheetNode As BrowserNode = oPane.GetBrowserNodeFromObject(oSheet)
	Try
		oPane.Reorder(oPreviousNode, True, oSheetNode) 'threw an error on the last one
	Catch : Continue For : End Try
	oPrevousNode = oSheetNode
Next

 

Message 5 of 9

WCrihfield
Mentor
Mentor
Accepted solution

Hi @t_fransman.  Since I do not know how capable you may be at developing your own custom iLogic rules yet, below is the code for an unfinished iLogic rule which contains a custom Sub routine specifically for reordering drawing sheets.  Before you call that custom Sub routine to run, you will first need to customize the block of code that will add each Sheet of your drawing to that List, in the order you want them to be in when done.  Once that is done, just call the custom Sub routine to process that List of sheets, and it will reorder the Sheets in the model browser tree to the same order they are in that input List.  I do not know what order you need them to be in based solely on the brief, difficult to understand comments in your first post.

It looks like the example code provided by @dalton_northwind will try to order them according to the order of the rows in a PartsList that if expects to find on the initially active sheet of the drawing, going by the FullFileName match of the item in that row, and the first view found within each Sheet.  Nice job @dalton_northwind.

Sub Main
	Dim oDDoc As Inventor.DrawingDocument = TryCast(ThisApplication.ActiveDocument, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oOrderedSheets As List(Of Inventor.Sheet) = New List(Of Inventor.Sheet)
	
	'<<< your custom block of code here to add all Sheets in this drawing to this List, >>>
	'<<< in the order you want them to be arranged >>>
	
	'when done, call the custom Sub routine to reorder the actual Sheets that way
	ReorderSheets(oOrderedSheets)
	oDDoc.Update2(True)
End Sub

''' <summary>
''' Reorder drawing sheets according to the input List of sheets
''' </summary>
''' <param name="SheetsList">A List of drawing sheets ordered the way you want them</param>
Sub ReorderSheets(SheetsList As List(Of Inventor.Sheet))
	If (SheetsList Is Nothing) OrElse (SheetsList.Count = 0) Then Exit Sub
	Dim oDDoc As Inventor.DrawingDocument = TryCast(SheetsList.Item(0).Parent, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Exit Sub
	Dim oBPane As Inventor.BrowserPane = oDDoc.BrowserPanes.Item("DlHierarchy")
	Dim oPrev As Inventor.BrowserNode = oBPane.GetBrowserNodeFromObject(SheetsList.Last())
	Dim oThisNode As Inventor.BrowserNode = Nothing
	For i As Integer = SheetsList.Count - 1 To 0 Step -1
		oThisNode = oBPane.GetBrowserNodeFromObject(SheetsList.Item(i))
		If oThisNode Is oPrev Then Continue For
		Try
			oBPane.Reorder(oPrev, True, oThisNode)
			oPrev = oThisNode
		Catch
		End Try
	Next 'i
	oBPane.Update()
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 9

t_fransman
Advocate
Advocate

ok i will look at all of these ideas, basically when i export them from the parent drawing i want the child drawing to not duplicate the existing sheets so dimensions etc... aren't lost. Make a new sheet if a part is added, remove a sheet if the part no longer lives in the parent BOM. I have Create missing sheets, Refresh the border individual to ea. sheet,  Self heal if someone moves the text that looks at each part (.ipt) and fills the border, just need next to order sheets by ITEM #. And then reorder them (after naming the tree the same ITEM 1 for example). So it's easy to see if one is needed or not needed and/or they are in order.  And then i'll work on auto scale auto align the views etc. It places a flat and formed view many other small things already done

 

0 Likes
Message 7 of 9

t_fransman
Advocate
Advocate

May be superseded if the auto drawing create stuff in the Alpha is ever released to the masses, but works for now as busy work. Really need the auto dimension for the sheets as well that they are demo-ing, if that's a word. 

0 Likes
Message 8 of 9

t_fransman
Advocate
Advocate

I got this to so far take sheet 1 and slide it down one move per click. More so need to look at the BOM in a drawing and reorder to match. I have the add/ remove working to eliminate sheets if not in the BOM already. And a lot of other Company specific things done. Thanks so much all, I'll keep digging, and see if I can use this. It may be that I have it in the wrong context, (as a side kick in the -Details drawing i create auto instead of the parent drawing where the large rule exists). Really useful so far guys thank you ( and Ai). 

0 Likes
Message 9 of 9

t_fransman
Advocate
Advocate

I was able to solve it with the help here, after some tweaking (with some Help from Ai) Thanks All

0 Likes