Kadmos.com

  Home | Products | Download | Purchase | Support | Language

Google
Search site:

Products
DXFReader ActiveX Control
 • DXF Files Overview
 • Distribution
 • Installation
 • Quick Start
 • Control Summary
 • Download
 • Buy now!
 • DXFReader Reference
 • DXFPlot Reference

IXF ActiveX Control

Postel ActiveX Control

Tech Support
OnLine Support
Phone Support
Sample Code
Registered Users
FAQ
References
Kadmos
Contact Kadmos
Environment
Customer List
Newsletter
Download
ActiveX Controls
Updates
Purchase
Price List
International Resellers
Our Guarantee
Shipment Options
Payment Options
Shopping Cart
    Quick Start DXFReader ActiveX Control - Quick Start

Quick Start

The DXFReader control makes it extremely easy to add CAD and plot capability to your applications.
It takes only one statement to display a DXF file and to plot it.
With the DXFPlot control you can add plot previewing capabilities with very little extra code.

First Example

The following is a demonstration of a simple application, called QuickDXF , that lets you show and plot DXF files. In just a few short steps you can produce a graphic application with complete functionality.

Before you start following the tutorial, you need to start Visual Basic and load the DXFReader custom controls. For help on how to load custom controls, see the Visual Basic documentation. We will use Visual Basic 5.0 but, with little differences, this tutorial is suited also for Visual Basic 6.0 or 4.0.

Step 1: Design the Form

Start by adding five controls to a blank form:

  1. Place the DXFReader control (Name property: DXFReader1) to cover most of the left area of the form.
  2. Place a Command Button (Name property: Command1) in the upper right corner of the form (set the Caption property to Load Files...).
  3. Place a Command Button (Name property: Command2) just below Command1 (set the Caption property to Plot Preview...).
  4. Place a Command Button (Name property: Command3) just below Command2 (set the Caption property to Plot).
  5. Near the right bottom of the form place a Common Dialog Box control (Name property: CommonDialog1).

Step 2: Add code to display DXF files

This is easy. Use the Common Dialog control to choose the file and the DXFReader control to display it. Most of the code goes into the Command1 click event:

Private Sub Command1_Click()
 With CommonDialog1

  .DefaultExt = "dxf"
  .DialogTitle = "Open DXF File"

  .Filter = "DXF File (*.DXF)|*.dxf|All (*.*)|*.*"
  .FilterIndex = 0
  .Flags = &H4 Or &H2

  .ShowOpen

  If Len(.filename) = 0 Then
   Exit Sub
  End If

  DXFReader1.ReadDXF .FileTitle

 End With
End Sub

Step 3: Add plot preview

  1. Add a new form (Name property: PlotPreview, BorderStyle property: 4 - Fixed ToolWindow).
  2. Place the DXFPlot control (Name property: DXFPlot1) to cover most of the area of this form.
  3. Add the following code to the Command2 click event:

    Private Sub Command2_Click()
     DXFReader1.PlotPreview PlotPreview.DXFPlot1
     PlotPreview.Show 1
    End Sub

Step 4: Add plot capability

This is possible only with one line of code!

Private Sub Command3_Click()
 DXFReader1.Plot
End Sub

Second Example

This example, called RasterDXF, will show how to merge a digitized image with a vectorial drawing using DXFReader.

The following picture is a digitized image of a city survey in the scale of 1:500 (1 centimeter = 5 meter).

The image was digitized at 400 dpi equal to 157.48031 pixel/cm.
We need to scale the picture to obtain that one drawing's unit is equal to one meter so the scale factor is:

1 / (157.48031 / 5) = 0.03175

The following picture shows the DXF file of the methane pipeline of the preceding part with the drawing's unit equal to one meter.

This drawing is composed of several polylines representing the different pipes: in the main street, in the secondary street and on the building.
There are also some insert of blocks indicating the valves in the pipe for gas distribution.

This example will do:

  • Load the raster picture in the control
  • Scale the picture in the way that one meter is equal to one drawing unit
  • Load the DXF file with the pipe's drawing
  • Parse the drawing database to intercept every insert of "VALVE" block
  • Add a progressive number to the valves near their insertion point
  • Plot the whole drawing scale 1:500, rotated 90° with margins of 2 centimeter from every side and interactively selecting the origin point.

Step 1: Design the Form

Start by adding six controls to a blank form:

  1. Place the DXFReader control (Name property: DXFReader1) to cover most of the left area of the form.
  2. Place a Command Button (Name property: Command1) in the upper right corner of the form (set the Caption property to 1. Load Raster Image).
  3. Place a Command Button (Name property: Command2) just below Command1 (set the Caption property to 2. Scale the Image).
  4. Place a Command Button (Name property: Command3) just below Command2 (set the Caption property to 3. Load DXF File).
  5. Place a Command Button (Name property: Command4) just below Command2 (set the Caption property to 4. Add Valves counting).
  6. Place a Command Button (Name property: Command5) just below Command2 (set the Caption property to 5. Plot scale 1:500).

Step 2: Add code to load the raster image

The code goes into the Command1 click event:

Private Sub Command1_Click()

 With DXFReader1

  .NewDrawing
  .Picture = LoadPicture(App.Path + "\kalsa.bmp")
  .Regen

  End With

End Sub

Step 3: Add code to scale the image

The code goes into the Command2 click event:

Private Sub Command2_Click()

 With DXFReader1

  .PictureScaleX = 0.03175
  .PictureScaleY = 0.03175
  .ZoomPicture 'Zoom to the full picture extents
  .SetLimits .MinX, .MinY, .MaxX, .MaxY 'Set the drawing limits to scaled picture limits

  End With

End Sub

Step 4: Add code to load the DXF file

The code goes into the Command3 click event:

Private Sub Command3_Click()

 With DXFReader1

  .ReadDXF App.Path + "\kalsagas.dxf"
  .ZoomLimits 'Zoom to the full limits

  End With

End Sub

Step 5: Add code to count the valves and to add new entities to the DXF file

The code goes into the Command4 click event:

Private Sub Command4_Click()

 With DXFReader1

 Dim k As Long
 Dim Ent As DXFReaderEntity

 With DXFReader1
  k = 1

  For Each Ent In .Entities

   If Ent.entitytype = "INSERT" Then

    If Ent.blockname = "VALVE" Then

     .AddEntity "TEXTS"
     .Entities(.Entities.Count).entitytype = "TEXT"
     .Entities(.Entities.Count).x0 = Ent.x0
     .Entities(.Entities.Count).y0 = Ent.y0
     .Entities(.Entities.Count).g40 = 0.5
     .Entities(.Entities.Count).Text = "V" + Trim(Str$(k))
     .Entities(.Entities.Count).Textstyle = "DEFAULT"
      k = k + 1

    End If
   End If

  Next Ent

  .Regen 'Regenerate the drawing

 End With

End Sub

Step 6: Add code to choose with mouse the plot origin and to plot the drawing

The code goes into the Command5 click event and into the DXFReader1 MouseDown event:

Private Sub Command5_Click()

 With DXFReader1

  .PlotMode = drCentimeters
  .PlotRotation = dr90
  .PlotMarginBottom = 2
  .PlotMarginTop = 2
  .PlotMarginLeft = 2
  .PlotMarginRight = 2
  MsgBox "Choose the plot origin onto the drawing."
  .MousePointer = drCross

  End With

End Sub

Private Sub DXFReader1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

 With DXFReader1

  If .MousePointer = drCross Then

   .MousePointer = drDefault
   .PlotOriginX = x
   .PlotOriginY = y
   .Plot

  End If

 End With

End Sub


Copyright © 2008 Kadmos.com - All rights reserved. Privacy Policy