When I want to automate my drawings (and create dimensions using iLogic) I run into 3 issues:
I don't want my dimensions to look like this.
I need quite some extra code generate dimensions to look like this.
I would like to propose a new class that solve all of these issues and save me some extra code. This class should have a property/method that will the appropriate inventor settings so I can choose if I want my dimension texts to be centered. It should set the styles settings in such a way that dimension text are vertically aligned. And last but not least it MUST return all settings back to default even if the rule crashes. Therefore the class should implement the IDisposable interface. That way we can use the "Using" functionality of .Net and a try/catch/finally Block will be implemented automatically. Then this class could also replace the Drawing.BeginManage() and Drawing.EndManage() because we can be sure that the Drawing.EndManage() is called if it's the implemented in the dispose() method.
This is how I implemented this class. (Maybe another name for the class might be better but you will get the idea.)
Public Class DrawingComponentManager
Implements IDisposable
Private _drawing As IManagedDrawing
Private _inventor As Inventor.InventorServer
Private _style As DimensionStyle
Private _center As Boolean
Private _horizontalOrientation As DimensionTextOrientationEnum
Private _alignedOrientation As DimensionTextOrientationEnum
Private _verticalOrientation As DimensionTextOrientationEnum
Public Sub New(drawing As IManagedDrawing)
_drawing = drawing
_inventor = drawing.NativeEntity.Parent
_style = drawing.Document.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle
_center = _inventor.DrawingOptions.CenterDimensionText
_horizontalOrientation = _style.HorizontalDimensionTextOrientation
_alignedOrientation = _style.AlignedDimensionTextOrientation
_verticalOrientation = _style.VerticalDimensionTextOrientation
_drawing.BeginManage()
_style.HorizontalDimensionTextOrientation = DimensionTextOrientationEnum.kInlineHorizontalDimensionText
_style.AlignedDimensionTextOrientation = DimensionTextOrientationEnum.kInlineAlignedDimensionText
_style.VerticalDimensionTextOrientation = DimensionTextOrientationEnum.kInlineHorizontalDimensionText
End Sub
Public WriteOnly Property CenterDimensionText() As Boolean
Set(ByVal value As Boolean)
_inventor.DrawingOptions.CenterDimensionText = value
End Set
End Property
Public Sub Dispose() Implements IDisposable.Dispose
_drawing.EndManage()
_inventor.DrawingOptions.CenterDimensionText = _center
_style.HorizontalDimensionTextOrientation = _horizontalOrientation
_style.AlignedDimensionTextOrientation = _alignedOrientation
_style.VerticalDimensionTextOrientation = _verticalOrientation
End Sub
End Class
This is a follow up on this post: Unexpected dimension text place
Can't find what you're looking for? Ask the community or share your knowledge.