Hello,
I have this code that will scale a drawingview & then it will position it to the center of the sheet.
The behavior is most of the time OK, but sometimes the view just really out of the center. What is the reason for this?
What is also the difference between oDrawView.Center & oDrawView.Postion? They seam to do exactly the same. Could the issue be cause of this?
We almost always use a normal base view & a overlay (to highlight some parts)
See example of the view misplaced by this code:This is my code:
Public Sub AutoScale() 'Scale all views on all pages to fit nicely on the sheets 'step 0. declare stuff Dim oDrawDoc As DrawingDocument Dim oSheet As Sheet Dim oDrawView As DrawingView Set oDrawDoc = ThisApplication.ActiveDocument ' step 2. Process all pages Dim i As Integer i = 3 For i = 3 To oDrawDoc.Sheets.Count Set oSheet = oDrawDoc.Sheets.Item(i) Set oDrawView = oSheet.DrawingViews.Item(1) Call ProcessPages(oSheet, oDrawView) Next End Sub Private Sub ProcessPages(ByVal oSheet As Sheet, ByVal oDrawView As DrawingView) ' step 1 get current drawingscale Dim oDrawViewScale As Double oDrawViewScale = oDrawView.Scale ' step 2 Determine the best scale by looking at the view widths. Dim dWidthScale As Double dWidthScale = (oSheet.Width - 5) / oDrawView.Width * oDrawViewScale '5cm = distance to stay away from sides ' step 3 Determine the best scale by looking at the view heights. Dim dHeightScale As Double dHeightScale = (oSheet.Height - 9) / oDrawView.Height * oDrawViewScale '9cm = distance to stay away from top and bottom (including the header) ' step 4 Choose the best scale Dim ComputeViewScale As Double If dWidthScale < dHeightScale Then ComputeViewScale = dWidthScale Else ComputeViewScale = dHeightScale End If ' step 5 set the correct scale oDrawView.ScaleString = ComputeViewScale 'step 6 set the location of the view Dim CenterPoint As Point2d 'place above the center of the page (2cm) ' - - - - I believe it goes wrong here - - - - ' ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - Set CenterPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2) oDrawView.Center = CenterPoint ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - ' - - - - I believe it goes wrong here - - - - ' End Sub
thank you all for your input!
Solved! Go to Solution.
From API help:
Center | Gets and sets the display center point of the drawing view on the owning sheet. |
Position | Gets and sets the point used to position the drawing view on the sheet. |
Po position the view you should use the ".Position" property. That should solve your issue.
Hello,
I have tested my code with ".postion" a bit but this I keep encountering the non-predictable behavior.
I also see that depending the where you create your sketch (first click on a model or first click on the sheet) the scale of your sketch is different.
Maybe this has something to do with it? Maybe I need to put in a multiplicator or something?
example 1: 100mm in sketch based on view
Example 2: 100mm in sketch based on sheet
Depending on the API calls you are using, some of them are scaled by the view scale, so you may need to account for that in your code. I think oView.Height and oView.Width are both affected by this.
Hello,
I have Changed the code a bit for compensating the offset by deducating ''the center-location of the view itself'' from the ''center of the page''.
The result is already better but still feels unpredictable. Especially if you run the macro multiple times.
Also the behavior of the zoom is not always uniform.
So I still believe I miss an important piece of insight in how Inventor works with this.
This is the improved code:
Public Sub AutoScale() 'Scale all views on all pages to fit nicely on the sheets 'step 0. declare stuff Dim oDrawDoc As DrawingDocument Dim oSheet As Sheet Dim oDrawView As DrawingView Set oDrawDoc = ThisApplication.ActiveDocument ' step 2. Process all pages Dim i As Integer i = 3 For i = 3 To oDrawDoc.Sheets.Count Set oSheet = oDrawDoc.Sheets.Item(i) Set oDrawView = oSheet.DrawingViews.Item(1) Call ProcessPages(oSheet, oDrawView) Next End Sub Private Sub ProcessPages(ByVal oSheet As Sheet, ByVal oDrawView As DrawingView) ' step 1 get current drawingscale Dim oDrawViewScale As Double oDrawViewScale = oDrawView.Scale ' step 2 Determine the best scale by looking at the view widths. Dim dWidthScale As Double dWidthScale = (oSheet.Width - 5) / oDrawView.Width * oDrawViewScale '5cm = distance to stay away from sides ' step 3 Determine the best scale by looking at the view heights. Dim dHeightScale As Double dHeightScale = (oSheet.Height - 9) / oDrawView.Height * oDrawViewScale '9cm = distance to stay away from top and bottom (including the header) ' step 4 Choose the best scale Dim ComputeViewScale As Double If dWidthScale < dHeightScale Then ComputeViewScale = dWidthScale Else ComputeViewScale = dHeightScale End If ' step 5 set the correct scale oDrawView.ScaleString = ComputeViewScale 'step 6 set the location of the view Dim PlacementPoint As Point2d 'place above the center of the page (2cm) ' - - - - I changed things here - - - - ' ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - Set PlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2 - oDrawView.Center.x, oSheet.Height / 2 - oDrawView.Center.y) '-> I compensate by deducting the centerlocation of the view from the center of the page oDrawView.Postion = PlacementPoint '-> I now use the '.Postion ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - ' - - - - - - - - ' - - - - I changed things here - - - - ' End Sub
Hi @Anonymous,
Try the following change in code.
Set CenterPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2) oDrawView.Position = CenterPoint
Can you please provide drawing to test position?
Please feel free to contact if there is any doubt.
If solves problem, click on "Accept as solution" / give a "Kudo".
Thanks and regards,
Hello,
So after some more extended testing I believe I have it figured it out.
What I have learned:
Set PlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2 - oDrawView.Center.x, oSheet.Height / 2 - oDrawView.Center.y) '-> I compensate by deducting the centerlocation of the view from the center of the page oDrawView.Postion = PlacementPoint '-> I now use the '.Postion
Can't find what you're looking for? Ask the community or share your knowledge.