Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
ThomasB44
1589 Views, 11 Replies

Set view position or center error value

Hi, I have an old code to control views positions. All was working as expected few months ago I guess.

It work for front or side views, with a little lack of precision.

It doesn't work for orthographic and perspective views.

It doesn't seem to work anymore :thinking_face:

I'm using IV2021.2

Here some examples codes to center a view on a sheet. Each command are producing some random results :

Capture.JPG

'SetCenter command
Dim oViewName As String
oViewName = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view :").Name
ActiveSheet.View(oViewName).SetCenter(ActiveSheet.Width / 2, ActiveSheet.Height / 2)
MessageBox.Show("ActiveSheet.View(oView).SetCenter()" _
& vbNewLine & "View center X : " & ActiveSheet.View(oViewName).Center.X _
& vbNewLine & "View center Y : " & ActiveSheet.View(oViewName).Center.Y _
& vbNewLine & "Sheet center X : " & ActiveSheet.Width/2 _
& vbNewLine & "Sheet center Y : " & ActiveSheet.Height/2 , "iLogic")
'SetSpacingToCorner
Dim oViewName As String
oViewName = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view :").Name
Dim CornerX, CornerY As Decimal
CornerX = (ActiveSheet.Width - ActiveSheet.View(oViewName).Width)/2
CornerY = (ActiveSheet.Height - ActiveSheet.View(oViewName).Height)/2
ActiveSheet.View(oViewName).SetSpacingToCorner(CornerX, CornerY, SheetCorner.TopLeft)
MessageBox.Show("ActiveSheet.View(oView).SetCenter()" _
& vbNewLine & "View center X : " & ActiveSheet.View(oViewName).Center.X _
& vbNewLine & "View center Y : " & ActiveSheet.View(oViewName).Center.Y _
& vbNewLine & "Sheet center X : " & ActiveSheet.Width/2 _
& vbNewLine & "Sheet center Y : " & ActiveSheet.Height/2 , "iLogic")
'oBaseView.Position
Dim oDoc As DrawingDocument
oDoc = ThisDrawing.Document
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oBaseView As DrawingView
oBaseView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view :")
Dim oViewName As String
oViewName = oBaseView.Name
Dim oTG As TransientGeometry 
oTG = ThisApplication.TransientGeometry
Dim oOriginPoint As Point2d
oOriginPoint = oTG.CreatePoint2d(oSheet.Width/2, oSheet.Height/2)
oBaseView.Position = oOriginPoint
MessageBox.Show("oBaseView.Position" _
& vbNewLine & "View center X : " & oBaseView.Center.X*10 _
& vbNewLine & "View center Y : " & oBaseView.Center.Y*10 _
& vbNewLine & "Sheet center X : " & oSheet.Width/2*10 _
& vbNewLine & "Sheet center Y : " & oSheet.Height / 2*10, "iLogic")

 

'oBaseView.Center
Dim oDoc As DrawingDocument
oDoc = ThisDrawing.Document
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oBaseView As DrawingView
oBaseView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a view :")
Dim oViewName As String
oViewName = oBaseView.Name
Dim oTG As TransientGeometry 
oTG = ThisApplication.TransientGeometry
Dim oOriginPoint As Point2d
oOriginPoint = oTG.CreatePoint2d(oSheet.Width/2, oSheet.Height/2)
oBaseView.Center = oOriginPoint
MessageBox.Show("oBaseView.Center" _
& vbNewLine & "View center X : " & oBaseView.Center.X*10 _
& vbNewLine & "View center Y : " & oBaseView.Center.Y*10 _
& vbNewLine & "Sheet center X : " & oSheet.Width/2*10 _
& vbNewLine & "Sheet center Y : " & oSheet.Height / 2*10, "iLogic")

Can you reproduce this ?

Any ideas ?


Thomas
Mechanical Designer / Inventor Professionnal 2025
Inventor Professional EESignature