Inventor VBA - Changing view position

Inventor VBA - Changing view position

basnederveen
Advocate Advocate
1,949 Views
2 Replies
Message 1 of 3

Inventor VBA - Changing view position

basnederveen
Advocate
Advocate

Hello,

 

I am trying to change the position of multiple views through VBA in inventor. 

 

My 'Test Code' can be found below;

 

Sub aligntest()

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
Set oSheet = ThisApplication.ActiveDocument.ActiveSheet

Dim Xpos1 As Double
Dim Ypos1 As Double

Dim oSS As SelectSet
Set oSS = oDrawDoc.SelectSet

Dim oPos As Point2d
Dim oPos1 As Point2d

Dim oDrawingView As DrawingView
Dim oDrawingView1 As DrawingView

Dim j As Double
j = 0

' find first view
For j = 1 To oSS.Count
    If oSS.Item(j).Type = kDrawingViewObject Then
        Set oDrawingView1 = oSS.Item(j)
        Set oPos1 = oDrawingView1.Position
        
        Ypos1 = oPos1.Y
        Xpos1 = oPos1.X
        Exit For
    End If
Next
            
Dim l As Double
l = 0
            
For l = 1 To oSS.Count
    If oSS.Item(l).Type = kDrawingViewObject Then
        Set oDrawingView = oSS.Item(l)
        Set oPos = oDrawingView.Position
        
        oPos.Y = Ypos1
        ' oPos.X = Xpos1 
        
        oDrawingView.Position = oPos
    End If
Next

The problem I found with this code is as soon as it moves the first view to the desired location, the selectset dissappears.. Is there a way to maintain selectset after moving a view? Or reselecting the same items?

 

The reason I made this 'test sub' is because Im trying to align views from a userform. The form finds all the views in a sheet, and then gives the user a few options that can be executed on these views. One of them should be align the views. I have all the views in the sheet coming up in a listbox. Then I I get selected rows from the listbox and try to find the view. 

 

Its a 10 column listbox, down here is the code that runs when pressing the align views button.

 

Private Sub CommandButton8_Click()
' align views horizontal
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' set ook activesheet degene waarvan de views gepakt worden
Dim oSheet As Sheet
Set oSheet = ThisApplication.ActiveDocument.ActiveSheet

' Dont need all tihs
Dim Xpos As Double
Dim Ypos As Double
Dim Width As Double
Dim Length As Double
Dim Xpos1 As Double
Dim Ypos1 As Double
Dim Width1 As Double
Dim Length1 As Double
Dim oScale As Double
Dim oScale1 As Double

'Dim ViewBottomLeftCornerX As Double
'Dim ViewBottomLeftCornerX1 As Double
'Dim ViewBottomLeftCornerY As Double
' Dim ViewBottomLeftCornerY1 As Double

Dim j As Double
j = 0

With Me.ListBox2
    For j = 0 To .ListCount - 1
        If .Selected(j) Then
        
            oScale1 = .List(1, 2)
            Top1 = .List(1, 8) '* oScale / 10)
            Height1 = .List(1, 4) '* oScale / 10)
            Xpos1 = .List(1, 5)
            Ypos1 = .List(1, 6)
            
            oScale = .List(j, 2)
            Top = (.List(j, 3) * oScale / 10)
            Height = (.List(j, 4) * oScale / 10)
            Xpos = .List(j, 5)
            Ypos = .List(j, 6)
                  
            Dim oPos As Point2d
            Dim oDrawingView As DrawingView

            For i = 1 To oDrawDoc.ActiveSheet.DrawingViews.Count
                If Left(oDrawDoc.ActiveSheet.DrawingViews.Item(i).Position.X, 5) = Left(Xpos, 5) And Left(oDrawDoc.ActiveSheet.DrawingViews.Item(i).Position.Y, 5) = Left(Ypos, 5) Then
                    Set oDrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(i)
                    Set oPos = oDrawingView.Position
                                           
                    oPos.Y = Ypos1
                    oDrawingView.Position = oPos
                    
                    
                End If
            Next
        End If
    Next
End With

End Sub

 

Problem here is that as soon as the views are aligned by the code (i put the .List(1, Column) because I was just testing with 3 views, I have to make it so the first selected view is taken) the userform 'minimizes'.. I have never seen this before, and I hope someone here knows what is happening!

 

I've attached a screenshot of what's left of my userform when I run the align views code..

 

Due to this happening after moving views, and also the selectset dissappearing after moving a view, I get the idea something is going wrong, or that this is normal when repositioning a view..

 

Does anyone here know what is up?

 

0 Likes
Accepted solutions (1)
1,950 Views
2 Replies
Replies (2)
Message 2 of 3

basnederveen
Advocate
Advocate

Small update;

 

Just now I commented a few of the lines of code getting the listbox values, and suddenly what is left of my userform after aligning is more. Screenshot attached.

0 Likes
Message 3 of 3

basnederveen
Advocate
Advocate
Accepted solution

With the userform it is fixed somehow. I dont know why. I think it might have something to do with the width and scale declarations, i've changed the names now there are no more problems with the userform.

 

The selectset problem is still occurring though.

0 Likes