Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Dimension constraint positioning

Anonymous

Dimension constraint positioning

Anonymous
Not applicable

I want create the situaition as in the photo via ilogic. I know how to create a line add the constraints and the dimension constraint. The problem i encountered is postioning the dimension constraint a little above the line and in the middle of the line.

 

Is there anyway to automaticly postion the dimension constraint like in the picture via ilogic for any kind of view  and any line length???? 

 

Here is the code so far:

 

Dim partDoc As PartDocument 
partDoc = ThisApplication.activedocument

Dim partDef As Inventor.PartComponentDefinition 
partDef = partDoc.ComponentDefinition 

'set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry


' Create a new sketch.
Dim oSketch As PlanarSketch 
oSketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(1), False)

oSketch.edit

Dim oOriginSketchPoint As SketchPoint = oSketch.AddByProjectingEntity(PartDef.WorkPoints.Item(1))
oline=oSketch.SketchLines.AddByTwoPoints (oOriginSketchPoint, ThisApplication.TransientGeometry.CreatePoint2d(-100,0))

oSketch.GeometricConstraints.AddHorizontal(oline)
oSketch.DimensionConstraints.AddTwoPointDistance(oline.startSketchPoint,oline.EndSketchPoint, DimensionOrientationEnum.kHorizontalDim,ThisApplication.TransientGeometry.CreatePoint2d(0,oline.Length*0.1))

 

 

0 Likes
Reply
480 Views
3 Replies
Replies (3)

JamieVJohnson2
Collaborator
Collaborator

Its all in your point math.  Calculated the middle point offset from the line to be exactly where you want the text center to be.  tg.CreatePoint(x,y) use line midpoint or [ startpoint + ((line startpoint - line endpoint)/2)] to get the midpoint.  

use line geometry 3d direction cross product (use the sketch plane normal vector for input) to get a vector (3d) that is 90deg from the line direction, but this has to be back translated from 3d model space to the 2d sketch space.  Or you could calculate your own 2d cross product (a 2d vector).  Or you could just use a rotation calculation.  Then find a point that is from midpoint along the new direction a distance of your intended offset (such as 1/4").

 

If you know line direction is vertical or horizontal from the beginning, then you wouldn't need vector calculus to pick a position, you simply need to manipulate x and y by adding offsets. 

Vertical line: x = midpoint x + offset, y = midpoint y

Horizontal line: x = midpoint x, y = midpoint y + offset

 

jvj

Anonymous
Not applicable

 I was afraid there is no easy way for this. I actually don't understand using vectors in inventor and translating from 3dmodel space to  2d sketch space,I always get some kind an error.@JamieVJohnson2 can i trouble you to finish this code with the method you explained in the reply if it is not too much trouble?????

 

 

Dim partDoc As PartDocument 
partDoc = ThisApplication.ActiveDocument

Dim partDef As Inventor.PartComponentDefinition 
partDef = partDoc.ComponentDefinition 

'set a reference to the transient geometry collection.
Dim oTransGeom As TransientGeometry
oTransGeom = ThisApplication.TransientGeometry


' Create a new sketch.
Dim oSketch As PlanarSketch 
oSketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(1), False)

oSketch.Edit

Dim oOriginSketchPoint As SketchPoint = oSketch.AddByProjectingEntity(partDef.WorkPoints.Item(1))
oline = oSketch.SketchLines.AddByTwoPoints(oOriginSketchPoint, ThisApplication.TransientGeometry.CreatePoint2d(- 100, - 100))

 

0 Likes

JamieVJohnson2
Collaborator
Collaborator

Sorry I'm only allowed to write code for my current organization or share bits of code that I have already written.  As far as I can go is 'psuedo' code, and what you need is going to take some time to work out.  Also it needs to be your work out, because only you know the end purpose of the code.  Besides it could be fun (if not excruciatingly educational).

 

jvj
0 Likes