Tuesday, 18 July 2017

iLogic to Align Drawing Views

Hey.
It's been a while.

In response to a Forum post, I stared playing around with some code I found here:
https://www.cadlinecommunity.co.uk/hc/en-us/articles/202280491-Inventor-2015-iLogic-Accurately-Position-Drawing-Views

I then happened to come across another post by Adrian Salariu. Random Stuff

Using the two bits of code and a little perseverance and tinkering, I have managed to make my own tool.

The code allows a greater selection of alignment. I foresee its use in drawings where I have multiple section and detail views, previously I would normally "eyeball" the alignment between the various views.
NOTE:
If you decide to use, please share any improvements.

Enjoy
Reg

Start of the Code:




'Reg Hasell
'18/07/2017
'This will align the selected views on the drawings sheet
'A minimum of two views must be selected.
'The first view selected will be the Anchor. (Base View)
'A section of the code was taken from the forum
'Thanks to Adrian Salariu, I stole the First view Co-Ordinates from him.
'I then changed everything to suit my personal needs.

Sub Main()
Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.count <2 Then
    MessageBox.Show("A Minimum of two views must be seleted first", "iLogic")
    Return
End If
oMenu()
End Sub

Sub oMenu()
Dim oResu1t As String="Result"
Dim oLst As New ArrayList
oLst.Add("Vert - Left")
oLst.Add("Vert - Right")
oLst.Add("Vert - CL")
oLst.Add("")
oLst.Add("Hor - Top")
oLst.Add("Hor - Bottom")
oLst.Add("Hor - CL")

'Display table and get the selection
oResu1t=InputListBox("Select Alignment", oLst, oResu1t, _
Title := "View Alignment", ListName := "View Alignment")

'Set iProperties based on the selection.
If oResu1t="Vert - Left" Then
Call oVert_Left()
ElseIf oResu1t="Vert - Right" Then
Call oVert_Right()
ElseIf oResu1t="Vert - CL" Then
Call oVert_CL()
ElseIf oResu1t="Hor - Top" Then
Call oHor_Top()
ElseIf oResu1t="Hor - Bottom" Then
Call oHor_Bott()
ElseIf oResu1t="Hor - CL" Then
Call oHor_CL ()
End If
End Sub

'''****************************************************
'''----------------------------------------------------
'''****************************************************

Sub oVert_Left()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
       'views are processed by center so we need to get center X and substract half view
        Dim XPos As Double
        XPos = oFirstView.Position.X - (oFirstView.Width/2)
        Dim oPoint2D As Inventor.Point2D
        'view position Is XPos + half Of Each view
 For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
           oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(XPos + (oView.Width/2),oView.Position.Y)
           oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

'''****************************************************
'''----------------------------------------------------
'''****************************************************

Sub oVert_Right()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
        'views are processed by center so we need to get center X and substract half view
        Dim XPos As Double
        XPos = oFirstView.Position.X + (oFirstView.Width/2)
        Dim oPoint2D As Inventor.Point2D
        'view position Is XPos + half Of Each view
 For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
        oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(XPos - (oView.Width/2),oView.Position.Y)
           oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

'''****************************************************
'''----------------------------------------------------
'''****************************************************

Sub oVert_CL()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
        'views are processed by center so we need to get center X and substract half view
        Dim XPos As Double
        XPos = oFirstView.Position.X
        Dim oPoint2D As Inventor.Point2D

         For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
            oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(XPos,oView.Position.Y)
            oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

'''****************************************************
'''----------------------------------------------------
'''****************************************************

Sub oHor_Top()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
        'views are processed by center so we need to get center X and substract half view
        'Dim XPos As Double
        Dim YPos As Double
        'XPos = oFirstView.Position.X + (oFirstView.Width/2)
        YPos = oFirstView.Position.Y + (oFirstView.Height/2)
        Dim oPoint2D As Inventor.Point2D

         For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
            oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(oView.Position.X,YPos - (oView.Height/2))
            oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

'****************************************************
'----------------------------------------------------
'****************************************************

Sub oHor_Bott()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
       'views are processed by center so we need to get center X and substract half view

        'Dim XPos As Double
        Dim YPos As Double
        'XPos = oFirstView.Position.X - (oFirstView.Width/2)
        YPos = oFirstView.Position.Y - (oFirstView.Height/2)
        Dim oPoint2D As Inventor.Point2D

         For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
            oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(oView.Position.X,YPos + (oView.Height/2))
           oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

'****************************************************
'----------------------------------------------------
'****************************************************

Sub oHor_CL()
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
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(oSSet.item(1), DrawingView)
        'views are processed by center so we need to get center X and substract half view
        Dim XPos As Double
        Dim YPos As Double
            XPos = oFirstView.Position.X + (oFirstView.Width)
            YPos = oFirstView.Position.Y
        Dim oPoint2D As Inventor.Point2D

         For Each oView In oSSet
    'For Each oView In oSheet.DrawingViews
            oPoint2D = ThisApplication.TransientGeometry.CreatePoint2D(oView.Position.X,YPos)
           oView.Position = oPoint2D
        Next
       
'finish the transaction
trans.End
End Sub

No comments:

Post a Comment