Hi
Here is my most used code. There are two rules. One for the views, and I made a second one for the labels. (For some reason or other it does not work 100% of the time, any improvements to the code will be welcome. I have use snippets found on the forum.
'27.11.2019
'No frills code to align the views along the bottom edge.
Sub Main()
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
Dim oItems As ObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDoc As Document = ThisDoc.Document
Dim oSelection As SelectSet = oDoc.SelectSet
'If oSelection Is Nothing Then
If oSSet.Count <2 Then
MessageBox.Show("Nothing selected", "iLogic", MessageBoxButtons.OK)
Exit Sub
End If
' Dim oItems As ObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection ' Removed for 2.1 as it is now declared earlier
For Each Item As Object In oSelection
If Not TypeOf(Item) Is DrawingView Then Continue For 'DrawingViews only
oItems.Add(Item)
Next
oDoc.SelectSet.SelectMultiple(oItems)
oHor_Bott(oItems)
End Sub
'=========================================================================================================
Sub oHor_Bott(oItems)
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document
Dim oView As DrawingView
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim trans As Transaction
trans = ThisApplication.TransactionManager.StartTransaction(oDrawDoc, "Align Views")
'Dim oSSet As SelectSet = oDrawDoc.SelectSet
'For Each oView In oSSet
Dim oFirstView As DrawingView = TryCast(oItems.item(1), DrawingView)
Dim YPos As Double
YPos = oFirstView.Position.Y - (oFirstView.Height/2)
Dim oPoint2D As Inventor.Point2d
For Each oView In oItems
oPoint2D = ThisApplication.TransientGeometry.CreatePoint2d(oView.Position.X,YPos + (oView.Height/2))
oView.Position = oPoint2D
Next
trans.End
Dim oDoc As Document = ThisDoc.Document
oDoc.SelectSet.SelectMultiple(oItems)
End Sub
Align Labels:
'27.11.2019
'No frills code to align the views along the bottom selected Line.
'This is just for a quicker method, as this is the most used command.
Sub Main()
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
Dim oItems As ObjectsEnumerator = ThisApplication.TransientObjects.CreateObjectCollection
Dim oDoc As Document = ThisDoc.Document
Dim oSelection As SelectSet = oDoc.SelectSet
'If oSelection Is Nothing Then
If oSSet.Count <1 Then
MessageBox.Show("Nothing selected", "iLogic", MessageBoxButtons.OK)
Exit Sub
End If
For Each Item As Object In oSelection
If Not TypeOf(Item) Is DrawingView Then Continue For 'DrawingViews only
oItems.Add(Item)
Next
oDoc.SelectSet.SelectMultiple(oItems)
Align_Labels(oItems)
End Sub
'=========================================================================================================
Sub Align_Labels(oItems)
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document
Dim oView As DrawingView
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim trans As Transaction
trans = ThisApplication.TransactionManager.StartTransaction(oDrawDoc, "Align Views")
'Dim oSSet As SelectSet = oDrawDoc.SelectSet
'
Dim oNewPosition As Point2d
oNewPOS = InputBox("Add Offset?", "Title", 1)
oNewPOS /= 10
For Each oView In oItems
oNewPosition = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X, oView.Center.Y - (oView.Height / 2)-( 1+oNewPOS))
oView.Label.Position = oNewPosition
Next
trans.End
Dim oDoc As Document = ThisDoc.Document
oDoc.SelectSet.SelectMultiple(oItems)
End Sub
Reg
2026.1