- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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