// Init API.
HpdApi api = HpdApi.GetInstance();
// Open rpoject.
Project project = api.OpenProject(@"d:\Projects\Demo\Demo.hxproj");
// Open and select variant and cable drawing.
Variant variant = project.GetVariants()[0];
Drawing2D drawing = variant.GetCableDrawings().FirstOrDefault(d => d.Name == "Cable drawing_1");
drawing.Open(false, false);
try
{
// Select control points.
ICdControlPoint cp1 = drawing.GetAllOccurrences().OfType<ICdControlPoint>().FirstOrDefault(c => c.Name == "cp_00015");
ICdControlPoint cp2 = drawing.GetAllOccurrences().OfType<ICdControlPoint>().FirstOrDefault(c => c.Name == "cp_00008");
// Create the dimension.
OccCdOuterDimension dimension = (drawing as CableDrawing)?.PlaceOuterDimension(cp1, ApiDimensionPointType.Center, cp2, ApiDimensionPointType.Center, new Transform2DProperty<LengthProperty>("18mm", "-18mm"));
}
catch (Exception e)
{
// Handle the exception here.
}
// Save changes and close documents.
drawing?.Save();
drawing?.Close();
project?.Close();
api?.Close();