Coincident constraint - why so complicated?

Coincident constraint - why so complicated?

llorden4
Collaborator Collaborator
1,258 Views
5 Replies
Message 1 of 6

Coincident constraint - why so complicated?

llorden4
Collaborator
Collaborator

I constantly struggle with the Coincident constraint, and it seems a bit unnecessary the additional steps that are required to make this constraint work within iLogic.

 

I don't have to take these additional steps with the other constraints so maybe this is just a handling bug within Inventor, but when I want to use this Coincident constraint with sketchpoints, I must first assign the sketchpoint to a variable name, I can't simply point to the sketchpoint itself.

 

Example that fails but typically works with other constraint types:

oSketch.GeometricConstraints.AddCoincident(Line1.EndSketchPoint, Arc1.CenterSketchPoint)

 

Example that succeeds:

oSKP1 = Line1.EndSketchPoint
oSKP2 = Arc1.CenterSketchPoint
oSketch.GeometricConstraints.AddCoincident(oSKP1, oSKP2) 

 It's a bit frustrating to have to keep re-figuring these steps out whenever I come back to needing this constraint and seems an unnecessary fluff factor to coding.  The editor's pop-up shows these variable types as "SketchPoints" while I'm typing, so the format appears correct and I fail to understand why the direct pointer fails to work in this case.

llorden4_0-1639170797584.png

 

Something I'm overlooking or another process that's consistent in approach with all the other constraints?

 

Currently using Inventor 2022.2

Autodesk Inventor Certified Professional
0 Likes
Accepted solutions (1)
1,259 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor

I tried the following code and it works for me.

Dim doc As PartDocument = ThisDoc.Document
Dim oSketch As PlanarSketch = doc.ComponentDefinition.Sketches.Item(1)
Dim Arc1 As SketchArc = oSketch.SketchArcs.Item(1)
Dim Line1 As SketchLine = oSketch.SketchLines.Item(1)

oSketch.GeometricConstraints.AddCoincident(Line1.EndSketchPoint, Arc1.CenterSketchPoint)

I can't reproduce the problem. Can you post the complete script you are working on?

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 3 of 6

llorden4
Collaborator
Collaborator

Here's an executable of the issue you can copy and paste to run...

 

Sub Main
Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oWorkPlane As WorkPlane
Dim oSketch As PlanarSketch
Dim oLine(3) As SketchLine

'for sample
Dim FlatAngle As Double = 30
Dim Dia As Double = 30
Dim Value As Double
Dim IsSlipJoint As Boolean = False
Dim MatThick As Double = 0.25

'close any active sketches
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
    oSketch = ThisApplication.ActiveEditObject
    oSketch.ExitEdit
End If

'remove any previously created stuff
While oCompDef.Features.Count > 0
	oCompDef.Features.Item(oCompDef.Features.Count).Delete
End While

While oCompDef.Sketches.Count > 0
	oCompDef.Sketches.Item(oCompDef.Sketches.Count).Delete
End While

'make new stuff
oWorkPlane = oCompDef.WorkPlanes.Item("XZ Plane")
oSketch = oCompDef.Sketches.Add(oWorkPlane)
oSketch.Name = "Sealer sketch"
oGC = oSketch.GeometricConstraints
oDC = oSketch.DimensionConstraints
Value = (Dia / 2 * 2.54) * Tan(FlatAngle / 2 * PI / 180)
oLine(1) = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(-Value, -(Dia / 2 * 2.54)), oTG.CreatePoint2d(0, 0))
oLine(2) = oSketch.SketchLines.AddByTwoPoints(oLine(1).EndSketchPoint, oTG.CreatePoint2d(Value, -(Dia / 2 * 2.54)))
oGC.AddGround(oLine(1).EndSketchPoint)
oGC.AddHorizontalAlign(oLine(1).StartSketchPoint, oLine(2).EndSketchPoint)
If IsSlipJoint Then												'slipjoint = polygon shape
	oLine(3) = oSketch.SketchLines.AddByTwoPoints(oLine(2).EndSketchPoint, oLine(1).StartSketchPoint)
	oSKP = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0), False)
	oGC.AddMidpoint(oSKP, oLine(3))
	oGC.AddVerticalAlign(oSKP, oLine(1).EndSketchPoint)
	oTmp = oDC.AddTwoLineAngle(oLine(1), oLine(2), oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False)
	oTmp.Parameter.Expression = CStr(FlatAngle) & " deg"
	oTmp = oDC.AddOffset(oLine(3), oLine(1).EndSketchPoint, oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False, False)
	oTmp.Parameter.Expression = CStr(Dia / 2) & " in"
Else
	oArc = oSketch.SketchArcs.AddByCenterStartEndPoint(oLine(1).EndSketchPoint, oLine(2).EndSketchPoint, oLine(1).StartSketchPoint, False)
	
'This line fails
	oGC.AddCoincident(oLine(1).EndSketchPoint, oArc.CenterSketchPoint)

'These REM'd lines don't fail
'	oSKP1 = oLine(1).EndSketchPoint
'	oSKP2 = oArc.CenterSketchPoint
'	oGC.AddCoincident(oSKP1, oSKP2)


	oTmp = oDC.AddTwoLineAngle(oLine(1), oLine(2), oTG.CreatePoint2d(0, oLine(1).Geometry.MidPoint.Y), False)
	oTmp.Parameter.Expression = CStr(FlatAngle) & " deg"
	oTmp = oDC.AddRadius(oArc, oTG.CreatePoint2d(0, -Dia / 4 * 2.54), False)
	oTmp.Parameter.Expression = CStr(Dia / 2) & " in"
End If
oProfile = oSketch.Profiles.AddForSolid
oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kNewBodyOperation)
oExtrudeDef.SetDistanceExtent(MatThick * 2.54, kNegativeExtentDirection)
oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
oExtrude.Name = "Sealer Plate slice"

End Sub
Autodesk Inventor Certified Professional
0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

If you want to joint two curves by its end points, don't use AddCoincident() method but Merge two points to one.

This code works for me.

 

'This line fails
'oGC.AddCoincident(oLine(1).EndSketchPoint, oArc.CenterSketchPoint)
oLine(1).EndSketchPoint.Merge(oArc.CenterSketchPoint)

'These REM'd lines don't fail
'	oSKP1 = oLine(1).EndSketchPoint
'	oSKP2 = oArc.CenterSketchPoint
'	oGC.AddCoincident(oSKP1, oSKP2)

 

 

Here is full description of Sketch constraints API. At the bottom of the page is described your issue

https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-30082FDF-9476-49C6-BB3E-0DE90A3CC812

 

Message 5 of 6

llorden4
Collaborator
Collaborator

How in the world did you ever find that line of text?  Thanks for that link and solution.

Autodesk Inventor Certified Professional
0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor

Because I was in the same trouble few years ago.😁

0 Likes