Message 1 of 12
Automatic Scale and View Position
Not applicable
08-24-2015
07:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I made an iLogic code that automatically scales the views to fit the sheet and moves them to the correct place. I use this when I have parametric parts that change size from small to big and them don't fit the sheet.
As specified in the code the views must follow a specific order and name in the sheet:
The pattern view name should be this one, but it's not needed to have all views, it works from 1 up to 5 views automatically.
It's working just fine for me. But any improvements that i can had? any ideas to make it better?
' Automatic Scale and Position for Autodesk Inventor Drawings.
' V1.0 - 2015-08-24
' Views should follow an specific order and name.
'Views should follow this names and position but it's not needed to have them all! It works from only 1 view up to all 5 views.
'If they are not there the program will ignore.
'User request play in YY & YY axis
'Play in relation to the sheet size. It allows space for the Title Block and other notes if needed.
SheetPlayX = 100
SheetPlayY = 100
'User Fine Tune - In this you can fine tune some distances.
'Deviation X will move all views to right if positive or to left if negative.
'Deviation Y will move all views up if positive or down if negative. Normally used to move views up when there is a title block in the bottom.
deviation_X = 0
deviation_Y = 0
play_between_views = 0
'Define variables
Dim View(0 To 5) As String
Dim CenterX(0 To 5) As Single
Dim CenterY(0 To 5) As Single
Dim ViewHeight(0 To 5) As Single
Dim ViewWidth(0 To 5) As Single
Dim PlayX(0 To 3) As Single
Dim PlayY(0 To 3) As Single
ViewQtX = 0
ViewQtY = 0
'Determine the maximum available space in the sheet subtracting the play in x&Y and between views requested by the user.
SheetWidth = ActiveSheet.Width - SheetPlayX - play_between_views
SheetHeight = ActiveSheet.Height - SheetPlayY - play_between_views
'Define the name of each view.
View(1)="VIEW1"
View(2)="VIEW2"
View(3)="VIEW3"
View(4)="VIEW4"
View(5)="VIEW5"
'Determines the current scale of the main view (VIEW 1). It only reads the main one because it assumes that all other views are in the same scale.
CurrentScale=ActiveSheet.View(View(1)).Scale
' Try to find the width and height of each view in scale 1:1. If not found instead of give an error, makes it equal to zero.
For i=1 To 5
Try
ViewHeight(i)=ActiveSheet.View(View(i)).Height*(1/CurrentScale)
ViewWidth(i)=ActiveSheet.View(View(i)).Width*(1/CurrentScale)
Catch
ViewHeight(i)=0
ViewWidth(i)=0
End Try
Next
'Determines the max width and height that all views occupy in scale 1:1
MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3)
MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2)
'Width maximum height/width and maximum sheet size determine what scale is needed to fit in the sheet.
ScaleX = SheetWidth / MaxWidth
ScaleY = SheetHeight / MaxHeight
FinalScale = Min(ScaleY,ScaleX)
'Apply the final scale to the Main view rounded to the nearest .25
If FinalScale <1 Then
FinalScale = FinalScale^-1
inc = .25
FinalScale = Round(Round(FinalScale,2) / inc) * inc
ActiveSheet.View(View(1)).ScaleString="1/"&FinalScale
Else
inc = .25
FinalScale = Round(Round(FinalScale,2) / inc) * inc
ActiveSheet.View(View(1)).Scale=FinalScale
End If
'Writes to an custom iPropertie the scale
iProperties.Value("Custom", "Scale")=ActiveSheet.View(View(1)).ScaleString
'Reads the new height and width of each view.
For i=1 To 5
Try
ViewHeight(i)=ActiveSheet.View(View(i)).Height
ViewWidth(i)=ActiveSheet.View(View(i)).Width
Catch
ViewHeight(i)=0
ViewWidth(i)=0
End Try
Next
'Determine the new maximum width and height occupied by all views in the current scale.
MaxWidth = ViewWidth(5) + ViewWidth(1) + ViewWidth(3)
MaxHeight = ViewHeight(4) + ViewHeight(1) + ViewHeight(2)
'Determine how many rows and columns of views there are.
If ViewWidth(5)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(1)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(3)<>0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewHeight(4)<>0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(1)<>0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(2)<>0 Then
NumberViewsY = NumberViewsY+1
End If
'Width the new views width and height determine the available space in the sheet and divides by the number of views + 1/
'to determine how much play can be left between views. To that play also adds the user requested play_between_views.
PlayX(0) = (ActiveSheet.Width - MaxWidth) /(NumberViewsX+1)
PlayY(0) = (ActiveSheet.Height - MaxHeight) /(NumberViewsY+1)
If ViewWidth(5)<>0 Then
PlayX(1) = PlayX(0) + play_between_views
End If
If ViewWidth(1)<>0 Then
PlayX(2) = PlayX(0) + play_between_views
End If
If ViewHeight(2)<>0 Then
PlayY(1)=PlayY(0) + play_between_views
End If
If ViewHeight(1)<>0 Then
PlayY(2)=PlayY(0) + play_between_views
End If
'Defines the all views position. By default they are centred and equally spaced, but if the user adds any X/Y/view play it will relocated accordingly.
CenterX(5)= PlayX(0) + deviation_X + ViewWidth(5)/2
CenterX(1)= CenterX(5) + ViewWidth(5)/2 + PlayX(1) + ViewWidth(1)/2
CenterX(3)= CenterX(1) + ViewWidth(1)/2 + PlayX(2) + ViewWidth(3)/2
CenterX(2)= CenterX(1)
CenterX(4)= CenterX(1)
CenterY(2)= PlayY(0) + deviation_Y + ViewHeight(2)/2
CenterY(1)= CenterY(2) + ViewHeight(2)/2 + PlayY(1) + ViewHeight(1)/2
CenterY(4)= CenterY(1) + ViewHeight(1)/2 + PlayY(2) + ViewHeight(4)/2
CenterY(5)=CenterY(1)
CenterY(3)=CenterY(1)
'Apply to all views the new location
For i=1 To 5
Try
ActiveSheet.View(View(i)).SetCenter(CenterX(i),CenterY(i))
Catch
End Try
Next
'Update Inventor Drawing
InventorVb.DocumentUpdate()
'(c)2015 Fabmsg
