Unable to see newly created layer while clicking Show Layers

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
imilchman
Posts: 6
Joined: 03 Aug 2017, 19:40

Unable to see newly created layer while clicking Show Layers

Post by imilchman » 03 Aug 2017, 19:53

Hello,
I am trying to add layer to CADPictureBox.

cadImage = this.CADPictureBox.Image;

CADLayer l = new CADLayer()
{
Name = "Test",
Visibility = true
};
l.Loaded(this.cadImage.Converter);
this.cadImage.Converter.Layers.Add(l);
cadImage.Converter.OnCreate(l);

CADLine xLine = new CADLine();
xLine.Point = new DPoint(10, 10, 0);
xLine.Point1 = new DPoint(70, 20, 0);
xLine.Color = System.Drawing.Color.Red;
xLine.LineWeight = Convert.ToSingle(10);
cadImage.Converter.GetSection(ConvSection.Entities).AddEntity(xLine);
cadImage.Converter.OnCreate(xLine);
cadImage.Converter.Loads(xLine);
xLine.Layer = l;

this.CADPictureBox.InvalidateImage();

When I run following code
for (int i = 0; i < this.CADPictureBox.Image.Converter.GetSection(CADImport.FaceModule.ConvSection.Layers).Count; i++)
S = S + ((CADLayer)this.CADPictureBox.Image.Converter.Layers).Name + ", ";
System.Windows.MessageBox.Show("Layers count: " + this.CADPictureBox.Image.Converter.Layers.Count + " " + S);

I can see newly created layer, but if I click "Show Layers" menu button I cannot see new layer in the list. I use cadimport.dll v 12.0.20.20525

Am I doing something wrong?

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Unable to see newly created layer while clicking Show La

Post by support » 03 Aug 2017, 21:24

Hello,

CADLayer is normally added to a specified CADImage instance, not to CADPictureBox, so the sentence I am trying to add layer to CADPictureBox is not correct. CADPictureBox doesn't have Image property and InvalidateImage() method that makes your code not compilable.

Let's assume that your code is compilable by replacing this.CADPictureBox.Image field with this.cadImage and commenting out the line

Code: Select all

this.CADPictureBox.InvalidateImage();
After that let's take a look at the handler for "Show Layers" menu button, it invokes SetLayList() method which actually fills the layers list:

Code: Select all

private void SetLayList()
{
    if ((lForm.LayerList.Items.Count != 0) || (cadImage == null))
        return;
    ...
}
This method adds new records to the layers list only when the list is empty (Items.Count == 0), in other words, it doesn't refresh the existing list of layers. The given fact explains why you cannot see a new layer in this list.

To see newly created layers, you may try to clear the existing list if it's not empty and fill it all over again:

Code: Select all

private void SetLayList()
{
    if (cadImage == null)
        return;
    if (lForm.LayerList.Items.Count != 0)
        lForm.LayerList.Clear();
    ...
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

imilchman
Posts: 6
Joined: 03 Aug 2017, 19:40

Re: Unable to see newly created layer while clicking Show La

Post by imilchman » 03 Aug 2017, 22:27

Thank you!

Post Reply