- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
NextThe 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?
Solved! Go to Solution.