how to get Layout list and Entities list in file ViewerControlMainForm.cs file

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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 11 Jul 2019, 16:06

Hi Mikhail,

Need one help from your side. I want to get the control of Layout list, Block and Entities. Do we have such kind of control in our CAD.Net library in ViewerControlMainForm.cs file(Viewer control demo) ?.

So I can access the control and perform some action on that. Also, do let me know all the methods and events names which are populating the data.

Eagerly waiting for your reply.

Regards,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 11 Jul 2019, 20:23

Hello Shiv,

ViewerControlDemo project uses CADViewerControl which is a part of CAD .NET library. The control provides an access to a CADLayoutCollection through a CADViewerControl.Image.Converter.Layouts property. To get a list of CADLayout objects, you should iterate through the Layouts collection with a for-loop and populate the list with CADLayout items when the loop is running:

Code: Select all

using System.Collections.Generic;
...

List<CADLayout> layouts = new List<CADLayout>();
for (int i = 0; i < cadViewerControl1.Image.LayoutsCount; i++)
{
    layouts.Add(cadViewerControl1.Image.Converter.Layouts[i]);
}
As for the CADBlock and CADEntity lists, they can be populated using the ForEach method of CADImage.Converter.Blocks and CADImage.Converter.Entities collections that are accessed through a CADViewerControl.Image property:

Code: Select all

List<CADBlock> blocks = new List<CADBlock>();
cadViewerControl1.Image.Converter.Blocks.ForEach(entity => blocks.Add(entity as CADBlock));

List<CADEntity> entities = new List<CADEntity>();
cadViewerControl1.Image.Converter.Entities.ForEach(entity => entities.Add(entity));
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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 16 Jul 2019, 12:25

Sorry for the late reply, Thanks a lot for your help, Mikhail. Now I am able to get all entities and blocks in my drawing. I just wanted to know how I can show my model into Cadviewer control?
Regards,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 16 Jul 2019, 18:01

Hello Shiv,

Could you please specify what you mean by my model? Is it an existing drawing loaded from a file or a new CADImage instance created by code?

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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 17 Jul 2019, 08:23

Hi Mikhail,

Thanks for your reply. yes, the model is part of my existing design and I have got it from layout collection.

Also, my layouts return me multiple things(e.g . Models, rules, etc), How I can filter them and show them on CAdviewer control one by one.

Please let me know how I can pass and show it to Cadviewer control.


Thanks,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 17 Jul 2019, 18:53

Hello Shiv,

CADViewerControl shows the current CAD layout (CADImage.CurrentLayout) by default. However, you can switch between CAD layouts (Model, Layout1, Layout2, etc.) using the text box with a drop-down list located on the Layouts panel, right under the toolbar. Or you may change the current layout by code:

Code: Select all

// Layouts[0] item always corresponds to Model
cadViewerControl1.Image.CurrentLayout = cadViewerControl1.Image.Converter.Layouts[0];
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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 17 Jul 2019, 20:10

Thank you so much for your help, Mikhail.

I have tried the below code for showing the model in the cad viewer control but instead of showing model, it is still showing.DWG drawing.

if (CADImage != null)
{
try
{
List<CADLayout> layouts = new List<CADLayout>();
for (int i = 0; i < CADPictureBox.Image.LayoutsCount; i++)
{
layouts.Add(CADPictureBox.Image.Converter.Layouts);
}
CADPictureBox.Image.CurrentLayout = CADPictureBox.Image.Converter.Layouts[0];



Also, do let me know is there any way to filter layouts by name.



Best regards,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 17 Jul 2019, 20:15

shivajitheboss wrote:
17 Jul 2019, 20:10
Thank you so much for your help, Mikhail.

I have tried the below code for showing the model in the cad viewer control but instead of showing model, it is still showing.DWG drawing.

if (CADImage != null)
{
try
{
List<CADLayout> layouts = new List<CADLayout>();
for (int i = 0; i < CADPictureBox.Image.LayoutsCount; i++)
{
layouts.Add(CADPictureBox.Image.Converter.Layouts);
}
CADPictureBox.Image.CurrentLayout = CADPictureBox.Image.Converter.Layouts[0];

Could you please tell what layout name is displayed in the text box located on the Layouts panel, right under the CADViewerControl toolbar?

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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 17 Jul 2019, 20:21

Hi Mikhail,

Currently, it is showing the entire.DWG file in viewer editor even after assigning the layout[0]th index to the viewer control.

Also, please let me know the function, control, and event names that are used for the same in Cadviewer control demo.

Thanks,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 17 Jul 2019, 23:40

shivajitheboss wrote:
17 Jul 2019, 20:21
Currently, it is showing the entire.DWG file in viewer editor even after assigning the layout[0]th index to the viewer control.
Honestly, I don't understand what you mean by the entire DWG file. CADViewerControl cannot show all the layouts at once, it shows a certain layout whose name is displayed in the combo box located on the Layouts panel, right under the CADViewerControl toolbar.

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 get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by shivajitheboss » 18 Jul 2019, 19:12

I am so sorry about creating the confusion, Mikhail. Yes, you were right it was showing the only single layout at a time. Thanks a lot for your help.

Is there any way to filter the layouts with the names and display them as required.

Regards,
Shiv

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

Re: how to get Layout list and Entities list in file ViewerControlMainForm.cs file

Post by support » 19 Jul 2019, 15:53

Hi Shiv,

Only one layout can be displayed at a time. Could you give some more details about the task you wish to solve?

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

Post Reply