CADEditorX. Aan de slag

CADEditorX. Aan de slag

Standard CADEditorX interface:

CADEditorX standard interface

  1. Download the required version of CADEditorX: 32 bit or 64 bit
  2. Install the program
  3. To register the control element in the system via the Windows command line execute the following:
    regsvr32 <full path to the CADEditorLib.ocx library>

    For instance, to register the 64-bit version of CADEditorX in 64-bit Windows 7 execute the following:

    regsvr32 "c:\Program Files\CADSoftTools\CADEditorX 11\CADEditorLib.ocx"

    Please note: the CADEditorLib.ocx component is registered in the system during its installation. If you test different CADEditorX versions, it may be required to register the component manually in the system. Find out more about the Regsvr32 utility program at https://support.microsoft.com/en-us/kb/249873

  4. In the Start menu run the XML IDE demo application. This application helps to learn more about the CADEditorX features and provides you with access to a large number of XML examples.
    XML IDE window
  5. In the list of examples on the left select the Add.xml example and click Execute XML.
  6. When XML from the Add.xml example is executed, two objects are added to the control: the text CADSoftTools and a 10 units long horizontal line.
    Result of the Add.xml example XML execution
  7. You can also add text, lines and other objects with the help of the drawing tools embedded into the CADEditorX control. For instance, choose the Line tool and add it to the required part of the drawing with a mouse.
  8. Open demo projects that show how to run the most frequently used commands.
    CADEditorX Delphi demo

How to process XML

The programmatic interaction with the CADEditorX control element is based on the usage of the ProcessXML function and the OnProcess event.

ProcessXML Function

The ProcessXML function is used to process XML instructions. It receives the input XML as the parameter, processes it and returns the result as XML. The XML IDE demo application includes examples of XML instructions.

Syntax:

Delphi
function ProcessXML(const AInput: WideString): WideString

C#
public string ProcessXML(string AInput)

VB.NET
Public Function ProcessXML(aInput As String) As String

C++
BSTR ProcessXML(BSTR AInput)

JScript
public function ProcessXML(AInput : String) : String

AInput is the input XML document; the return value is the XML document containing some input data.

C# example:

private void button1_Click(object sender, EventArgs e)
{
  string command ="<?xml version =\"1.0\" encoding=\"utf-8\"?><cadsofttools version =\"2\">" +
                  "<command text =\"HideAllInterface\"/>" +
                  "</cadsofttools>";
  Process(command);
}    
 
private void Process(string arg)
{
  string result = axSgCADEditor1.ProcessXML(arg);
  label1.Text = result;
}

OnProcess Event

The OnProcess event is activated in the following cases:

  • when the ProcessXML function is executed
  • when one of the internal CADEditorX events is activated in case this internal event was activated earlier (i.e. if you subscribed to this event).

It makes the OnProcess event useful for processing of the data returned as XML.

Syntax:

Delphi
property OnProcess = procedure(ASender: TObject; const AXML: WideString) of object

C#
public event AxCADEditorLib.ISgCADEditorEvents_OnProcessEventHandler OnProcess
public delegate void ISgCADEditorEvents_OnProcessEventHandler(object ASender,AxCADEditorLib.ISgCADEditorEvents_OnProcessEvent e)

VB.NET
Public Event OnProcess(ByVal aSender As Object, ByVal e As AxCADEditorLib.ISgCADEditorEvents_OnProcessEvent)

C++
public IDispEventSimpleImpl<1, CCADEditorXEvents, &__uuidof(CADEditorLib::ISgCADEditorEvents)>

JScript
public event OnProcess(ASender : Object, AXML: String)

ASender is the control providing the data; AXML is the XML document containing the output data.

C# example:

public Form1()
{
    InitializeComponent();
    axSgCADEditor1.OnProcess += new AxCADEditorLib.ISgCADEditorEvents_OnProcessEventHandler(axSgCADEditor1_OnProcess);
}

private void axSgCADEditor1_OnProcess(object sender, AxCADEditorLib.ISgCADEditorEvents_OnProcessEvent e)
{
    label2.Text = e.aXML;
}

private void button2_Click(object sender, EventArgs e)
{
    string sMouseDown = "<?xml version =\"1.0\" encoding=\"UTF-8\"?><cadsofttools version =\"2\">" +
                        "<signtoevent Event =\"OnMouseDown\" Enabled =\"True\"/>" +
                        "</cadsofttools>";            
    Process(sMouseDown);

// The OnMouseDown event is an internal CADEditorX event

}

To implement complex tasks with the help of CAD XML API it is recommended to use an XML parser for processing of the output XML. There is a large number of XML parsers for all popular programming languages. Microsoft Windows offers the DOM technology to process XML; this technology is quite powerful but it is rather slow. Besides, there are a lot of simple and fast XML parsers that are offered as OpenSource for different programming languages.