Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic code Nested If

Anonymous

iLogic code Nested If

Anonymous
Not applicable

Hi.

 

I have a bit of code that checks dimensions in an idw to find out if they should display to 1 decimal place or rounded depending on their value, e.g. 20.2 displays as 20.2 but 20.0 displays as 20.

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet

For Each oDim As DrawingDimension In oSheet.DrawingDimensions
	If Round(oDim.ModelValue * 10, 1) -Round(oDim.ModelValue * 10, 0) = 0 Then 
		oDim.Precision = 0
	Else
		oDim.Precision = 1
	End If
Next

I want to add in another check to see if the dimension is <= 499.4 and then, based on the result:

 

1.  If it is above 499.4 it displays rounded (e.g. 499.5 displays as 500).

2.  If it is <=499.4 then it follows the previous rule and displays to a precision of either 0 or 1.

 

This was one of my attempts:

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet

For Each oDim As DrawingDimension In oSheet.DrawingDimensions
	If oDim.ModelValue > 499.4 Then
		oDim.Precision = 0
		Else
	If Round(oDim.ModelValue * 10, 1) -Round(oDim.ModelValue * 10, 0) = 0 Then 
		oDim.Precision = 0
		Else
		oDim.Precision = 1
	End If
	End If
Next

 

 

......... but no joy.

 

Could anybody please advise the best way to do this?

 

 

Thanks,

 

T

 

0 Likes
Reply
Accepted solutions (1)
590 Views
2 Replies
Replies (2)

WCrihfield
Mentor
Mentor
Accepted solution

Have you considered that the 499.4 raw number you are supplying may be getting understood as 'database units', instead of your intended 'document' units?  This is a fairly well known issue that a ton of us wish we could eliminate, once and for all, but it persists, due to global use.  Any raw numbers specified within the code, that are in a 'length' scenario, are usually understood by the 'system' as 'database units' (centimeters), instead of whatever length units you may be using within your document.

Try this (set-up to ensure the 499.4 is understood as Inches):  (you could also just use some simple math)

Sub Main
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	For Each oDim As DrawingDimension In oSheet.DrawingDimensions
		If oDim.ModelValue <= UnitConv(499.4, UnitsTypeEnum.kInchLengthUnits) Then
			If Round(oDim.ModelValue * 10, 1) -Round(oDim.ModelValue * 10, 0) = 0 Then
				oDim.Precision = 0
			Else
				oDim.Precision = 1
			End If
		Else
			oDim.Precision = 0
		End If
	Next
End Sub
Function UnitConv(oVal As Double, oIntendedUnits As UnitsTypeEnum) As Double
	'just set up to deal with 'Length' type units right now
	'this converts your Inches input to 'database units' so the rule will understand it as intended
	Return ThisApplication.UnitsOfMeasure.ConvertUnits(oVal, oIntendedUnits, UnitsTypeEnum.kDatabaseLengthUnits)
End Function

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Anonymous
Not applicable

Hi.

 

Thanks very much for your response.  This did the trick!

 

My units are mm so I just changed the 499.4 to 49.94 and bingo!  I wasn't aware of the units issue so thanks for that.

 

This is how the code finished up:

 

Sub Main
	Dim oDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Sheet = oDoc.ActiveSheet
	For Each oDim As DrawingDimension In oSheet.DrawingDimensions
		If oDim.ModelValue <= 49.94 Then
			If Round(oDim.ModelValue * 10, 1) -Round(oDim.ModelValue * 10, 0) = 0 Then  
				oDim.Precision = 0
			Else
				oDim.Precision = 1
			End If
		Else
			oDim.Precision = 0
		End If	
	Next
End Sub

 

Thanks very much for your help!

 

Cheers,

 

T

 

0 Likes