Scale view - line clarification

Scale view - line clarification

tomislav.peran
Advocate Advocate
227 Views
2 Replies
Message 1 of 3

Scale view - line clarification

tomislav.peran
Advocate
Advocate

Hello,

 

I have a question about a piece of code that bothers me because I do not understand how it works. 

I have used a red pen to write my comments beneath.

 

Dim DrawingScale As Double 
DrawingScale = (ViewWide / oView.Width)
If DrawingScale < 1 Then -> let's say this is 0.35
	
DrawingScale = DrawingScale ^ -1 -> then this is 2.86

inc = .25 -> why is this here?

DrawingScale = Round(Round(DrawingScale, 2) / inc) * inc ---> why is this: (.../ inc) * inc

I would expect something like this:

DrawingScale = Round(Round(DrawingScale, 2) , inc) -> I would expect something like this but that makes no sense
oView.ScaleString = "1/" & DrawingScale

 Can somebody please clarify that line of code?

 

Tom

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

WCrihfield
Mentor
Mentor
Accepted solution

Hi @tomislav.peran.  I will try to explain each step of what is going on in that longest line of code.

  • The innermost code is rounding the Double to 4 decimal places, which is 1 decimal place more than the end value needs to be.
  • Then the next step outward is dividing that value by the 'increment' value.
  • Then the remainder of that value (after the decimal place) is being dropped by rounding the value to the nearest whole number by the left most Round function.
  • Then that whole number is being multiplied by the 'increment' again, to get back to the closes multiple of the 'increment' value, without any remainder.

Does that explain it OK for you?  Rounding the value off to an Imperial fraction of an inch.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

tomislav.peran
Advocate
Advocate

Hi WCrihfield,

 

Thanks for the explanation. I broke down the code in the following way and it does what you said:

 

DrawingScale = (ViewWide / oView.Width) -> 0.008
DrawingScale = DrawingScale ^ -1 -> 120.550078288
DrawingScale = Round(DrawingScale, 2) -> 120.55 
DrawingScale = Round(DrawingScale / inc) -> 482
DrawingScale = DrawingScale * inc -> 120.5 

The idea of using 0.25 is to set the scale to 100, 100.25, 100.5, 100.75...I prefer a rounded scale but oke. 

 

It is clear now, thanks for helping out!

0 Likes