70001945 Create rotated dimensions with single click

Article 70001945
Type HowTo
Product Engine
Version 8
Date Added 3/26/2021 12:00:00 AM
Fixed 9.9001.0.5 (3/26/2021 12:00:00 AM)
Submitted by Kerry Francis

Summary

Is it possible to create rotated continuous dimensions with single click?

Solution

You can try a code like:

gPoint prevPT = null; // the point that th euser clicked previously
gPoint DimPos = null; // position of the dimensions
bool IsOnDimCont = false;

private void button1_Click(object sender, EventArgs e)
{
    //where doc is a vdDocument, like vdFramedControl1.BaseControl.ActiveDocument
    IsOnDimCont = false;
    if (doc.CommandAction.CmdDim(VectorDraw.Professional.Constants.VdConstDimType.dim_Rotated, null, null, 0.0d)) 
    {
        vdDimension dim = doc.ActiveLayOut.Entities.Last as vdDimension;
        prevPT = doc.World2UserMatrix.Transform(new gPoint(dim.DefPoint2)); // get the last point the user clicked and keep it for the next dimension
        gPoint DimPos = doc.World2UserMatrix.Transform(new gPoint(dim.LinePosition)); // or you can calculate this by using the midpoint of DefPoint1 & DefPoint2 plus a DX/DY 
        doc.OnPrompt += new vdDocument.PromptEventHandler(doc_OnPrompt);// enable the event
        for (int i = 0; i < 5; i++) // here you can change it to a do..while loop 
        {
            IsOnDimCont = true;
            if (doc.CommandAction.CmdDim(VectorDraw.Professional.Constants.VdConstDimType.dim_Rotated, null, DimPos, 0.0d))
            {
                vdDimension dimNext = doc.ActiveLayOut.Entities.Last as vdDimension;
                prevPT = doc.World2UserMatrix.Transform(new gPoint(dimNext.DefPoint2)); // get the last point the user clicked and keep it for the next dimension
            }
            IsOnDimCont = false;
        }
        doc.OnPrompt -= new vdDocument.PromptEventHandler(doc_OnContDimPrompt); // disable it
    }
}
 

void doc_OnContDimPrompt(object sender, ref string promptstr)
{
    if (IsOnDimCont && sender!=null && promptstr == "First Point:" ) // this means that it is inside your cont. dimension code
    {
        doc.PostCommandActionString(vdFramedControl1.BaseControl, prevPT.ToString()); // here we pass the first point of the new dimension using the prevPT stored earlier
    }
}

Send comments on this topic.