Cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Coordonate Dimensions in Draft

Experimenter
Experimenter

Hi,

 

I'm in a process of automating some drafts and would like to use coordonate dimensions.

I managed to add origin and coordinate but not in the way I want. 0 and 965 are set in the draft file, then I add the others with c#code. So far so good. Problem is I would like to have the coordonate undeneath the drawing view.Coordonate 1.PNG

I've tried different solutions, but whatever I do, or if when code end I move manually the origin to pull it down I got this result :

 

Coordonate 2.PNG

Weird right! They are not dissociated because when I move the origin the code added coordonate move also, and you can see the 965 arrow start at 563.

 

I tried to look around different properties like MeasureLineDirection, MeasurementAxisDirection, MeasurementAxisEx but every time I try to access (MeasureLineDirection) or modify (all) this properties it raises an exception :

Incorrect parameter. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))

 

So, I don't know if this properties would solve my issue, but it seems they are issues around them.

Secondly, what's am I doing wrong? How can I solve this?

 

Thanks a lot

 

application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");

documents = application.Documents;
draftDocument = (SolidEdgeDraft.DraftDocument)documents.Open(file);
sheet = draftDocument.ActiveSheet;

// Get the first and only Drawing View
drawingView = drawingViews.Item(1);

dvLines2d = drawingView.DVLines2d;

dimensions = (SolidEdgeFrameworkSupport.Dimensions)sheet.Dimensions;

List<Point> keyPointList = new List<Point>();

double xStartLine, yStartLine, xEndLine, yEndLine;

foreach (SolidEdgeDraft.DVLine2d dvLine2d in dvLines2d)
{

    dvLine2d.GetStartPoint(out xStartLine, out yStartLine);
    dvLine2d.GetEndPoint(out xEndLine, out yEndLine);

    Point p = new Point() { xStart = xStartLine, yStart = yStartLine, xEnd = xEndLine, yEnd = yEndLine, dvlined2D = dvLine2d };
    Console.WriteLine(p.xStart + " / " + p.yStart);
    keyPointList.Add(p);

}

Point origine = keyPointList.Where(p => p.xStart == keyPointList.OrderBy(px => px.xStart).First().xStart).OrderBy(p => p.yStart).First();
Point firstSquare = keyPointList.Where(p => p.yStart == keyPointList.OrderBy(py => py.yStart).First().yStart).OrderBy(p => p.xStart).First();
Point shelfTop = keyPointList.Where(p => p.xStart == keyPointList.OrderBy(px => px.xStart).First().xStart).OrderBy(p => p.yStart).Last();

List<Point> squares = keyPointList.Where(p => p.yStart == keyPointList.OrderBy(py => py.yStart).First().yStart && p.IsVertical == true).OrderBy(p => p.xStart).ToList();

SolidEdgeFrameworkSupport.Dimension dimensionOrigineX = null, dimensionEndX = null;

for (int dimIndex = 1; dimIndex <= dimensions.Count; dimIndex++)
{
    SolidEdgeFrameworkSupport.Dimension currentDimension = dimensions.Item(dimIndex);

    //Get the coordonate origin already set in the draft file
    if (currentDimension.VariableTableName.ToLowerInvariant() == "originex")
        dimensionOrigineX = dimensions.Item(dimIndex);

    if (currentDimension.VariableTableName.ToLowerInvariant() == "endx")
        dimensionEndX = dimensions.Item(dimIndex);

}

if (dimensionOrigineX != null)
{
    foreach (Point squarePoint in squares)
    {

        var u = dimensions.AddCoordinate(dimensionOrigineX, 0, 0, 0, false, squarePoint.dvlined2D.Reference, 0, 0, 0, false);
        u.TrackDistance = 0;
        var t = u.MeasureLineDirection; //Needed? Will do something?

    }
}

public class Point
{
    public double xStart { get; set; }
    public double yStart { get; set; }
    public double xEnd { get; set; }
    public double yEnd { get; set; }

    public SolidEdgeDraft.DVLine2d dvlined2D { get; set; }        

    public bool IsVertical
    {
        get {
            if (xStart == xEnd)
                return true;
            else
                return false;
        }            
    }

    public bool IsHorizontal
    {
        get
        {
            if (yStart == yEnd)
                return true;
            else
                return false;
        }
    }
}