Problems with saving to a DXF

Discuss and ask questions about CAD .NET library.

Moderators: admin, support, SDS

Post Reply
Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Problems with saving to a DXF

Post by Pascal » 04 Apr 2019, 14:19

Hello, I have some problems with saving to a DXF.

I have a ZIP file that with a test project where you can see the problems. It’s build from the AddEntities demo. I removed some buttons and created 2 new: Test ext. icon & Test circle. I also added some comment in the code to clarifier the problem.
But I cannot upload it here. I always get a warning that the file is too lage. Can I send it via another way? It's only 1.5MB.


1: When I draw a circle that is filled via a vBoundaryList.
That works fine within you component, but it will not generate a DXF. For example, when you save the DXF to your desktop, you see it’s generated. And when the save is finished, the file disappears.
I need these circles for a background to display a number in it.


2: In my project, I need to import icons from an external DXF. That works fine. But not in the saved DXG.
If I use a external DXG that has an external SHX file. The generated DXF cannot be opened in AutoCAD.
To be sure that the external SHX is not the problem, I have an example without the SHX. Now AutoCAD can open the DXF file, but the icon is not visible.
You can see both in the code.

Can you help me with this?
That last part is very important to finish my project. And especially the icon with external SHX file.

Thanks,
Pascal

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

Re: Problems with saving to a DXF

Post by support » 04 Apr 2019, 23:45

Hello Pascal,

We have changed the maximum file size allowed for a single attachment. Please try to attach the test project to your post using 'Edit post' button.

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

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 05 Apr 2019, 09:01

Sorry, same problem. And I also have the same problem when I upload a smaller ZIP of 900k where de CADimport dll is removed.

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

Re: Problems with saving to a DXF

Post by support » 05 Apr 2019, 19:47

Hello Pascal,

We have increased the maximum file size allowed for a single attachment up to 10 MBytes. Please try to attach the .zip file again.

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

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 06 Apr 2019, 10:30

Thanks, it worked. But I could not include the bin folder with the dll and exe files. That gave an error.
Do you have enough with this?
This example is based on the AddEntities demo, you can you the dll's from there.
Attachments
TestPascal.zip
(647.79 KiB) Downloaded 40 times

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

Re: Problems with saving to a DXF

Post by support » 09 Apr 2019, 17:40

Hello Pascal,

DXF file is not generated, because you didn't set a boundary path type flag for a vBoundaryList. You can set this flag through a CAD2DBoundaryList.BoundaryType property as follows:

Code: Select all

CAD2DBoundaryList vBoundaryList = new CAD2DBoundaryList();
vBoundaryList.BoundaryType = 1;
vBoundaryList.Add(vEllipse);
According to Autodesk DXF Reference, the boundary path type flag (bit coded) may take the following values:

Code: Select all

0 = Default
1 = External 
2 = Polyline
4 = Derived 
8 = Textbox 
16 = Outermost
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 10 Apr 2019, 10:03

Thank you very much, that solved the problem with the circle.
And did you find the problem with the icons from an external DXF?

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

Re: Problems with saving to a DXF

Post by support » 11 Apr 2019, 00:20

Hello Pascal,

The icon is not visible in the resulting DXF file, because you didn't copy the block "RF avec TA" from an external DWG file (Icons2.dwg) to the BLOCKS section of the created CAD image. The point you are missing is that a CADInsert object doesn't store entities, CADBlock does. CADInsert object is a reference to a CADBlock object, so adding the reference, not having the content, doesn't make sense.

Copying a CAD entity from an external drawing file is quite complicated process: you will have to create a copy of the entity by using a CADEntity.AssignEntity method and then add the copy to the created CAD image. To keep the entity appearance in the resulting DXF file, you will have to copy a layer (CADLayer) to which the entity belongs (it is important when the entity color is set to ByLayer), line type (CADLineType) used by the entity and, in case of CADText/CADMText entities, text style (CADStyle). In case of CADInsert entity, you will also need to copy its CADBlock and each entity in a CADBlock.Entities collection (the collection may contain CADInsert entities when using nested blocks). If the entity contains extended data (EED), you need to copy it as well.

I will try to post a routine which implements the above said as soon as possible.

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

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 15 Apr 2019, 11:02

Good news that it’s possible. I’ll wait for the code to check it out.
Thanks

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 06 May 2019, 10:05

Hello Mikhail, do you have any idea when you can post that routine?

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

Re: Problems with saving to a DXF

Post by support » 08 May 2019, 23:50

Pascal wrote:
06 May 2019, 10:05
Hello Mikhail, do you have any idea when you can post that routine?
Probably, next week.

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

Pascal
Posts: 16
Joined: 26 Oct 2018, 14:33

Re: Problems with saving to a DXF

Post by Pascal » 27 May 2019, 14:40

Hello Mikhail, please don't forget this.
Pascal

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

Re: Problems with saving to a DXF

Post by support » 07 Jun 2019, 21:20

Hello Pascal,

Sorry for a long wait for the code. Below you will find a routine which creates a copy of CADBlock in another CAD image.

Code: Select all

private CADLineType AddLType(CADImage targetImage, CADEntity entity)
{
    if (entity.LineType == null) return null;
    CADLineType linetype = targetImage.Converter.LTypeByName(entity.LineType.Name);
    if (linetype == null)
    {
        targetImage.Converter.Loads(entity.LineType);
        targetImage.Converter.GetSection(ConvSection.LTypes).AddEntity(entity.LineType);
        linetype = entity.LineType;
    }
    return linetype;
}

private CADLayer AddLayer(CADImage targetImage, CADEntity entity)
{
    if (entity.Layer == null) return null;
    int count = targetImage.Converter.Layers.Count;
    CADLayer layer = targetImage.Converter.LayerByName(entity.Layer.Name);
    if (count != targetImage.Converter.Layers.Count)
    {
        layer.AssignEntity(entity.Layer);
        layer.LineType = AddLType(targetImage, layer);
    }
    return layer;
}

public void CreateCopyOfBlock(CADBlock sourceBlock, CADImage targetImage)
{
    if (sourceBlock == null)
        return;
    CADBlock targetBlock = new CADBlock();
    targetBlock.Name = sourceBlock.Name;  

    CADEntity ent, newEnt;
    for (int i = 0; i < sourceBlock.Count; i++)
    {
        ent = sourceBlock.Entities[i];
        if (ent.EntType != EntityType.XRef)
        {
            if (ent.EntType == EntityType.Insert)
                CreateCopyOfBlock((ent as CADInsert).Block, targetImage);
            newEnt = (CADEntity)Activator.CreateInstance(ent.GetType());
            newEnt.AssignEntity(ent);
            newEnt.Layer = AddLayer(targetImage, ent);
            newEnt.ExtendedData.AddRange(ent.ExtendedData);
            targetBlock.AddEntity(newEnt);
        }
    }
    targetImage.Converter.GetSection(ConvSection.Blocks).AddEntity(targetBlock);
    targetImage.Converter.Loads(targetBlock);
}       

You should call the CreateCopyOfBlock method in your code as follows.

Code: Select all

    for (int i = 0; i < cadImageIcons.Converter.Entities.Count; i++){ 
        if(!IconFound){
            CADEntity ent = cadImageIcons.Converter.Entities[i];
            if(ent.EntType == EntityType.Insert){
                if(ent.Layer.Name.Equals(LayerToFind)){
                    // We found the layer, now find the icon
                    if(((CADInsert)ent).Block.Name.Equals(BlockToFind)){
                        MyIcon = (CADInsert)ent;
                        IconFound = true;
                        CreateCopyOfBlock(MyIcon.Block, this.cadImage);
                    }
                }
            }
        }
    }			
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply