<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Automatic Scale and View Position in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8914909#M115937</link>
    <description>&lt;P&gt;If you're using anything before Inventor 2019 you can't run a rule that uses "ActiveSheet" from anything other than a drawing which is what causes your error.&amp;nbsp; This rule also doesn't create any drawings just resizes them.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2019 15:47:09 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-07-17T15:47:09Z</dc:date>
    <item>
      <title>Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5784680#M115928</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As specified in the code the views must follow a specific order and name in the sheet:&lt;BR /&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/185084i2E45C0C807581D22/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="view.png" title="view.png" /&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's working just fine for me. But any improvements that i can had? any ideas to make it better?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;' 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 &amp;amp; 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&amp;amp;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 &amp;lt;1 Then
FinalScale = FinalScale^-1
inc = .25
FinalScale = Round(Round(FinalScale,2) / inc) * inc
ActiveSheet.View(View(1)).ScaleString="1/"&amp;amp;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)&amp;lt;&amp;gt;0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(1)&amp;lt;&amp;gt;0 Then
NumberViewsX = NumberViewsX+1
End If
If ViewWidth(3)&amp;lt;&amp;gt;0 Then
NumberViewsX = NumberViewsX+1
End If

If ViewHeight(4)&amp;lt;&amp;gt;0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(1)&amp;lt;&amp;gt;0 Then
NumberViewsY = NumberViewsY+1
End If
If ViewHeight(2)&amp;lt;&amp;gt;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)&amp;lt;&amp;gt;0 Then
PlayX(1) = PlayX(0) + play_between_views
End If
If ViewWidth(1)&amp;lt;&amp;gt;0 Then
PlayX(2) = PlayX(0) + play_between_views
End If

If ViewHeight(2)&amp;lt;&amp;gt;0 Then
PlayY(1)=PlayY(0) + play_between_views
End If
If ViewHeight(1)&amp;lt;&amp;gt;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&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2015 14:08:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5784680#M115928</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-24T14:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5785336#M115929</link>
      <description>Great stuff! &lt;BR /&gt;&lt;BR /&gt;This guy could use your help. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.autodesk.com/t5/inventor-ideastation/automated-view-scale-and-position/idc-p/5785327#M9464" target="_blank"&gt;http://forums.autodesk.com/t5/inventor-ideastation/automated-view-scale-and-position/idc-p/5785327#M9464&lt;/A&gt;</description>
      <pubDate>Mon, 24 Aug 2015 18:07:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5785336#M115929</guid>
      <dc:creator>PaulMunford</dc:creator>
      <dc:date>2015-08-24T18:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5785763#M115930</link>
      <description>That guy is me &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; I posted as an Idea because if it's integrated in inventor could work much much better..</description>
      <pubDate>Mon, 24 Aug 2015 21:49:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/5785763#M115930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-08-24T21:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7949478#M115931</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SyntaxEditor Code Snippet&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;Apply the final scale to the Main view&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I think there is something wrong with this line:&lt;/P&gt;&lt;PRE&gt;ActiveSheet.View(View(1)).ScaleString="1/"&amp;amp;FinalScale&lt;/PRE&gt;&lt;P&gt;I'm getting this error:&lt;/P&gt;&lt;P&gt;Error in rule: Rule0, in document: test.idw&lt;/P&gt;&lt;P&gt;The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 05:22:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7949478#M115931</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-21T05:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7950063#M115932</link>
      <description>&lt;P&gt;Hi! Please attach the drawing file you are working on here. It would be a lot easier to tell where the problem is.&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:40:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7950063#M115932</guid>
      <dc:creator>johnsonshiue</dc:creator>
      <dc:date>2018-04-21T18:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7950075#M115933</link>
      <description>&lt;P&gt;I have attached the idw and ipt files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 18:57:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/7950075#M115933</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-04-21T18:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8353601#M115934</link>
      <description>&lt;P&gt;I have the same error - any suggestions ??&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 15:48:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8353601#M115934</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-23T15:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8354141#M115935</link>
      <description>&lt;P&gt;I do it differently:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 . on save drawing i for each view add iproperties to drawing named view_name in wich i store position of view and size of it.&lt;/P&gt;&lt;P&gt;2. when i change dimmensions of part i run rule on that event that will rescale draiwing views according to correspond iproperties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i think you should consider to do it this way because it will wor for all kinds of drawings like 1 or multiple sheets, and 1 or multiple views on each sheet.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 19:16:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8354141#M115935</guid>
      <dc:creator>marcin_otręba</dc:creator>
      <dc:date>2018-10-23T19:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8884707#M115936</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've just tried running this code and I get one error message.&lt;/P&gt;&lt;P&gt;I've added the code to my part which has a rule automatically generating a drawing template.&lt;/P&gt;&lt;P&gt;I have now added this code as another rule to my part SQ-Rect Silencer.ipt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message I am getting is:-&lt;/P&gt;&lt;P&gt;Error in rule: Rule 23, in document: SQ-Rect Silencers.ipt&lt;/P&gt;&lt;P&gt;ThisDrawing: This document "SQ-Rect Silencers" is not a drawing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This doesn't appear in the code?&lt;/P&gt;&lt;P&gt;May be a daft question but should this code run within the ipt part or the automatically generated idw drawing?&lt;/P&gt;&lt;P&gt;Either way it doesn't appear to generate any views on the idw drawing. I only need a base and projected view with for dimensions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 08:44:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8884707#M115936</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-02T08:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8914909#M115937</link>
      <description>&lt;P&gt;If you're using anything before Inventor 2019 you can't run a rule that uses "ActiveSheet" from anything other than a drawing which is what causes your error.&amp;nbsp; This rule also doesn't create any drawings just resizes them.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 15:47:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/8914909#M115937</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-17T15:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/9997257#M115938</link>
      <description>&lt;P&gt;I'm learning iLogic and want to achieve something similar. It is possible for you to share the code? Would be a huge help for me and sure also for others.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2021 23:40:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/9997257#M115938</guid>
      <dc:creator>geludegijon</dc:creator>
      <dc:date>2021-01-12T23:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Automatic Scale and View Position</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/11391556#M115939</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1734991"&gt;@marcin_otręba&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This sounds interesting, would you be able to share a bit more detail on how you do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 21:29:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/automatic-scale-and-view-position/m-p/11391556#M115939</guid>
      <dc:creator>thomas_m</dc:creator>
      <dc:date>2022-08-30T21:29:09Z</dc:date>
    </item>
  </channel>
</rss>

