Hi
I thought I would add another rule which you may find useful. Most of it comes from the forum, I added a few small tweaks. Credit is given to the author. This will align views based on a horizontal or vertical line.
'Got this from Bart Den Otter
'Autodesk Forums
'https://forums.autodesk.com/t5/inventor-forum/aligning-views-to-a-line/td-p/7186354
'Good Code
'21.02.2020
Sub Main()
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oCurve1, oCurve2 As DrawingCurveSegment
oCurve1 = GetCurve1(oDoc)
oCurve2 = GetCurve2(oDoc)
Dim oView1, oView2 As DrawingView
oView1 = oCurve1.Parent.Parent
oView2 = oCurve2.Parent.Parent
Dim Curve1Point1, Curve1Point2, Curve2Point1, Curve2Point2, View1Point, View2Point As Point2d
Curve1Point1 = oCurve1.StartPoint
Curve1Point2 = oCurve1.EndPoint
Curve2Point1 = oCurve2.StartPoint
Curve2Point2 = oCurve2.EndPoint
If oView1.Name = oView2.Name Then
MessageBox.Show("Select lines from different views", "Align view error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
Exit Sub
End If
If (Round((Curve1Point1.X - Curve1Point2.X) * 1e8) = 0 And Round((Curve2Point1.X - Curve2Point2.X) * 1e8) = 0) Then
MoveView = Curve1Point1.X - Curve2Point1.X
oView2Point = oView2.Position
oView2Point.X = oView2Point.X + MoveView
oView2.Position = oView2Point
Else If (Round((Curve1Point1.Y - Curve1Point2.Y) * 1e8) = 0 And Round((Curve2Point1.Y - Curve2Point2.Y) * 1e8) = 0) Then
MoveView = Curve1Point1.Y - Curve2Point1.Y
oView2Point = oView2.Position
oView2Point.Y = oView2Point.Y + MoveView
oView2.Position = oView2Point
Else
MessageBox.Show("Lines are not horizontal or vertical or not in the same orientation.", "Align view error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
MsgBox(Curve1Point1.Y - Curve1Point2.Y)
MsgBox(Curve2Point1.Y - Curve2Point2.Y)
Exit Sub
End If
oAgainQ()
End Sub
Sub oAgainQ()
oAgain = MessageBox.Show("Again", "Rinse and Repeat", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If oAgain = vbYes
Main()
End If
End Sub
Private Function GetCurve1(ByVal oDoc As DrawingDocument) As DrawingCurveSegment
Dim Curve As DrawingCurveSegment
Curve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select first line to align")
Return Curve
End Function
Private Function GetCurve2(ByVal oDoc As DrawingDocument) As DrawingCurveSegment
Dim Curve As DrawingCurveSegment
Curve = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select second line to align")
Return Curve
End Function
Reg
2026.1