Center and scale the view

Center and scale the view

tomislav.peran
Advocate Advocate
547 Views
6 Replies
Message 1 of 7

Center and scale the view

tomislav.peran
Advocate
Advocate

Hello,

 

My question is about the code I found on the following link:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-drawing-view-scale/m-p/823488...

 

Code is used to scale the chosen view and I have added a line to center it.

I have placed a few questions next to the code lines, so if somebody finds the time to answer them it would be great.

 

 ThisApplication.ActiveDocument.Sheets("Sheet:2").Activate

    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    oSheet = oDwgDoc.Sheets.Item(2)
    Dim oView As DrawingView
    oView = oSheet.DrawingViews.Item(1) 
oView.ScaleString = "1:1" -> I believe this sets the temporary scale of the view? Dim ViewWide As Double ViewWide = 35 '-> what is here 35? I know Inventor works with centimeters so I assume those are cm? Dim DrawingScale As String DrawingScale = CStr(ViewWide / oView.Width) -> is oView.Width calculated when scale is 1:1 like defined here: oView.ScaleString = "1:1"
-> why is here CStr used? I have read CStr is used to variable conversion? oView.ScaleString = DrawingScale ActiveSheet.View("VIEW4").SetCenter(148.5,210) -> what should I put to center the view? I have used mm (I use A3 sheet format) but It does not place the view in the middle of the sheet.

Tom

0 Likes
Accepted solutions (2)
548 Views
6 Replies
Replies (6)
Message 2 of 7

Cadkunde.nl
Collaborator
Collaborator
Accepted solution

1) He sets oView.scalstring to 1:1 so what you measure oView.Width from that scale.

2) Cstr means Convert to string. If you put in a value that is a double or integer or etc, it makes sure that that input is converted to a string to prevent errors. You also have Cint or Cdbl as convert to integer or double

 

3) you have to reverse the X and Y position 

.SetCenter(210,148.5)

Oh and i forgot your viewwide question. Its only used in the math, so you can regard it as a factor.

Message 3 of 7

Daan_M
Collaborator
Collaborator
Accepted solution

 

 

ThisApplication.ActiveDocument.Sheets("Sheet:2").Activate

    Dim oDwgDoc As Document
    oDwgDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    oSheet = oDwgDoc.Sheets.Item(2)
    Dim oView As DrawingView
    oView = oSheet.DrawingViews.Item(1) 

oView.ScaleString = "1:1" 
'-> I believe this sets the temporary scale of the view?
'->> Yes

    
    Dim ViewWide As Double
    ViewWide = 35 
'-> what is here 35? I know Inventor works with centimeters so I assume those are cm?
'->> I think ViewWide is the width of your object in real life? not entirely sure but it is used later to create your drawing scale. So i makes sens that your real life width/drawing view width = your scale
    
    Dim DrawingScale As String
    DrawingScale = CStr(ViewWide / oView.Width) 

'-> is oView.Width calculated when scale is 1:1 like defined here: oView.ScaleString = "1:1" 
'->> oViewWidth is the width of your active Drawingview.

'-> why is here CStr used? I have read CStr is used to variable conversion? 
'->> Cstr converts a variable to string type
   
oView.ScaleString = DrawingScale
	
ActiveSheet.View("VIEW4").SetCenter(148.5,210) 

'-> what should I put to center the view? I have used mm (I use A3 sheet format) but It does not place the view in the middle of the sheet.
'->> to center your drawing i would use the following: ActiveSheet.View("VIEW4").SetCenter((oSheet.Width/2),(oSheet.Height/2))

 

 

Message 4 of 7

tomislav.peran
Advocate
Advocate

Hi Cadkunde,

 

Thanks for the explanation. 

 

Is 35 value in cm?

 ViewWide = 35

 Tom

0 Likes
Message 5 of 7

tomislav.peran
Advocate
Advocate

Hi Daan_M,

 

Great. Thanks a lot.

 

SetCenter((oSheet.Width/2),(oSheet.Height/2))

 

This is indeed much better to use than putting numbers.  I will use that.

 

Tom

Message 6 of 7

tomislav.peran
Advocate
Advocate

Hi Cadkunde,

 

"Oh and i forgot your viewwide question. Its only used in the math, so you can regard it as a factor."

 

Sorry, I have missed this sentence in your answer.

 

Awesome. Thanks!

 

Tom

0 Likes
Message 7 of 7

tomislav.peran
Advocate
Advocate

Hello,

 

Small update. The line ViewWide = 35 indeed sets the view width to 35 cm. 

 

If I set ViewWide = 42  my view will fit perfectly to an A3 sheet (420 x 297 mm).

 

See foto below:

 

tomislavperan_0-1670246125060.png

 

Tom

0 Likes