Dimension Sketch with iLogic

Dimension Sketch with iLogic

Anonymous
Not applicable
2,192 Views
4 Replies
Message 1 of 5

Dimension Sketch with iLogic

Anonymous
Not applicable

I was wondering how one might go about dimensioning a line length inside of a sketch as a parameter in iLogic.

 

Currently my code does the following:

Creates a sketch:

 

Dim planeXY = oCD.WorkPlanes.Item(3)'1 for yz, 2 for xz, 3 for xy
Dim my_sketch As Sketch
my_sketch = oCD.Sketches.Add(planeXY)
my_sketch.Name = "Mounting Holes" ' name sketch
my_sketch.EditCreates parameters

 

Creates points:

 

Dim tg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim lines As Inventor.SketchLines = my_sketch.SketchLines
Dim points As Inventor.SketchPoints = my_sketch.SketchPoints

Dim point_array(3) As Inventor.SketchPoint
point_array(0) = points.Add(tg.CreatePoint2d(0, 0), False)
point_array(1) = points.Add(tg.CreatePoint2d(4, 0), False)
point_array(2) = points.Add(tg.CreatePoint2d(4, 4), False)
point_array(3) = points.Add(tg.CreatePoint2d(0, 4), False)

 

 

Connects those points to form a square:

 

'connect sketch points
Dim line0 = lines.AddByTwoPoints(point_array(0), point_array(1))
Dim line1 = lines.AddByTwoPoints(point_array(1), point_array(2))
Dim line2 = lines.AddByTwoPoints(point_array(2), point_array(3))
Dim line3 = lines.AddByTwoPoints(point_array(3), point_array(0))

 

 

Adds geometric constraints:

 

'constrain geometry
Dim constr As Inventor.GeometricConstraints
constr = my_sketch.GeometricConstraints

'horizontal constraints
constr.AddHorizontal(line0)
constr.AddHorizontal(line2)
'vertical constraints
constr.AddVertical(line1)
constr.AddVertical(line3)

'equal constraints
constr.AddEqualLength(line0, line1)

'dimension lines?????????????
Dim dimension As Inventor.DimensionConstraints
dimension = my_sketch.DimensionConstraints

 

 

But how do you dimension that line using the values defined in the parameters? I essentially want the user to be prompted to input a number as a parameter, and have that parameter be applied to the respective line. I have attached a picture of what I am hoping the end result to be.

iLogic dimension line.png

Thank you!

0 Likes
2,193 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor

Hi, try the following code. It is simplified and maybe it can help you improve your code.

 

 

Dim doc = ThisDoc.Document
oCD =doc.componentdefinition

Dim planeXY = oCD.WorkPlanes.Item(3)'1 for yz, 2 for xz, 3 for xy
Dim my_sketch As Sketch
my_sketch = oCD.Sketches.Add(planeXY)
my_sketch.Name = "Mounting Holes" ' name sketch
my_sketch.Edit 'Creates parameters
 
'Creates points:

Dim tg As Inventor.TransientGeometry = ThisApplication.TransientGeometry
Dim lines As Inventor.SketchLines = my_sketch.SketchLines
Dim points As Inventor.SketchPoints = my_sketch.SketchPoints

Dim point_array(3) As Inventor.SketchPoint
point_array(0) = points.Add(tg.CreatePoint2d(0, 0), False)
point_array(1) = points.Add(tg.CreatePoint2d(4, 0), False)
point_array(2) = points.Add(tg.CreatePoint2d(4, 4), False)
point_array(3) = points.Add(tg.CreatePoint2d(0, 4), False)
 
'Connects those points To form a square:

'connect sketch points
Dim line0 = lines.AddByTwoPoints(point_array(0), point_array(1))
Dim line1 = lines.AddByTwoPoints(point_array(1), point_array(2))
Dim line2 = lines.AddByTwoPoints(point_array(2), point_array(3))
Dim line3 = lines.AddByTwoPoints(point_array(3), point_array(0))
 
'Adds geometric constraints:

'constrain geometry
Dim constr As Inventor.GeometricConstraints
constr = my_sketch.GeometricConstraints

'horizontal constraints
constr.AddHorizontal(line0)
constr.AddHorizontal(line2)
'vertical constraints
constr.AddVertical(line1)
constr.AddVertical(line3)

'equal constraints
constr.AddEqualLength(line0, line1)

'Add Dimensions
my_sketch.DimensionConstraints.AddOffset(line0, line2.StartSketchPoint, tg.CreatePoint2d(5, 2), False, False)
my_sketch.DimensionConstraints.AddOffset(line1, line3.StartSketchPoint, tg.CreatePoint2d(2, -1), False, False)

 I hope this helps. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 5

Anonymous
Not applicable

Thank you very much for your response!

 

The line:

my_sketch.DimensionConstraints.AddOffset(line0,line2.StartSketchPoint, tg.CreatePoint2d(5,2), false, false)

worked on my end.

 

Do you think you could explain a bit how this command works though? Or perhaps a link to documentation on this command? Looks like it added a 4cm constraint. I was wondering how that comes from this line.

 

I was also hoping to make the dimension set equal to a parameter. Do you know if that's possible with this command?

 

Thank you!

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor

This is then part of the help of the inventor API.

The number you are asking for is necessary for the position of the dimension text. In my case I put that value because I knew that it would center the dimension with respect to the entities. However, you could place some function to link it to the entities so that it is centered according to them.
 
 
 

DimensionConstraints.AddOffset Method

 

Parent Object: DimensionConstraints

 

Description

 

Method that creates a new offset dimension constraint between two entities.

 

Syntax

 

DimensionConstraints.AddOffset( Line As SketchLine, Entity As SketchEntity, TextPoint As Point2d, LinearDiameter As Boolean, [Driven] As Boolean ) As OffsetDimConstraint

Parameters

NameTypeDescription
LineSketchLineInput SketchLine object.
EntitySketchEntityInput sketch entity. This must be either a or SketchPoint object. If creating a linear diameter dimension and Entity is a SketchLine, then Entity is used as the centerline. If Entity is a SketchPoint, then Line is used as the centerline.
TextPointPoint2dInput object that defines the position of the dimension text.
LinearDiameterBooleanInput Boolean that specifies whether the dimension should be a standard distance dimension or be displayed as a linear diameter dimension.
DrivenBooleanOptional input Boolean that specifies whether the dimension should be a driven or driving dimension. The default is False, which will create a driving dimension.

Remarks

One of the input entities must be a sketch line. The other entity can be either a line or a point. When two lines are input this constraint has the effect of forcing parallelism between the lines. The dimension axis is perpendicular to the sketch line input for the Line argument. The picture below illustrates two cases of the offset dimension constraint. In the dimension with the 0.614 value, the two red vertical lines are constrained. In the second case the line representing the center line and the horizontal red line are constrained. In the second case the LinearDiameter flag was set to True to result in the linear diameter type of dimension.
0.jpg
In the picture below, two offset dimension constraints are placed. This illustrates that the input line controls the axis of the dimension. The dimension line is perpendicular to the sketch line. The distance between the line and the other object is controlled by the constraint. The two dimensions below are both between a line and a point. The 0.684 dia. was placed with the LinearDiameter flag set to true.

 

1.jpg

 

 

I hope this helps you with your problem. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 5

Anonymous
Not applicable

Thanks! That does clear up how the function works. Looks like if I wanted to drive a dimension with a parameter, it would need to be done with a different method. I can probably get away without it.

 

Thank you for your help!

0 Likes