How to display scale of a view set by an iLogic rule in ratio/fraction form?

How to display scale of a view set by an iLogic rule in ratio/fraction form?

sohaib.as01
Advocate Advocate
1,076 Views
5 Replies
Message 1 of 6

How to display scale of a view set by an iLogic rule in ratio/fraction form?

sohaib.as01
Advocate
Advocate

Hello everyone
So I have written a code to set scale of a particular drawing view. Now everything is working as it should except that I cant figure out a way to display the scale of that section view in a standard fraction/ratio form.

For example, when my iLogic code sets the scale, the scale should be displayed on drawing as 1:5, instead its being displayed as 0.2:1 . Any solution for that please? 

Here is my iLogic code for the scale

SEC_A.Scale = 1 'initiating view scale with 1
	ReqdH1 = ActiveSheet.Height / 1.8 'Height I need my view size to reduce to
	ActH1 = SEC_A.Height*10 'getting view width whcih is my Actual width (width by this method comes out in cm, converting to mm by Xing with 10)
	x = ReqdH1 / ActH1    'factor by which the view scale is going to be reduced/increased
	SEC_A.Scale = SEC_A.Scale * x
0 Likes
1,077 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Here is some post to help.

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-convert-decimal-to-fraction/td-p...

 

https://knowledge.autodesk.com/support/inventor/learn-explore/caas/CloudHelp/cloudhelp/2020/ENU/Inve...

 

You may need to round up/down the view scale to be an industry recognized scale.

 

Some examples 

 

'convert values to fraction
oT = FormatAsFraction(Thickness)

 

'convert values to fraction
oT = RoundToFraction(Thickness, 1/8, RoundingMethod.RoundUp)
oW = RoundToFraction(Width, 1/16, RoundingMethod.RoundUp)
oL = RoundToFraction(Length, 1/32, RoundingMethod.RoundUp)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

sohaib.as01
Advocate
Advocate

hey thanks @A.Acheson , I was able to figure out how to round the scale to nearest fraction using help from your last reply. But now another main issue is, how can I display the scale that is coming out to be as "1:4" instead of "1/4" on the drawing? As the scale is being displayed as a fraction instead of a ratio. 

Thanks alot

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

If you use the  replace string function to replace “/“ with “:” this will likely get you the ratio.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 6

sohaib.as01
Advocate
Advocate

Hi

I tried doing that as well, replacing "/" with ":". but its till not working. here is my code:

	'Adjusting Section A scale w.r.t sheet size and view size
	SEC_A.ScaleString = "1:1" 'initiating view scale with 1
	ReqdH_A = ActiveSheet.Height / 1.8 'Height I need my view size to reduce to
	ActH_A = SEC_A.Height*10 'getting view width whcih is my Actual width (width by this method comes out in cm, converting to mm by Xing with 10)
	x_A = ReqdH_A / ActH_A    'factor by which the view scale is going to be reduced/increased
	SEC_A.Scale = (SEC_A.Scale * x_A)	

	SCALE = RoundToFraction(SEC_A.Scale, 1 / 8, RoundingMethod.RoundUp)
	SCALE.Replace("/" , ":")
	SEC_A.ScaleString = SCALE
	SEC_A.ScaleString.Replace("/" , ":")
0 Likes
Message 6 of 6

A.Acheson
Mentor
Mentor

I am not sure why the fraction function isn't working. Looking at other post decimal to fraction conversion is a tricky subject.  Another method would be to restrict what decimal is selected and then between the range manually  set the fraction value to string value.

 

Here is a decimal to fraction function I found here  that might get you closer to your end goal.

 

Sub Main

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView


'Iterate through sheets
For Each oSheet In oDoc.Sheets
	
	Try
    'Grab the first drawing view on the sheet
    oDrawingView = oSheet.DrawingViews(1)
	SCALE = oDrawingView.Scale
 	MessageBox.Show(SCALE, "Title")

 	Catch
	MessageBox.Show("No View", "Title")
	End Try
	
	SCALEFRAC = GetFraction(SCALE) 
	SCALERATIO = SCALEFRAC.Replace("/" , ":")
	MessageBox.Show(SCALERATIO, "Title")
Next
End Sub


 Function GetFraction(ByVal d As Double) As String
        ' Get the initial denominator: 1 * (10 ^ decimal portion length)
        Dim Denom As Int32 = CInt(1 * (10 ^ d.ToString.Split("."c)(1).Length))

        ' Get the initial numerator: integer portion of the number
        Dim Numer As Int32 = CInt(d.ToString.Split("."c)(1))

        ' Use the Euclidean algorithm to find the gcd
        Dim a As Int32 = Numer
        Dim b As Int32 = Denom
        Dim t As Int32 = 0 ' t is a value holder

        ' Euclidean algorithm
        While b <> 0
            t = b
            b = a Mod b
            a = t
        End While

        'Get whole part of the number
        Dim Whole As String = d.ToString.Split("."c)(0)
		If Whole = "0" Then
	        ' Return our answer
	        Return (Numer / a) & "/" & (Denom / a)
		Else
			 ' Return our answer
	        Return Whole & " " & (Numer / a) & "/" & (Denom / a)
		End If
    End Function

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes