iLogic help - convert Inch to Architectural style?

iLogic help - convert Inch to Architectural style?

pederskin
Explorer Explorer
2,126 Views
13 Replies
Message 1 of 14

iLogic help - convert Inch to Architectural style?

pederskin
Explorer
Explorer

I have a parameter length that is currently in inches and I would like to use it to populate the description but I would like it to be displayed in Architectural style (i.e. 12’-3”).  I would also like to have it round up to the nearest 3”.  Any help would be greatly appreciated.

 

Thanks,

Neil

0 Likes
Accepted solutions (1)
2,127 Views
13 Replies
Replies (13)
Message 2 of 14

MjDeck
Autodesk
Autodesk

Here's a rule that will do it:

roundedUp = Ceil(length/3) * 3
Dim feet As Integer = roundedUp \ 12
Dim inches As Integer = roundedUp - feet * 12
If (feet > 0) Then
  description = String.Format("{0}'-{1}""", feet, inches)
Else
  description = String.Format("{0}""", inches)
End If
iProperties.Value("Project", "Description") = description


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 14

pederskin
Explorer
Explorer

Hello Mike,

 

I may be missing something but it keeps showing a decimal in
the description property.   I’ve added my
custom parameter…which is currently formatted in Inches.  Any ideas?

 

roundedUp = Ceil(length/3) * 3

Dim feet As Integer = roundedUp \ 12

Dim inches As Integer = roundedUp - feet * 12

If (feet > 0)
Then

  description = String.Format("{0}'-{1}",Belt_Length, feet, inches)

Else

  description = String.Format("{0}", Belt_Length, inches)

End If

iProperties.Value("Project", "Description") = description

0 Likes
Message 4 of 14

MjDeck
Autodesk
Autodesk
Accepted solution

Looks like you made too many changes to the rule.  You should only have to change the first line:

roundedUp = Ceil(Belt_Length/3) * 3
Dim feet As Integer = roundedUp \ 12
Dim inches As Integer = roundedUp - feet * 12
If (feet > 0) Then
  description = String.Format("{0}'-{1}""", feet, inches)
Else
  description = String.Format("{0}""", inches)
End If
iProperties.Value("Project", "Description") = description

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 14

pederskin
Explorer
Explorer

Hello Mike,

 

My bad...it works perfectly!!!

 

Thank you!

0 Likes
Message 6 of 14

timothy_berg
Advocate
Advocate

Hello Mike,

 

How do i get the conversion to give me a feet and inches with the rounding converting to the nearest 1/16"?

0 Likes
Message 7 of 14

Anonymous
Not applicable
dim DecimalDimension as decimal = 159.8125
Dim feet As Integer = Floor(Round((DecimalDimension\ 12),0))
Dim inches As String = RoundToFraction((DecimalDimension - (feet * 12)), 1/16, RoundingMethod.Round)
If (feet > 0) Then
  ArchitecturalDimension = String.Format("{0}'-{1}""", feet, inches)
Else
  ArchitecturalDimension = String.Format("{0}""", inches)
End If

iProperties.Value("Custom", "ArchitecturalValue") = ArchitecturalDimension

 have a nice day

0 Likes
Message 8 of 14

timothy_berg
Advocate
Advocate

thanks for replying although i think the rule is still missing a couple of lines try running your rule with a value of 11.6

 

screenshot242016.PNG

0 Likes
Message 9 of 14

Anonymous
Not applicable

SyntaxEditor Code Snippet

Dim DecimalDimension As Decimal = 11.6
Dim feet As Integer = Floor(DecimalDimension)\ 12
Dim inches As String = RoundToFraction((DecimalDimension - (feet * 12)), 1/16, RoundingMethod.Round)
If (feet >= 1) Then
  ArchitecturalDimension = String.Format("{0}'-{1}""", feet, inches)
Else
  InchesNoFeet = RoundToFraction((DecimalDimension), 1/16, RoundingMethod.Round)
  ArchitecturalDimension = String.Format("{0}""", InchesNoFeet)
End If
iProperties.Value("Custom", "ArchitecturalValue") = ArchitecturalDimension

Try this 🙂 

0 Likes
Message 10 of 14

timothy_berg
Advocate
Advocate

WORKS LIKE A CHARM THANKS A MILLION!!

screenshot242016-1.PNGscreenshot242016-2.PNG

0 Likes
Message 11 of 14

MechMachineMan
Advisor
Advisor

It might be more beneficial to have seperate styles. I'm undecided. But in case anyone wants to go that route, here is a rule:

 

Sub Main()

	Dim oThreshold As Double = 48 ' inch
	Dim oFractional As String = "Fractional"
Dim oArchitectural As String = "Architectural" Dim oDrawDoc As DrawingDocument Try oDrawDoc = ThisApplication.ActiveDocument Catch MsgBox("This rule is intended for drawing documents only.", MsgBoxStyle.OKOnly, "Change Style") Exit Sub End Try Dim oUOM As UnitsOfMeasure oUOM = oDrawDoc.UnitsOfMeasure oThreshold = oUOM.ConvertUnits(oThreshold, "in", "cm") Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager Dim oArchitecturalStyle As DimensionStyle = oStylesMgr.DimensionStyles.Item(oArchitectural) Dim oFractionalStyle As DimensionStyle = oStylesMgr.DimensionStyles.Item(oFractional) Dim oDims As DrawingDimensions Dim n As Integer = 0 For Each oSheet In oDrawDoc.Sheets oDims = oSheet.DrawingDimensions For Each oDim As GeneralDimension In oDims Select Case True Case oDim.ModelValue > oThreshold AndAlso oDim.Style.Name Like oFractional oDim.Style = oArchitecturalStyle n += 1 Case oDim.ModelValue <= oThreshold AndAlso oDim.Style.Name Like oArchitectural oDim.Style = oFractionalStyle n += 1 Case Else 'Do Nothing End Select Next Next MsgBox("Done" & vbNewLine & "Dimensions changed: " & n, MsgBoxStyle.OKOnly, "Change Style") End Sub

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 12 of 14

timothy_berg
Advocate
Advocate

OK looks like i didn't test this enough if the value is 23.99, doesn't matter what the foot value is, the key is almost rounding to a whole foot number for example this should read 2'-0" but the result is 1'-12" so any value between 23.9375 and 23.9999 will provide the wrong value, please help.

0 Likes
Message 13 of 14

MjDeck
Autodesk
Autodesk

Hi Timothy,

Please try this version of ofoven's rule:

Dim DecimalDimension As Decimal = 23.99
Dim roundingInterval as Double = 1/16

Dim rounded As Double = Round(DecimalDimension/roundingInterval) * roundingInterval

Dim feet As Integer = Floor(rounded)\ 12
Dim inches As String = RoundToFraction((rounded - (feet * 12)), roundingInterval, RoundingMethod.Round)
If (feet >= 1) Then
  ArchitecturalDimension = String.Format("{0}'-{1}""", feet, inches)
Else
  ArchitecturalDimension = String.Format("{0}""", inches)
End If
iProperties.Value("Custom", "ArchitecturalValue") = ArchitecturalDimension

Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 14

timothy_berg
Advocate
Advocate

THAT FIXED IT!!

 

great work thanks

 

 

0 Likes