KernelCAD Documentation

DInsight Home
Skip Navigation Links.
Start page
Quick Start
Installation
Overview of the software
What is new
Collapse KernelCAD ModelsKernelCAD Models
Collapse KernelCAD ComponentsKernelCAD Components
KernelCAD Control
KernelCAD .NET Control
Methods and Properties
Menu
Model Explorer
Birds Eye View
Programming
Direct User Access
Direct Operations
Interface Queries
Printing Support
Data Types
Modes of KernelCAD Control
DIObjectGenerator class
Properties
FlatObjectArray Poperty
Context
64 bit development
Dual Mode
Initialisation Context
Overlay Editor
Memory Management
Input validation
Collapse Advanced functionalityAdvanced functionality
Collapse InterfacesInterfaces
Alphabetical list
I3DGrid
I3DBugger
I3Dpt
IAxiBase
IAxis
IBoolSection
IBoolSectionEx
IBoundary
IColor
IConstraint
IData
IDiffSurface_KC
IDIFont
IDraw
IDrawUtil
IDraw2
IElem
IElement
IKCLine
ILightSource
ILocation
ILocationEx
IMaterial
IMetrics
IMetrics2
IModel
IModel2
IModelEx
IPatch
IKCPathCollisionDetector
IProfiles
IPropertyArray
IPropertyArray2
IStdShape
IStrip
ISurface
IText
ITexture
ITransform
IUnknown
Collapse Open Cascade TechnologyOpen Cascade Technology
Collapse DataData
Collapse MovementMovement
Collapse FramesFrames
Collapse Oriented ObjectsOriented Objects
Collapse SectionsSections
Collapse GeneralGeneral
Collapse Topological InterfacesTopological Interfaces
Collapse Viewing InterfacesViewing Interfaces
Collapse Lines And CurvesLines And Curves
Collapse Symmetry InterfacesSymmetry Interfaces
Collapse Clipping plane interfacesClipping plane interfaces
Collapse AlgorithmsAlgorithms
Collapse 2D Geometry2D Geometry
Collapse Programming Samples and TutorialsProgramming Samples and Tutorials
Collapse OverviewOverview
Collapse DeploymentDeployment
Collapse .NET Samples.NET Samples
Collapse C++ SamplesC++ Samples
Collapse Visual Basic SamplesVisual Basic Samples
Collapse Delphi SamplesDelphi Samples
Collapse 3D Debugger3D Debugger
Collapse DeploymentDeployment
Licensing
Model Viewer
Open C++ Source
Technical Support
Skip Navigation LinksHome Page > Programming Samples and Tutorials > .NET Samples > WPF > WPF
WpfCAD Sample Overview

WpfCAD C# WPF Tutorial

Source code for the sample is located in the Samples\NET\C#\WPF\WpfCAD folder of the KernelCAD installation directory.

The application demonstrates usage of KernelCAD in a Windows Presentation Framework application.

The tutorial is based on Visual Studio 2008. It also assumes KernelCAD 4.3 or later is installed on the computer.

The application will depend on the controls library <KernelCAD Installation Directory>Samples\NET\C#\WPF\KcAxLib

Creating the application

  • Build 32 bit Debug version of the KcAxLib project
  • Close KcAxLib solution
  • Create new C# WPF application in Samples\NET\C#\WPF\ folder
  • Open the project properties for the project and in the Build page select Platform Target x86
  • Add references to all dlls in the KcAxLib\Bin\Debug folder: Right-click on the project file in the solution explorer, Select Add Reference. Browse to KcAxLib\Bin\Debug folder. Select all .dll files in the folder. Click OK
  • Add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll. To do that in the Add Reference dialog select the .NET tab, scroll down and select WindowsFormsIntegration item
  • Add a reference to System.Windows.Forms assembly in the same manner
  • Open Window1.xaml and replace lines containing Title and Grid element with:

Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid Name="grid1">

</Grid>

  • Open Window1.xaml.cs and add the following three lines at the top

using KcAxLib;
using AxKernCADnet;
using KernCADnet;

  • In the same file add the method below to the Window1 class

private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host = new     System.Windows.Forms.Integration.WindowsFormsHost();


// Create the ActiveX control.
KcAxLib.KcAxControl axKc = new KcAxLib.KcAxControl();

// Assign the ActiveX control as the host control's child.

host.Child = axKc;

// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);

axKc.ModelPath = "Models\\Torus.glm";

IModel iModel = axKc.GetModel();
int countObjects = iModel.GetSectionCount();
if (countObjects > 0)
{
ISection iSection = iModel.GetSection(0);
string objName = iSection.GetName();
int countChildren = iSection.GetChildCount();
}
}

  • Build the application
  • Set a break point in the Window_Loaded method and check that everything works as expected, namely countObjects is not zero and the objName is "Torus_Knot01"

Samples\NET\C#\WPF\ folder contains a finished copy of the tutorial in WpfCAD_Completed folder.

See also "Walkthrough: Hosting an ActiveX Control in WPF" MSDN topic: