AnsweredAssumed Answered

Fully define a line in 3DSketch using API

Question asked by Hepzibah Chandranand on Oct 7, 2019



I need to fully define a line in 3DSketch using the API.


   //draw a line from origin to a point

   var line = swModelDoc.SketchManager.CreateLine(origin[0], origin[1], origin[2], pt[0], pt[1], pt[2]);


   //get the center point of the line

   var startPt = (SketchPoint)((SketchLine)line).GetStartPoint2();
   var endPt = (SketchPoint)((SketchLine)line).GetEndPoint2();

   var x = (startPt.X + endPt.X) / 2.0;
   var y = (startPt.Y + endPt.Y) / 2.0;
   var z = (startPt.Z + endPt.Z) / 2.0;


   //add the dimensions along the 3 axis

   var dimx = (DisplayDimension)swModelDoc.SketchManager.AddAlongXDimension(x, y, z);

   var dimy = (DisplayDimension)swModelDoc.SketchManager.AddAlongYDimension(x, y, z);

   var dimz = (DisplayDimension)swModelDoc.SketchManager.AddAlongZDimension(x, y, z);


This is successful in most cases.

But sometimes, one of the dimensions is not added and the line is under defined.

Also there is the scenario when the line is perfectly only in one axis.


What do I need to do additionally, for the line to be fully defined OR for all the dimensions to be added successfully??