Read multiple files to one model

< previous    1 2
Wout
10/11/2007 12:13 PM

Hi Clay,

I found the problem, the cloned object still has to be added to the model.Entities. The Clone method does not know where it should go, because the caller may want to add it to e.g. DxfBlock.Entities. Here's the working code:

C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WW.Cad.IO;
using WW.Cad.Model;
using WW.Cad.Model.Entities;

namespace DxfViewExample {
  /// &lt;summary&gt;
  /// The main form with a property grid on the left
  /// and a DXF view control on the right.
  /// &lt;/summary&gt;
  public partial class MainForm : Form {
    public MainForm(DxfModel model) {
      InitializeComponent();

      // Added by Clay *****************************************************************************
      OpenFileDialog openFileDialog = new OpenFileDialog();
      openFileDialog.FileName = 'choose source file';
      openFileDialog.Filter = 'DXF|*.dxf';
      if (openFileDialog.ShowDialog() == DialogResult.OK) {
        DxfModel sourceModel = DxfReader.ReadDxf(openFileDialog.FileName);

        foreach (DxfEntity sourceEntity in sourceModel.Entities) {
          if (sourceEntity is DxfPolyline2D) {
            model.Entities.Add(
              (DxfEntity)sourceEntity.Clone(
                model, 
                ReferenceResolutionType.CloneMissing
              )
            );
          }
        }
      }
      // Added by Clay *****************************************************************************

      viewControl.Model = model;
    }

    private void viewControl_EntitySelected(object sender, EntityEventArgs e) {
      propertyGrid.SelectedObject = e.Entity;
    }
  }
}

Wout

Clay
10/11/2007 2:33 PM

Hi Wout

Thank you very much, it works fine.

best regards
Clay

< previous    1 2