AddCoincident with Two Sketch Points

By Xiaodong Liang

The UI allows you use the coincident constraint between two points, but if you look at the results, there is no coincident constraint. Inventor deletes one sketch point and changed both lines to share a point. The API does not hide this from the user since the signature calls to return the coincident constraint (but we can’t do that via API if no point were really created). So AddCoincident will fail if you try to constraint two sketch points of lines. If you want to merge the sketch points, use SketchPoint.Merge instead.

 

private void mergeTwoPoints()    {             // assume we have got Inventor application             // get current document        PartDocument oPartDoc =             m_inventorApp.ActiveDocument as PartDocument;        PlanarSketch oSketch =             oPartDoc.ComponentDefinition.Sketches[1];             TransientGeometry oTG =             m_inventorApp.TransientGeometry;        Point2d oLine1St =            oTG.CreatePoint2d(0,0);        Point2d oLine1End =             oTG.CreatePoint2d(1,0);                // create line 1        SketchLine line1 =             oSketch.SketchLines.AddByTwoPoints(oLine1St,                                             oLine1End);                          Point2d oLine2St =             oTG.CreatePoint2d(2,2);        Point2d oLine2End =             oTG.CreatePoint2d(3,4);            // create line 2        SketchLine line2  =            oSketch.SketchLines.AddByTwoPoints(oLine2St,                                            oLine2End);             // the line will fail        //oSketch.GeometricConstraints.AddCoincident(        //    (SketchEntity)line1.StartSketchPoint,         //    (SketchEntity)line2.EndSketchPoint);             // use this line instead        line1.StartSketchPoint.Merge(line2.EndSketchPoint);    }

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading