Text Origin position changes when it should remain the same.

Text Origin position changes when it should remain the same.

shastu
Advisor Advisor
1,206 Views
20 Replies
Message 1 of 21

Text Origin position changes when it should remain the same.

shastu
Advisor
Advisor

Someone please explain to me how the Text.Origin works because I just can't understand why it would change without an explanation.  In order to demonstrate the problem I have added the same statement back to back for a total of 4 lines.  As I step through the code the Text Origin (x,y) changes even through the statements are identical.  I have dPosition = oDimension.Text.Origin.x so that oPosition value should not be changing, but it does.  Instead of using oPosition I tried setting the oDimension.Text.Origin = (dPosition,0) but of course it did not like that.  Please watch the video and tell me why at the very end the text origin values change between the same command being ran.  It only changes between the first time and second time.  The third and fourth time it remains the same as I would think it should.  What is even more interesting, is the value for the dPosition is -9.01809283345083 and as you can see in the video, but if I run another macro immediately after that to see what the x value is instead it is -9.1039932852577.

 

In the video, pay attention to where the 2.125 dimension moves to while the code is being stepped through.  Here is a link to the video:

https://autode.sk/3EfxdSZ

0 Likes
Accepted solutions (2)
1,207 Views
20 Replies
Replies (20)
Message 2 of 21

shastu
Advisor
Advisor

No one?  This is causing me serious problems and I need someone to explain this to me.

0 Likes
Message 3 of 21

jjstr8
Collaborator
Collaborator

I'm able to duplicate the issue you're seeing.  Since you can't manipulate Origin directly, I'm assuming that the setter for Origin, on the Inventor side, has some extra position validation code.  It acts like the coordinates are coming from a user drag of a dimension.  Dimensions have "soft" stops when dragging to help you with consistent placement and to keep you from putting text over extension lines and such.  I couldn't say for certain without seeing your code, but I think Inventor is bumping you off of positions like it would if you dragged the dimension.  In my testing, I had a diameter dimension that I had to assign Origin three times for it to stick.  Do yours eventually go in the right place?

0 Likes
Message 4 of 21

shastu
Advisor
Advisor

I am noticing the same problem with hole notes.  The y positioning works as expected, but the x position does not.  See video.  No matter where I place the hole note, if I change the y position to 0 it goes down to the same y location every time.  If I then leave the y position and just move the x dimension, it should go to the same location each time left or right, but it doesn't.  In fact, the further out I move the hole note, the further out it moves when it should be going to zero.  

0 Likes
Message 5 of 21

jjstr8
Collaborator
Collaborator

Hole notes seem to be worse.  The X position goes back and forth with each successive setting of Origin.  I also cannot figure out how you're supposed to handle the leader segments.

 

@johnsonshiue :  Can you shed some light on this?

0 Likes
Message 6 of 21

shastu
Advisor
Advisor

I agree.  it works perfectly if I only change the y value so my logic seems to be correct, but trying to change just the x direction does not work the same way.  If I set it to 0, it should go to 0 every time, but it doesn't.

0 Likes
Message 7 of 21

JelteDeJong
Mentor
Mentor

I created a small test code.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet

Dim dimension = sheet.DrawingDimensions.Item(1)

Dim p1 = ThisApplication.TransientGeometry.CreatePoint2d(dimension.Text.Origin.X, dimension.Text.Origin.Y)
Dim p2 = ThisApplication.TransientGeometry.CreatePoint2d(dimension.Text.Origin.X - 10, dimension.Text.Origin.Y)

dimension.Text.Origin = p2
MsgBox("stop")
dimension.Text.Origin = p2
MsgBox("stop")
dimension.Text.Origin = p2
MsgBox("stop")
dimension.Text.Origin = p1
MsgBox("stop")
dimension.Text.Origin = p1
MsgBox("stop")
dimension.Text.Origin = p1
MsgBox("stop")

And I could not reproduce the problem. Can you create a simple piece of test code to reproduce this problem?

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 8 of 21

shastu
Advisor
Advisor

I have attached a file with a drawing in it.  Open the drawing and run the below code:

 

Sub showproblem()
Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oDDoc As DrawingDocument
Set oDDoc = oApp.ActiveDocument
Dim oSheet As sheet
Set oSheet = oDDoc.ActiveSheet
Dim oDDims As DrawingDimensions
Set oDDims = oSheet.DrawingDimensions
Dim oDDim As DrawingDimension
Dim oLGDim As OrdinateDimension
oDDoc.SelectSet.Clear
Dim oOColl As ObjectCollection
Set oOColl = oApp.TransientObjects.CreateObjectCollection


For Each oDDim In oDDims
If TypeOf oDDim Is OrdinateDimension Then
Set oLGDim = oDDim
If oLGDim.DimensionType = kHorizontalDimensionType Then
Call oOColl.Add(oDDim)
End If
End If
Skipthis:
Next


Call oDDoc.SelectSet.SelectMultiple(oOColl)
Call showProblem2part
End Sub
Sub showProblem2part()
Dim oApp As Inventor.Application
Set oApp = ThisApplication

Dim oDrawDoc As DrawingDocument
Set oDrawDoc = oApp.ActiveDocument

' Determine how many dimensions are in the select set.
Dim oSelectSet As SelectSet
Set oSelectSet = oDrawDoc.SelectSet
Dim colDimensions As New Collection
Dim i As Long
For i = 1 To oSelectSet.count
If TypeOf oSelectSet.Item(i) Is DrawingDimension Then
' Add any dimensions to the collection. We need to save them
' in something besides the selection set because once we start
' manipulating them the select set will be cleared.
colDimensions.Add oSelectSet.Item(i)
End If
Next

For i = 1 To colDimensions.count
Dim oDimension As DrawingDimension
Set oDimension = colDimensions.Item(i)

If i = 1 Then
' Get the position of the first dimension text. This is
' the position the other dimensions will be aligned to.
Dim dPosition As Double
dPosition = oDimension.Text.Origin.x - 0.2
Else
If i = 2 Then
dPositionY = oDimension.Text.Origin.y
TopDim = oDimension.Text.Text
End If

' Change the position of the dimension.
Dim oPosition As Point2d
Set oPosition = oDimension.Text.Origin

oPosition.x = dPosition
'End If
'I don't understand why I have to run the below line twice, but it gets it closer to where it is supposed to be.
oDimension.Text.Origin = oPosition
oDimension.Text.Origin = oPosition
If TopDim = "used" Then GoTo SkipTopDim
TopDim = oDimension.Text.Text
If TopDim = findDim Then
oStr = " REF"
oDimension.Text.FormattedText = oStr
TopDim = "used"
End If
If TopDim = findDim2 Then
oStr = " REF"
oDimension.Text.FormattedText = oStr
TopDimValue = TopDim
TopDim = "used"
End If
SkipTopDim:

End If
Next


End Sub

 

if you set the oDimension.Text.Origin to a value that value should place the text at the exact location specified, but it doesn't.  I have proven that by running the code twice in a row without the oPosition changing, or at least it shouldn't change, but it does.

0 Likes
Message 9 of 21

jjstr8
Collaborator
Collaborator

@JelteDeJong :  Try your code again with the text for a hole thread note.

0 Likes
Message 10 of 21

shastu
Advisor
Advisor

Below is a simplified code just to prove my point for the hole thread notes.  Run this code multiple times and you will see the note jump back and forth between positions instead of going to the 0 position and staying there.  Also if you move the hole note before running the code you will see that it does not go to the same position as it did the first time you ran it.

 

Sub Test()

Dim oApp As Inventor.Application

Set oApp = ThisApplication

    Dim oDDoc As DrawingDocument

    Set oDDoc = oApp.ActiveDocument

    Dim oSheet As Sheet

    Set oSheet = oDDoc.ActiveSheet

    Dim oHoleNotes As HoleThreadNotes

    Set oHoleNotes = oSheet.DrawingNotes.HoleThreadNotes

    Set objPoint2D = Nothing

    Dim oHN As HoleThreadNote

 

For Each oHN In oHoleNotes

    Set oPosition = oHN.Text.Origin

    oPosition.x = 0

'    oPosition.y = 0

 

    oHN.Text.Origin = oPosition

 

Next

 

End Sub

0 Likes
Message 11 of 21

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @shastu,

 

I'm not sure I understand the behavior, but if you toggle the HideValue option it seems to "fix" the issue.

 

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

 

Dim oHN As HoleThreadNote
For Each oHN In oHoleNotes
	oHN.HideValue = True
	oPosition = oHN.Text.Origin
	oPosition.X = 0
	'oPosition.X = 0
	oHN.Text.Origin = oPosition	
	oHN.HideValue = False
Next 

 

EESignature

0 Likes
Message 12 of 21

jjstr8
Collaborator
Collaborator

@Curtis_Waguespack:  Strange behavior indeed.  I'm not sure how you even thought to do that.  I don't know if that solves every case, since you don't seem to have control over the last leg of the leader.

 

@shastu :  I saw your other post that Mike Deck replied to.  Is placing a new annotation using the information from the current annotation but with a new location an option?

0 Likes
Message 13 of 21

shastu
Advisor
Advisor

Thanks.  I don't understand why that works, but it is a great work around!!!!

0 Likes
Message 14 of 21

shastu
Advisor
Advisor

Disregard this.

0 Likes
Message 15 of 21

MjDeck
Autodesk
Autodesk
Accepted solution

@shastu , here's a modified version of your macro for moving dimensions. To make it work, I narrowed it down to ordinate dimensions. I also added an option to handle either horizontal or vertical dimensions.
It deals with two things:
1. The OrdinateDimension.Text.Origin point is at the center of the text. So if you want to align the right edge of the text with another dimension, you have to subtract half the width of the text to get the point you want. The RangeBox property gives you a box around the text.
2. In some cases, it's not enough to move the OrdinateDimension.Text.Origin. You also have to move points on the leader line. There are two points available: OrdinateDimension.JogPointOne and OrdinateDimension.JogPointTwo. These are always there, even if the line is perfectly horizontal or vertical. They can sometimes put constraints on the text such that the text just won't move where you want unless you also move them.

So this macro will do that. Please try it out. Maybe it's more complicated than it needs to be. It will try to evenly space the jog points, which is not absolutely necessary. But it makes it easier to do manual adjustments if you end up wanting a jog in the line.

It might be a good idea for Autodesk to add a new function to do this, something like
OrdinateDimension.MoveText()


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 16 of 21

shastu
Advisor
Advisor

HOLY SMOKES!!!  That seems crazy to have to do all of that, but it does work.  I would never have been able to come up with that.  Your amazing.  Thank you so much.

0 Likes
Message 17 of 21

shastu
Advisor
Advisor

Mike,  That took me a bit to figure out how to apply that into my code as I do not have user interaction of them typing in H or V and I need it to do both, not one or the other.  I also still need to capture different values depending on which ones it is doing where as your code was just capuring the code for the Horizontal dimensions.  Anyway, I was finally able to get everything figured out and it made me think of a question I would like to ask you.  I have been writing code for quite a while, but it is not what I do on a regular basis so I am no expert obviously.  When going from one procedure to another I have always just used calls and passed the information from one procedure to another.  I noticed that you are sometimes using functions and sometimes using calls.  My question is, can you give me an explanation as to when you use a function and when you use a call?  It probably should be obvious to me and if I thought about it long enough, I could probably figure out your reasoning, but just wanted to make sure I wasn't missing any other reasoning.

0 Likes
Message 18 of 21

MjDeck
Autodesk
Autodesk

If you have a procedure that produces a new output that you're going to use right away after you call it, then it's best to make that procedure a Function. Especially if the output is a single value. Then you can just return it from the function. For instance:

Function GetCoordinate(pt As Point2d, axis As Integer) As Double

returns a single value of type Double.
And you can easily call that function and get that return value with code like this:

 Dim attachX As Double
 attachX = GetCoordinate(attachPt, moveAxis)

 SetCoordinate, on the other hand, doesn't need to return anything. It produces output, but it does it by modifying a point object, which is one of its arguments. So a Sub is fine for SetCoordinate, and Call can be used to call a Sub.

Sub SetCoordinate(pt As Point2d, axis As Integer, newValue As Double)

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 19 of 21

shastu
Advisor
Advisor

O.K.  Thanks for the explanation.  One more final question and then I will be done asking on this post.  You know how you are controlling the points of the ordinate dimension leaders (pt1 and pt2)?  Can you do the same thing with chamfer notes?  I looked but did not see a way to control the Y direction of the chamfer leader note.

0 Likes
Message 20 of 21

MjDeck
Autodesk
Autodesk

Yes, you can move the points on a chamfer note leader. The ChamferNote object has a Leader property. (This object is also available on other note objects.) The Leader object is described here. It contains nodes of type LeaderNode. These are the points on the leader, with additional data. Each LeaderNode has a Position property, which is of type Point2d. You would modify that to move the leader point.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes