Midpoint to Midpoint Constraint

Midpoint to Midpoint Constraint

Anonymous
Not applicable
3,056 Views
6 Replies
Message 1 of 7

Midpoint to Midpoint Constraint

Anonymous
Not applicable

Hey fellows,

 

I want to put create a conincident constraint between the midpoints of two lines. I already found out, that if you want to constrain midpoints via the API you have to use the MidPointConstraint Object.

 

I tried to accomplish it with the following code, but it doesn´t give me the same result, as if I would create the constraint via the Inventor User Interface. Enclosed you find a picture of the desired result 🙂

SketchPoint sketchPoint = planarSketch.SketchPoints.Add(InventorSketchLine1.Geometry.MidPoint);

MidpointConstraint midpointConstraint = planarSketch.GeometricConstraints.AddMidpoint( sketchPoint , InventorSketchLine1);

 

Has anyone stumbled across the same problem and knows a solution?

 

Best regards 🙂

0 Likes
Accepted solutions (3)
3,057 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this iLogic Rule.

Dim oSketch As PlanarSketch = ThisDoc.Document.ComponentDefinition.Sketches(1)
Dim oLine1 As SketchLine = oSketch.SketchLines(1)
Dim oLine2 As SketchLine = oSketch.SketchLines(2)
Dim oPoint As SketchPoint = oSketch.SketchPoints.Add(oLine1.Geometry.MidPoint, False)
oSketch.GeometricConstraints.AddMidpoint(oPoint, oLine1)
oSketch.GeometricConstraints.AddMidpoint(oPoint, oLine2)

If you create a new part with a sketch containing two lines and run the rule, are you then getting the desired result? 🙂

Message 3 of 7

Anonymous
Not applicable

Thanks a lot Jhoel 🙂 works perfectly! The only downside is the additional sketchpoint, but that is neglectable 😉

 

Can I ask you another midpoint related question Jhoel? Do you know if it´s possible to apply a dimensional constraint between the Endpoint of one SketchLine and the midpoint of of another SketchLine?

 

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this:

Dim oSketch As PlanarSketch = ThisDoc.Document.ComponentDefinition.Sketches(1)
Dim oLine1 As SketchLine = oSketch.SketchLines(1)
Dim oLine2 As SketchLine = oSketch.SketchLines(2)
'Create the midpoint-------------------------------------------------------------------------
Dim oLine2MidPoint As SketchPoint = oSketch.SketchPoints.Add(oLine2.Geometry.MidPoint, False)
oSketch.GeometricConstraints.AddMidpoint(oLine2MidPoint, oLine2)

'This is for the text position--------------------------------------------------------
Dim oVector As Vector2d = oLine1.Geometry.EndPoint.VectorTo(oLine2MidPoint.Geometry)
oVector.ScaleBy(1/2)
Dim oPoint As Point2d = oLine1.Geometry.EndPoint
oPoint.TranslateBy(oVector)
'-------------------------------------------------------------------------------------
oSketch.DimensionConstraints.AddTwoPointDistance(oLine1.EndSketchPoint, oLine2MidPoint, DimensionOrientationEnum.kAlignedDim, oPoint)
Message 5 of 7

Anonymous
Not applicable

Thanks again Jhoel!

I hope I can ask you another question 😅

I´d like to create a midpoint to midpoint constraint between to arcs, but I don´t know how to access their midpoints.

I tried to use  arc1.Geometry. .... , but it doesn´t return the midpoint, only the centerpoint.

Do you know how to access the midpoints?

 

Best regards from germany!

 

0 Likes
Message 6 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Sorry, I missed this post!

 

You don't really need to find the midpoint of the arc 🙂

 

Dim oSketch As PlanarSketch = ThisDoc.Document.ComponentDefinition.Sketches(1)
Dim oArc1 As SketchArc = oSketch.SketchArcs(1)
Dim oArc2 As SketchArc = oSketch.SketchArcs(2)

Dim oPoint As SketchPoint = oSketch.SketchPoints.Add(ThisApplication.TransientGeometry.CreatePoint2d(), False) 'Randomly insert the point
oSketch.GeometricConstraints.AddMidPointToArc(oPoint, oArc1) 'Constrain to first arc
oSketch.GeometricConstraints.AddMidPointToArc(oPoint, oArc2) 'Constrain to second arc
Message 7 of 7

Anonymous
Not applicable

ahhh such a simple solution 🙂 thanks a lot again!

0 Likes