Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

View Height and Width Drive View Scale?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
gfunnybus
1453 Views, 3 Replies

View Height and Width Drive View Scale?

I have seen a lot of posts of people using IF statements to determine the view scale in order to fit thier drawing sheet. I am wondering if there is a way to scale the view in a way that can maintain a specific veiw height and width. An attempt at the solution being possibly fetching the extents of the assembly document and applying a scale factor? All help appreciated! Attached is a reference for what I would like to accomplish. 

3 REPLIES 3
Message 2 of 4
gadurai
in reply to: gfunnybus

Hi,

 

you have to store the drawing view's height and Width in the sheets attribute through API  once you have made a perfect view.

 

While updating part/assembly file, the view width& height will be changing.You can read the current View's width & height and reduce/increase the View scale(through loop) until you reach the existing value you have stored in the attribute for perfect view width and height.

 

The scale factor you can keep very small to achive better result.

 

The following is my code..**************

 

You have to het SpaceHgt and SpaceWidth from the attribute attached with view or sheet.

 

public void ScaleView(DrawingView Oview,double SpaceWidth,double SpaceHgt,double ScaleFactor)
{

if ((Math.Round(Oview.Width, 5) > SpaceWidth) || (Math.Round(Oview.Height, 5) > SpaceHgt)) //If the Width or Height is greater than specified, Decreasing Scale
{
   do
    {
     Oview.Scale = Oview.Scale - ScaleFactor;
     } while ((Math.Round(Oview.Width, 5) > SpaceWidth) || (Math.Round(Oview.Height, 5) > SpaceHgt));
return;
}

if ((Math.Round(Oview.Width, 5) < SpaceWidth) && (Math.Round(Oview.Height, 5) < SpaceHgt)) //If the Width or Height is less than specified, Increasing Scale
{
   do
   {
    Oview.Scale = Oview.Scale + ScaleFactor;
    } while ((Math.Round(Oview.Width, 5) < SpaceWidth) && (Math.Round(Oview.Height, 5) < SpaceHgt));
return;
}


}

 

 

Regards,

Appadurai.G

 

Message 3 of 4
gfunnybus
in reply to: gadurai

Looks to me like this will work, I'm going to try and write it up in an iLogic rule and see if I can get the same results. Thanks!

Message 4 of 4
gfunnybus
in reply to: gadurai

I came up with this in iLogic. It scales the base view based on the addition of the dimensions of the projected top and right views. The only problem (I see right now) is that my step size I use to scale cannot be less than 0.01. For some reason, anything less than 0.01 will not scale the view at all, and will loop infinitely until I tell it to stop. That scale factor varies about 0.75" from the lower to the upper bounds which would be unacceptable for my sheet at this point. Anyways, here's my code:

 

ThisApplication.StatusBarText = "Scaling Views to Fit Drawing Sheet"

Dim oStepSize As Double = 00.0100
Dim oGap As Double = 00.7500
Dim oMaxH As Double = 06.0000
Dim oMaxW As Double = 12.0000

' VIEW1 = Base View' VIEW2 = Top View' VIEW3 = Right View' VIEW4 = ISO Top Right View
If ((Round(ActiveSheet.View("VIEW1").Height,4) + Round(ActiveSheet.View("VIEW2").Height,4)) > oMaxH _ Or (Round(ActiveSheet.View("VIEW1").Width,4) + Round(ActiveSheet.View("VIEW3").Width,4)) > oMaxW) Then i = 1 While ((Round(ActiveSheet.View("VIEW1").Height,4) + Round(ActiveSheet.View("VIEW2").Height,4)) > oMaxH _ Or (Round(ActiveSheet.View("VIEW1").Width,4) + Round(ActiveSheet.View("VIEW3").Width,4)) > oMaxW) ActiveSheet.View("VIEW1").Scale = ActiveSheet.View("VIEW1").Scale - oStepSize i = i + 1 ThisApplication.StatusBarText = ("Scaling Down: Attempt #" & i & " Scale: " & ActiveSheet.View("VIEW1").Scale) If i > 500 Then ThisApplication.StatusBarText = "Scaling Down: Exceeded Expected Iterations" MessageBox.Show("Exceeded expected iterations", "Scaling Down Failed") Exit While End If End While i = Nothing Else If ((Round(ActiveSheet.View("VIEW1").Height,4) + Round(ActiveSheet.View("VIEW2").Height,4)) < oMaxH _ Or (Round(ActiveSheet.View("VIEW1").Width,4) + Round(ActiveSheet.View("VIEW3").Width,4)) < oMaxW) Then i = 1 While ((Round(ActiveSheet.View("VIEW1").Height,4) + Round(ActiveSheet.View("VIEW2").Height,4)) < oMaxH _ Or (Round(ActiveSheet.View("VIEW1").Width,4) + Round(ActiveSheet.View("VIEW3").Width,4)) < oMaxW) ActiveSheet.View("VIEW1").Scale = Round(ActiveSheet.View("VIEW1").Scale + oStepSize,5) i = i + 1 ThisApplication.StatusBarText = ("Scaling Down: Attempt #" & i & " Scale: " & ActiveSheet.View("VIEW1").Scale) If i > 500 Then ThisApplication.StatusBarText = "Scaling Down: Exceeded Expected Iterations" MessageBox.Show("Exceeded expected iterations", "Scaling Down Failed") Exit While End If End While i = Nothing Else End If 'spacing from bottom left corner to edges of base view
ActiveSheet.View("VIEW1").SetSpacingToCorner(1.25, 2.375, SheetCorner.BottomLeft) 'spacing between edges of base view and top view
ActiveSheet.View("VIEW2").SpacingBetween("VIEW1") = oGap 'spacing between edges of base view and right view
ActiveSheet.View("VIEW3").SpacingBetween("VIEW1") = oGap 'spacing from bottom left corner to center of iso view
ActiveSheet.View("VIEW4").SetCenter(14.75, 6.25) MessageBox.Show( _ "Combined View Height: " & Round((ActiveSheet.View("VIEW1").Height + ActiveSheet.View("VIEW2").Height),4) & vbLf & "Target Height: " & oMaxH & vbLf & _ "Combined View Width: " & Round((ActiveSheet.View("VIEW1").Width + ActiveSheet.View("VIEW3").Width),4) & vbLf & "Target Width: " & oMaxW)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report