How to add layers in CAD.net

Discuss and ask questions about CAD .NET library.

Moderators: support, SDS, admin

Post Reply
shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

How to add layers in CAD.net

Post by shivajitheboss » 03 Jul 2019, 12:18

Hi,

I am just wondering how we can add new layers in CAD.net.Please give me brief details like class name etc.


Thanks,
Shiv

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

Re: How to add layers in CAD.net

Post by support » 03 Jul 2019, 20:35

Hello Shiv,

Please take a look at AddEntities sample project which is installed with CAD .NET library, you can find it in the folder c:\Users\USER_NAME\Documents\CAD .NET 14\demo_sources\AddEntities\C#\. The C# source file Form1.cs includes AddLayer() method:

Code: Select all

private void AddLayer()
{
    CADLayer vLayer = new CADLayer();
    vLayer.Name = cnstSpline;
    vLayer.Color = Color.FromArgb(0xFF, 0x7F, 0x9F);
    AddEntToSection(ConvSection.Layers, vLayer);
}
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

Re: How to add layers in CAD.net

Post by shivajitheboss » 04 Jul 2019, 08:10

Thank you so much, Mikhail, for your help.

Regards,
Shiv

shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

Re: How to add layers in CAD.net

Post by shivajitheboss » 05 Jul 2019, 10:57

Hi Mikhail,

I have gone through the sample code which you had suggested to me. However, I still can't add the layers in the existing image. I am trying to achieve this in WPF. Please find my code below;

public void CreateNewDrawing()
{
this.CADImage = new CADImage();
this.CADImage.InitialNewImage();
}
public void AddEntity(ConvSection aSection, CADEntity aEntity)
{
this.CADImage.Converter.Loads(aEntity);
this.CADImage.Converter.GetSection(aSection).AddEntity(aEntity);
}

private void AddLayer_Click(object sender, RoutedEventArgs e)
{
try
{
CreateNewDrawing();
CADLayer vLayer = new CADLayer();
vLayer.Name = cnstSpline;
vLayer.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x9F);
AddEntity(ConvSection.Layers, vLayer);

}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}

}

I am trying to add layers in the existing image which is I am passing using CADEditorControl.

Also, please tell me how I can get all the list of available layers in the drawing form code.

Please suggest.

Thanks,
Shiv

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

Re: How to add layers in CAD.net

Post by support » 05 Jul 2019, 17:27

Hello Shiv,

To add layers into the CADEditorControl image, you should use the CADImage object obtained through a CADEditorControl.Image property instead of a new CADImage instance created in the CreateNewDrawing() routine.

You can get the list of available layers through a CADEditorControl.Image.Converter.Layers collection.

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

Re: How to add layers in CAD.net

Post by shivajitheboss » 06 Jul 2019, 08:27

Thank you So much, Mikhail, for your help.

Now I am able to add layers in my existing drawing. The only problem I am facing is it is overriding the all the layers present in the layers toolbox with the newly created layer. So if I go to check available layers in the drawing it will only show 2 layers 0 and newly created one.

Also, Please let me know how I can check the duplicate layer.

Regards,
Shiv

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

Re: How to add layers in CAD.net

Post by support » 08 Jul 2019, 20:55

shivajitheboss wrote:
06 Jul 2019, 08:27
The only problem I am facing is it is overriding the all the layers present in the layers toolbox with the newly created layer. So if I go to check available layers in the drawing it will only show 2 layers 0 and newly created one.
Could you please specify your CADImport.dll version and post the code which you use to add layers?
shivajitheboss wrote:
06 Jul 2019, 08:27
Also, Please let me know how I can check the duplicate layer.
Could you please tell what you mean by the duplicate layer?

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

Re: How to add layers in CAD.net

Post by shivajitheboss » 09 Jul 2019, 07:50

Hi Mikhail, Thanks for your reply. Please find my comments in the bold below;

Could you please specify your CADImport.dll version and post the code which you use to add layers? I am using the "14.0.0.40520" version of CADimport.dll. Please find the code below;


private const string cnstSpline = "spline_Layer";
private void AddLayer_Click(object sender, RoutedEventArgs e)
{
try
{
CreateNewDrawing();
CADLayer vLayer = new CADLayer();
vLayer.Name = cnstSpline;
// cadImage.Converter.LayerByName("Layer1").Visible = false;
AddEntity(ConvSection.Layers, vLayer);
// CADPictureBox.LayerForm.SetLayList(vLayer);
//CADPictureBox.LayerForm.ShowDialog();

this.CADImage.GetExtents();
this.CADPictureBox.Invalidate();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}

}

public void CreateNewDrawing()
{

this.CADImage = CADPictureBox.Image;
// this.CADImage = new CADImage();
//CADPictureBox.Image = CADImage;
this.CADImage.InitialNewImage();
}

public void AddEntity(ConvSection aSection, CADEntity aEntity)
{
this.CADImage.Converter.Loads(aEntity);
this.CADImage.Converter.GetSection(aSection).AddEntity(aEntity);

}


Could you please tell what you mean by the duplicate layer? It means if there same layer with the same name is already existing in my drawing so I don't want to add the same layer again I the drawing. I Want to add a duplicate layer check in my code.

Please revert me in case of any queries.

Thanks,
Shiv

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

Re: How to add layers in CAD.net

Post by support » 09 Jul 2019, 20:11

Hello Shiv,

Thank you for the code.

The root of the problem lies in the line

Code: Select all

this.CADImage.InitialNewImage();
The InitialNewImage method creates an empty CADImage with a single layer "0". As you understood, this method shouldn't be called when working with an existing CAD drawing. Just comment out this line.

As for the check for duplicate layers, it is already implemented in a CADConverter.LayerByName method which first checks if a layer with the given name exists. If the layer exists, the method returns a corresponding CADLayer instance, otherwise, it adds a new CADLayer with the given name and returns it.

The code snippet below shows how to add a new layer using the LayerByName method.

Code: Select all

CADLayer vLayer = this.CADImage.Converter.LayerByName("NewLayer");
vLayer.Color = Color.FromArgb(0xFF, 0x7F, 0x9F);
this.CADImage.Converter.Loads(vLayer);
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

shivajitheboss
Posts: 32
Joined: 20 Jun 2019, 16:40

Re: How to add layers in CAD.net

Post by shivajitheboss » 10 Jul 2019, 07:58

Thank you so much for your help, Mikhail. Really appreciate your help.

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

Re: How to add layers in CAD.net

Post by support » 10 Jul 2019, 19:02

shivajitheboss wrote:
10 Jul 2019, 07:58
Thank you so much for your help, Mikhail. Really appreciate your help.
You are welcome. :)

Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply