Unexpected dimension text place

Unexpected dimension text place

JelteDeJong
Mentor Mentor
1,234 Views
8 Replies
Message 1 of 9

Unexpected dimension text place

JelteDeJong
Mentor
Mentor

I have an iLogic rule. The part that I have problems with looks like this:

Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
Dim dimensions = Sheet_1.DrawingDimensions.GeneralDimensions

' Get all intents
Dim legIntent1 = VIEW1.GetIntent("LegMount1", PointIntentEnum.kMidPointIntent)
Dim legIntent3 = VIEW1.GetIntent( "LegMount3", PointIntentEnum.kMidPointIntent)
Dim sideIntent1 = VIEW1.GetIntent("side1", Nothing)
Dim sideIntent2 = VIEW1.GetIntent("side2", Nothing)

' Placement logic
ThisDrawing.BeginManage()
Dim textPointJustUnderView = VIEW1.SheetPoint(2, -0.2)

dimensions.AddLinear("Mounting point1", textPointJustUnderView, sideIntent1, legIntent1)
dimensions.AddLinear("Mounting point2", textPointJustUnderView, sideIntent2, legIntent3)
dimensions.AddLinear("LegMountDim1", textPointJustUnderView, legIntent1, legIntent3)
ThisDrawing.EndManage()

When I run this rule I get the following result

JelteDeJong_0-1694176445019.png

I expected a result like this:

JelteDeJong_1-1694176556270.png

for all dimensions I use the same text point offset but they are not inline. for some reason it also does not matter what I set in the x direction for the text point it is always centered. 

This is all done with iLogic API/code but when I do the same with the inventor API then I can get the expected results. (I wish I could just give a Point2D to the AddLinear function. Those sheet points dot work for me....)

Can any one point me in a direction that will get me the expected results without using the Inventor API. 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Accepted solutions (1)
1,235 Views
8 Replies
Replies (8)
Message 2 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @JelteDeJong 

 

I have never seen the X value do anything at all, for a horizontal dimension.

 

If you are placing a horizontal dimension it seems to only look at the Y value, and just ignores the X value.

If you are placing a vertical dimension it seems to only look at the X value, and just ignores the Y value.

 

That seems to just be how it works... unless I've missed something. 

 

In fact I generally instruct people to enter zero for the X when placing a horz. dim and zero for the Y when placing a vert. dim just for clarity.

 

Maybe Mike Deck can confirm this is just how it works, or help us understand how to get the expected results? @MjDeck 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

EESignature

0 Likes
Message 3 of 9

Curtis_Waguespack
Consultant
Consultant

Also, I think the 40 dims not being on the same line, might have something to do with the dim style overriding the placement, because there is not room??? 

 

I'm not sure... but based on your code, I would have expected them to land on the same line.

 

You might try the same thing with a larger space ( 100 instead of 40) or a larger view scale, to see if the dim style is forcing it off the line for some reason. 

 

 

EESignature

0 Likes
Message 4 of 9

JelteDeJong
Mentor
Mentor

Tnx @Curtis_Waguespack for your fast responds. At least it confirms that I'm not doing anything strange. 

@MjDeck can you clarify why I'm getting these results and maybe suggest a method to move the text point horizontal and on the same line as the other dimension.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 9

MjDeck
Autodesk
Autodesk
Accepted solution

@JelteDeJong , here's a way that works for me, using the SheetPoint function. But I didn't see the problem with vertical placement. That might be dependent on the dimension style.
If you can make it work with API code using Point2d coordinates, it should be possible to do the same with iLogic. You can use Point2d instead of SheetPoint. It just requires some conversion. I'll post a separate reply for that.
Here's SheetPoint code. Note how it turns off the CenterPoint option. This will prevent iLogic from automatically moving the outer text inside the dimension lines.

Dim saveCenter = ThisServer.DrawingOptions.CenterDimensionText
ThisServer.DrawingOptions.CenterDimensionText = False
Try
	' Placement logic
	ThisDrawing.BeginManage()
	Dim textPointJustUnderView_center = VIEW1.SheetPoint(0.5, -0.2)
	Dim textPointJustUnderView_left = VIEW1.SheetPoint(-0.05, -0.2)
	Dim textPointJustUnderView_right = VIEW1.SheetPoint(1.05, -0.2)

	dimensions.AddLinear("Mounting point1", textPointJustUnderView_left, sideIntent1, legIntent1)
	dimensions.AddLinear("Mounting point2", textPointJustUnderView_right, sideIntent2, legIntent3)
	dimensions.AddLinear("LegMountDim1", textPointJustUnderView_center, legIntent1, legIntent3)
	ThisDrawing.EndManage()
Finally
	ThisServer.DrawingOptions.CenterDimensionText = saveCenter
End Try

Mike Deck
Software Developer
Autodesk, Inc.

Message 6 of 9

MjDeck
Autodesk
Autodesk

Here's an example using explicit Point2d coordinates. The textOrigin argument to the iLogic AddLinear function is  a DocumentUnitsPoint2d object. This is in document units. Otherwise it's very similar to the API Point2d object. You can set its coordinates from a Point2d.

Dim saveCenter = ThisServer.DrawingOptions.CenterDimensionText
ThisServer.DrawingOptions.CenterDimensionText = False
Try
	' Placement logic
	ThisDrawing.BeginManage()
	Dim y_offset = -8 ' in drawing units
	Dim textPointJustUnderView_center = VIEW1.SheetPoint(0.5, -0.2)

	Dim textPointJustUnderView_left = ThisDrawing.Geometry.Point2d(0, 0) ' create new point in document units
	textPointJustUnderView_left.InDatabaseUnits = legIntent1.PointOnSheet ' this sets the point in document units
	textPointJustUnderView_left.X = textPointJustUnderView_left.X - 40
	textPointJustUnderView_left.Y = textPointJustUnderView_left.Y + y_offset
	
	Dim textPointJustUnderView_right = ThisDrawing.Geometry.Point2d(0, 0)
	textPointJustUnderView_right.InDatabaseUnits = legIntent3.PointOnSheet
	textPointJustUnderView_right.X = textPointJustUnderView_right.X + 40
	textPointJustUnderView_right.Y = textPointJustUnderView_left.Y
	
	textPointJustUnderView_center.Y = textPointJustUnderView_left.Y

	dimensions.AddLinear("Mounting point1", textPointJustUnderView_left, sideIntent1, legIntent1)
	dimensions.AddLinear("Mounting point2", textPointJustUnderView_right, sideIntent2, legIntent3)
	dimensions.AddLinear("LegMountDim1", textPointJustUnderView_center, legIntent1, legIntent3)
	ThisDrawing.EndManage()
Finally
	ThisServer.DrawingOptions.CenterDimensionText = saveCenter
End Try

Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 9

JelteDeJong
Mentor
Mentor

@MjDeck Thank you for the examples!

Setting the option "ThisServer.DrawingOptions.CenterDimensionText" solved the issue that the x value was ignored in the sheet point.

However, that did not solve the issue that the dimensions were on the same line. I did discover a couple of other things that led me to the solution. The dimensions are inline the first time I run the code. Only on the sequential runs will the dimensions get out of line. (That makes me expect there is a bug in the text position API.) This bug shows itself only when you have some style settings. These are those settings:

JelteDeJong_0-1694211685153.png

JelteDeJong_1-1694211739736.png

I managed to work around the issues by setting the options to the desired values and then back again. (like you did with the centre option.) The complete workaround for all issues creates a lot of code but it seems to work. (I could/should test it a bit more.) Here is the important part of the code that seems to work.

Dim saveCenter = ThisServer.DrawingOptions.CenterDimensionText
ThisServer.DrawingOptions.CenterDimensionText = False

Dim style = ThisDoc.Document.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.LinearDimensionStyle
Dim style1 = style.HorizontalDimensionTextOrientation
Dim style2 = style.AlignedDimensionTextOrientation
Dim style3 = style.VerticalDimensionTextOrientation
style.HorizontalDimensionTextOrientation = DimensionTextOrientationEnum.kInlineHorizontalDimensionText
style.AlignedDimensionTextOrientation = DimensionTextOrientationEnum.kInlineAlignedDimensionText
style.VerticalDimensionTextOrientation = DimensionTextOrientationEnum.kInlineHorizontalDimensionText

ThisDrawing.BeginManage()

' Add dimensions here!

ThisDrawing.EndManage()

ThisServer.DrawingOptions.CenterDimensionText = saveCenter
style.HorizontalDimensionTextOrientation = style1
style.AlignedDimensionTextOrientation = style2
style.VerticalDimensionTextOrientation = style3

 

@MjDeck Just on a side note. Instead of a "ThisDrawing.BeginManage()" and a "ThisDrawing.EndManage()" I wish there was a "GroupManager" that implements the "IDisposable Interface". It would be nice If we could do something like this:

Using manager As New GroupManager("groupName")
    manager.TemporaryDisableOptionCenterDimensionText()
    manager.TemporarySetStyle_BugWorkAround()

    ' Add dimensions here

End Using

Which is much shorter than the first code snippet and automatically includes a try/finally block!

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 8 of 9

JelteDeJong
Mentor
Mentor

Just for documentation. I transformed the code from the OP to this rule:

Public Sub Main()
	Dim Sheet_1 = ThisDrawing.Sheets.ItemByName("Sheet:1")
	Dim VIEW1 = Sheet_1.DrawingViews.ItemByName("VIEW1")
	Dim dimensions = Sheet_1.DrawingDimensions.GeneralDimensions

	' Get all intents
	Dim legIntent1 = VIEW1.GetIntent("LegMount1", PointIntentEnum.kMidPointIntent)
	Dim legIntent2 = VIEW1.GetIntent("LegMount2", PointIntentEnum.kMidPointIntent)
	Dim legIntent3 = VIEW1.GetIntent("LegMount3", PointIntentEnum.kMidPointIntent)
	Dim sideIntent1 = VIEW1.GetIntent("side1", Nothing)
	Dim sideIntent2 = VIEW1.GetIntent("side2", Nothing)
	
	' Setup default values
	Dim y1 = -0.3
	Dim horizontalDimType = DimensionTypeEnum.kHorizontalDimensionType
	
	Using manager As New ILogicGroupManager(ThisDrawing)
		' Placement logic
		manager.CenterDimensionText = False
		dimensions.AddLinear("Mounting point1", VIEW1.SheetPoint(-0.07, y1), sideIntent1, legIntent1)
		dimensions.AddLinear("Mounting point2", VIEW1.SheetPoint(1.07, y1), legIntent3, sideIntent2)
		
		manager.CenterDimensionText = True
		dimensions.AddLinear("LegMountDim1", VIEW1.SheetPoint(0.5, y1), legIntent1, legIntent2, horizontalDimType)	
		dimensions.AddLinear("LegMountDim2", VIEW1.SheetPoint(0.5, y1), legIntent2, legIntent3, horizontalDimType)
	End Using
End Sub


Public Class ILogicGroupManager
    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

For demonstration purposes, I added an extra dimension. As you can see the SheetPoints.X values of the LegMountDim1 and LegMountDim2 are the same but the texts are nicely centred.

JelteDeJong_0-1694381655477.png

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 9 of 9

JelteDeJong
Mentor
Mentor

I created in idea post on this topic. Basicaly I would like the class above to become a part of the iLogic API. Votes would be very welcome.

https://forums.autodesk.com/t5/inventor-ideas/create-a-class-to-handle-unexpected-dimension-text-pla...

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes