Page 1 of 1

How to load several files in a CadViewerControl

Posted: 14 Nov 2019, 08:54
by OhMonBato
I'm beginner with Cad.net and I need to open several files (DXF or DWG) and display them together in a single control.
How can I do that ?

I'm programming using VB.Net

Re: How to load several files in a CadViewerControl

Posted: 14 Nov 2019, 13:23
by support
Hello,

Single CADViewerControl instance cannot load and display several DWG/DXF files at once.

Mikhail

Re: How to load several files in a CadViewerControl

Posted: 14 Nov 2019, 14:53
by OhMonBato
Thank you for your answer.
I tried with a CadViewerControl to load 2 differents files using this way :

Code: Select all

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Img = New CADImage
        Img = CADImage.CreateImageByExtension("2carres.dwg")
        Img.LoadFromFile("2carres.dwg")
        CadViewerControl1.LoadFile("2carres.dwg")
    End Sub
And with a second button :

Code: Select all

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim DP1 As New DPoint(0, 0, 0)
        Dim DPScale As New DPoint(1, 1, 1)

        Img = New CADImage
        Img = CADImage.CreateImageByExtension("2cercles.dwg")
        Img.LoadFromFile("2cercles.dwg")
        CadViewerControl1.Image.AddScaledDXF(Img, "2cercles.dwg", DP1, DPScale, 0)
    End Sub
With second button, is the file inserted as a block ?
Or is it possible in a ViewerControl to open several files only as block ?

Re: How to load several files in a CadViewerControl

Posted: 14 Nov 2019, 20:41
by support
CADImage.AddScaledDXF method inserts an Xref - a reference to an external DWG/DXF file that appears in the current drawing and gives you the visual impression that it is part of the drawing.

Xrefs are often compared to blocks, but they have a major advantage over the latter. When a block is inserted into a project, its geometry does not change regardless of the source file’s changes. When an Xref is inserted to a project, the host project is updated at every opening with what the current state of the Xref is.

Mikhail

Re: How to load several files in a CadViewerControl

Posted: 17 Nov 2019, 17:52
by OhMonBato
Thank you for the explanation, but for the moment Xref is exactly what I need. I just need to display some files, user will not be allowed to modify them.

There is something I don't understand. I you refer to my previous post, I've 2 buttons, if I click on button 1 then button 2, no problem (load a file then display another file as Xref). But if I click directly on button 2, so without loading another file before, I've an error and cannot display the file as Xref.

Re: How to load several files in a CadViewerControl

Posted: 21 Nov 2019, 17:10
by support
Hi

The problem with button 2 occurs because to display a file as Xref you need to create a CADImage first like follows:

Code: Select all

ImgBase = New CADImage
ImgBase.InitialNewImage()
cadViewerControl1.Image = ImgBase
Without cadViewerControl1.Image = ImgBase you'll get an exception at CadViewerControl1.Image.AddScaledDXF(Img, "2cercles.dwg", DP1, DPScale, 0)

Andrei