Rescale View with iLogic

Rescale View with iLogic

alysonrssl
Contributor Contributor
306 Views
2 Replies
Message 1 of 3

Rescale View with iLogic

alysonrssl
Contributor
Contributor

Hi everyone, 

 

Thanks to @JelteDeJong I know how to managed the rescale views in my drawings,

But I would like to only have ISO scale like :

1/200

1/100

1/50

...

Until 200/1

 

Do you know a way to "round" the value from this code or maybe set another parameter instead of giving dimension in (view, 10, 10) to have ISO scale ?

 

Thanks in advance, 

 

Public Sub Main()

Dim frontView As DrawingView = sheet.DrawingViews.Cast(Of DrawingView).Where(Function(v) v.Name = "FRONT VIEW").FirstOrDefault()
	
	
	
	If (frontView Is Nothing) Then
		MsgBox("Front view not found")
	End If
	
	ReScaleView(frontView, 10, 10)

End sub

Public Sub ReScaleView(view As DrawingView, X As Double, Y As Double)

	If (view.ScaleFromBase) Then Return

	Dim XOrg As Double = view.Width / view.Scale
	Dim YOrg As Double = view.Height / view.Scale

	Dim XScale As Double = X / XOrg
	Dim YScale As Double = Y / YOrg

	view.Scale = Math.Min(XScale, YScale)

 

 

0 Likes
Accepted solutions (1)
307 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

You might want to have a look at this function. You also might want to add all scales that you like to have. But don't change the order of the list.

Public Sub ReScaleView(view As DrawingView, X As Double, Y As Double)

	If (view.ScaleFromBase) Then Return

	Dim XOrg As Double = view.Width / view.Scale
	Dim YOrg As Double = view.Height / view.Scale

	Dim XScale As Double = X / XOrg
	Dim YScale As Double = Y / YOrg
	Dim minScale = Math.Min(XScale, YScale)

	Dim isoScales As New List(Of Double)
	isoScales.Add(1 / 50)
	isoScales.Add(1 / 20)
	isoScales.Add(1 / 10)
	isoScales.Add(1 / 5)
	isoScales.Add(1 / 2)
	isoScales.Add(1 / 1)
	isoScales.Add(2 / 1)
	isoScales.Add(5 / 1)
	isoScales.Add(10 / 1)
	isoScales.Add(20 / 1)
	isoScales.Add(50 / 1)

	Dim scaleCloseEnough = isoScales.First()
	For Each isoScale As Double In isoScales
		If (minScale > isoScale) Then
			scaleCloseEnough = isoScale
		End If
	Next

	view.Scale = scaleCloseEnough
End Sub

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

alysonrssl
Contributor
Contributor

Thank you Jelte, that works perfectly! 

0 Likes