Scaling views to fit a sheet

Scaling views to fit a sheet

Anonymous
Not applicable
1,283 Views
13 Replies
Message 1 of 14

Scaling views to fit a sheet

Anonymous
Not applicable
Is there a way to automatically fit all views on a sheet? I've got a database with a bunch of simple parts that I need to create and I can't find a good way to scale the views (base, section, projected) on the sheet.

I've got around 160,000 more prints that could utilize this auto scaling concept so, I'm rather desperate to hear if there are any suggestions at all. If I can't scale automatically I would just like somebody at Autodesk to tell me out right.
0 Likes
1,284 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Inventor doesn's support any auto scaling functionality for a set of drawing
views. It's possible to write your own though. Below are two of the key
functions from a much larger program I wrote a while ago that does this.
The ComputeViewScale takes all of the arguments as input and returns the
scale to use. The ComputeViewPositions ByVal arguments are inputs and the
ByRef are outputs. It computes the actual position where to create each
view.

Private Function ComputeViewScale(ByVal PartLength As Double, ByVal
PartHeight As Double, ByVal PartDepth As Double, ByVal AreaWidth As Double,
ByVal AreaHeight As Double, ByVal ViewSpacing As Double, ByVal BorderSpacing
As Double) As Double
On Error GoTo ErrorFound

' Initialize an array with the valid scale values from 1/128 to 64
Dim adScales(13) As Double
adScales(0) = 1 / 128
Dim i As Integer
For i = 1 To 13
adScales(i) = adScales(i - 1) * 2
Next

' Determine the best scale by looking at the view widths.
Dim dWidthScale As Double
dWidthScale = -1
For i = 0 To 13
If ((PartLength + PartDepth) * adScales(i)) + (ViewSpacing +
BorderSpacing * 2) <= AreaWidth Then
dWidthScale = adScales(i)
Else
Exit For
End If
Next

' Determine the best scale by looking at the view heights.
Dim dHeightScale As Double
dHeightScale = -1
For i = 0 To 13
If ((PartHeight + PartDepth) * adScales(i)) + (ViewSpacing +
BorderSpacing * 2) <= AreaHeight Then
dHeightScale = adScales(i)
Else
Exit For
End If
Next

If dWidthScale < dHeightScale Then
ComputeViewScale = dWidthScale
Else
ComputeViewScale = dHeightScale
End If

Exit Function

ErrorFound:
ComputeViewScale = -1
End Function


Private Function ComputeViewPositions(ByVal ViewScale As Double, _
ByVal PartLength As Double, _
ByVal PartHeight As Double, _
ByVal PartDepth As Double, _
ByVal BorderWidth As Double, _
ByVal BorderHeight As Double, _
ByVal BorderXOffset As Double, _
ByVal BorderYOffset As Double, _
ByVal ViewSpacing As Double, _
ByVal BorderSpacing As Double, _
ByRef FrontViewCenter As Point2d, _
ByRef RightViewCenter As Point2d, _
ByRef TopViewCenter As Point2d, _
ByRef IsoViewCenter As Point2d) As
Boolean

On Error GoTo ErrorFound
Dim oTG As TransientGeometry
Set oTG = goApp.TransientGeometry

' Initialize the return points.
Set FrontViewCenter = oTG.CreatePoint2d
Set RightViewCenter = oTG.CreatePoint2d
Set TopViewCenter = oTG.CreatePoint2d
Set IsoViewCenter = oTG.CreatePoint2d

' Account for the scale.
PartLength = PartLength * ViewScale
PartHeight = PartHeight * ViewScale
PartDepth = PartDepth * ViewScale

' Determine the equal spacing between the border and views along the
width of the sheet.
Dim dWidthSpace As Double
dWidthSpace = (BorderWidth - (PartLength + PartDepth)) / 3

' Use half of this spacing to shift if over towards the left side of the
sheet.
dWidthSpace = dWidthSpace * 0.5

' Determine the x positions of the front, right, and top views.
FrontViewCenter.X = BorderXOffset + dWidthSpace + (PartLength / 2)
TopViewCenter.X = FrontViewCenter.X
RightViewCenter.X = FrontViewCenter.X + (PartLength / 2) + dWidthSpace +
(PartDepth / 2)

' Determine the equal spacing between the front and top views along the
height of the sheet.
Dim dHeightSpace As Double
dHeightSpace = (BorderHeight - (PartHeight + PartDepth)) / 3

' Determine the y positions of the front, right, and top views.
FrontViewCenter.Y = BorderYOffset + dHeightSpace + (PartHeight / 2)
RightViewCenter.Y = FrontViewCenter.Y
TopViewCenter.Y = FrontViewCenter.Y + (PartHeight / 2) + dHeightSpace +
(PartDepth / 2)

ComputeViewPositions = True
Exit Function

ErrorFound:
ComputeViewPositions = False
End Function

--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 3 of 14

Anonymous
Not applicable
As far as I know, there isn't a direct way to do this. It is technically
possible to write a macro that would do this scaling automatically, but it
may not be that straighforward. You would first set up the views such that
the scales of all view are inherited from the base view. You would then
experiment with a range of values for the base view scale such that all the
views fit within the range of the sheet. You may have to move the drawing
views around in the process since they may end up too far or overlap as a
result of scaling. The API has the necessary tools, but again, this may not
be trivial to implement.

Sanjay-
0 Likes
Message 4 of 14

Anonymous
Not applicable
Thanks for the very quick response you guys! Brian, thanks for the code I'm defiantly going to try it out. Since I have a starting point let me ask a couple of other questions along the same line.

1) Do I dimension the drawings before or after the scaling code? It would be great if I could create a template and then generate the scaling functions off of that template.

2) When I use Brian's code does the scale of the views take into account the dimensions that I need to have and the relative position of the dimensions?

3) I noticed that there is a red dotted line going around each view that I created. First, what is that box called? Can I place my dimensions within that box (by growing the box) and then run the scale code from Brian over the top of it? If I can do it that way then I'll know that none of my dimensions will be over lapping.

Thanks so much for taking the time to answer my questions.

Jeff N.
0 Likes
Message 5 of 14

Anonymous
Not applicable
1) Do I dimension the drawings before or after the scaling code? It would
be great if I could create a template and then generate the scaling
functions off of that template.

In my program that used the code I posted, the view scale is determined
before any views are placed. I opened the part invisibly and extracted its
size. This size information was used as input to the functions. The
resulting information is then used to create the views at the computed
scale.

However, since dimensions are associated to the geometry in the view and
also take into account the view scale, you can scale a view after creating
dimensions and everything will still be ok. It's likely that you'll need to
reposition the text though.

2) When I use Brian's code does the scale of the views take into account the
dimensions that I need to have and the relative position of the dimensions?

My code doesn't take into account any dimensions. However, you can define
the required room around the views when the scale is computed. The
AreaWidth and AreaHeight arguments specifies the width and height of the
area on sheet where views can be placed. The ViewSpacing argument defines
the distance required between views. The BorderSpacing argument defines the
distance required from the border.

3) I noticed that there is a red dotted line going around each view that I
created. First, what is that box called? Can I place my dimensions within
that box (by growing the box) and then run the scale code from Brian over
the top of it? If I can do it that way then I'll know that none of my
dimensions will be over lapping.

This box is only a visual feedback to indicate the view you are selecting.
It's created by scaling the actual size of the view. If it wasn't scaled
then for many parts it would like directly over the part geometry and not be
easily seen. The area between this box and the actual view doesn't
represent anything.

--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 6 of 14

Anonymous
Not applicable
Brian-
Thanks for the help I think that you've answered all of my questions and now all I have to do is just get dirty and write the code.

Thanks-
Jeff
0 Likes
Message 7 of 14

Anonymous
Not applicable
Brian-
After looking at your code I'm a little confused about the AreaWidth and the AreaHieght variables. You state that their the area on the sheet but what units are they in? If I specify a size I'm basically just guessing and with trial 'n error I'll figure out the pattern for one part type but I have have over 75 part types that I have to consider.

What I would like to do is create a template with the correct dimension call outs (per part type) and then measure from the dimensions (left to right and bottom to top) thus creating a square and that should be my AreaXXX. Does this sound like a good idea? If so then how can I measure the AreaXXX?

I also have another post discussing dimensions overlapping the views that I've created. Can you take a look and that and give me some input.

http://discussion.autodesk.com/thread.jspa?threadID=641572

Thanks Jeff
0 Likes
Message 8 of 14

Anonymous
Not applicable
In my application that used the code I posted I was using the API to get the
size of the sheet and the title block to determine the area I had to place
views within. The units are centimeters since that is the internal length
unit of Inventor. You could choose to determine this area any way you want.
If for some reason it ends up being different for the different types of
parts and you can't compute it based on information you can get from the API
you could define it yourself and save it in each template, (possibly as an
iProperty), and then get and use this information when needed.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 9 of 14

Anonymous
Not applicable
Brian-
Is there a way to give an ID/name to a give dimension in the drawing environment?
0 Likes
Message 10 of 14

Anonymous
Not applicable
Dimensions support attributes. You can use these to assign a unique name to
the dimensions you care about and can query for them later using the
attribute.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 11 of 14

Anonymous
Not applicable
Brian-
What my overall goal is to move the dimensions and tails of the arrowheads out from on top of the images of the part. My line of thinking goes something like this;

1) Can I measure the distance from edge to edge of the a view? I think I can but not sure. If I can then I can find the center point and the area that should be the part.

2) Can I move the dimensions dynamically if their x/y coordinates reside within the bounding box of the part? I noticed in another post the "ordinate" positioning my not be possible.

3) If I move the dimension then I have to move the same tail of the arrow to match the dimension. Can this even be done? I would have to give the arrow head a specific ID but hopefully then encompass attributes like dimensions.

Thanks-
Jeff
0 Likes
Message 12 of 14

Anonymous
Not applicable
Brian-
Can you take a look at the code that I've tweaked. I'm not getting the correct result. It appears that no matter what values that I insert I should always get a scale just below whatever the AreaWidth and AreaHeight.

Note: If I convert all values to cm then my scale is even further off.

'- Values for part are in inches and values for sheet are in cm -'
dblScale = ComputeViewScale(0.125, 0.187, 0.187, 1.33, 0.825, 0.1, 0.1)

Private Function ComputeViewScale(ByVal PartLength As Double, ByVal PartHeight As Double, ByVal PartDepth As Double, ByVal AreaWidth As Double, _
ByVal AreaHeight As Double, ByVal ViewSpacing As Double, ByVal BorderSpacing As Double) As Double

' Initialize an array with the valid scale values from 1/128 to 64
Dim adScales(13) As Double
adScales(0) = 1 / 128
Dim i As Integer
'Dim intScale As Integer
For i = 1 To 13
'If (adScales(i - 1) * 2) < 1 Then
adScales(i) = adScales(i - 1) * 2
'Else
'adScales(i) = intScale + 1
'intScale += 1
'End If
Next

' Determine the best scale by looking at the view widths.
Dim dWidthScale As Double
dWidthScale = -1
For i = 0 To 13
If ((PartLength + PartDepth) * adScales(i)) + (ViewSpacing + BorderSpacing * 2) <= AreaWidth Then
dWidthScale = adScales(i)
Else
Exit For
End If
Next

' Determine the best scale by looking at the view heights.
Dim dHeightScale As Double
dHeightScale = -1
For i = 0 To 13
If ((PartHeight + PartDepth) * adScales(i)) + (ViewSpacing + BorderSpacing * 2) <= AreaHeight Then
dHeightScale = adScales(i)
Else
Exit For
End If
Next

If dWidthScale > dHeightScale Then
ComputeViewScale = dWidthScale
Else
ComputeViewScale = dHeightScale
End If
End Function
0 Likes
Message 13 of 14

Anonymous
Not applicable
Hi Jeff,

Can you email me directly? You can use brian . ekins @ autodesk . com
(without the spaces of course).
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 14 of 14

Anonymous
Not applicable
Sure thing.
0 Likes