Regen or RegenAll each Entity in DWG C# or VB.NET

Regen or RegenAll each Entity in DWG C# or VB.NET

florian_wenzel
Advocate Advocate
2,310 Views
10 Replies
Message 1 of 11

Regen or RegenAll each Entity in DWG C# or VB.NET

florian_wenzel
Advocate
Advocate

Hi,

AutoCAD Mechanical 2023

API   VB.NET or C# and VisualStudio

 

i try to regen the Entity in Drawing, but the Result ist not exactly good.

They are still some Entity, and they are not regetereted.

 

Actualy 

florian_wenzel_0-1678967382560.png

 

the Goal:

florian_wenzel_0-1678968078681.png

florian_wenzel_1-1678968103656.png

 

 

 

 

This is my Code:

C#

 

 

[CommandMethod("Regen_OpenDWG", CommandFlags.Session)]
public void OpenDWG()
{
    string strFileName = @"C:\InventorAPI\Example\2023.03.16\Test_A.dwg";
    string strFileNameSave = @"C:\InventorAPI\Example\2023.03.16\Test_B.dwg";

    DocumentCollection acDocMgr = Application.DocumentManager;

    using (Database acCurDB = new Database(false, true))
    {
        acCurDB.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndReadShare, true, "");

        // Regenerate each entity in the drawing
        Document acDoc = Application.DocumentManager.MdiActiveDocument;
        acDoc.SendStringToExecute("_REGENALL ", true, false, false);

        acCurDB.SaveAs(strFileNameSave, DwgVersion.AC1032);
    }
}

 

 

 

VB.NET:

 

    <CommandMethod("Regen_OpenDWG", CommandFlags.Session)>
    Public Sub OpenDWG()


        Dim strFileName As String = "C:\InventorAPI\Example\2023.03.16\Test_A.dwg"
        Dim strFileNameSave As String = "C:\InventorAPI\Example\2023.03.16\Test_B.dwg"

        Dim acDocMgr As DocumentCollection = Application.DocumentManager



        Using acCurDB As New Database(False, True)
            acCurDB.ReadDwgFile(strFileName, FileOpenMode.OpenForReadAndReadShare, True, "")

            ' Regenerate each entity in the drawing
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

            acDoc.SendStringToExecute("_REGENALL ", True, False, False)
            acCurDB.SaveAs(strFileNameSave, DwgVersion.AC1032)

        End Using




    End Sub

 

 

Thanks for any Suggestion

 

 

0 Likes
Accepted solutions (1)
2,311 Views
10 Replies
Replies (10)
Message 2 of 11

_gile
Consultant
Consultant

Hi,

It seems there's some confusion here.

On one hand, you use a side database to access to a dwg file (i.e. you open the "Test_A.dwg" file in memory) on the other hand, you call the Regen command in the active document (i.e. the active document from where you call "Regen_OpenDWG").

What do you want to achieve?

Regen the active document? if so, no need to create a new Database and read "Test_A.dwg".

Regen the "Test_A.dwg" file? if so, you cannot access to the document of  a side Database and it is useless to regen a closed file because the document will automatically regen the next ime it is opened.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 11

florian_wenzel
Advocate
Advocate

Hi,

is possible to Regen all Entity from a Document in Memory using Side Database?

i was using few option, but with out result:

acCurDB.Regenmode = True

acDoc.Editor.Regen()

0 Likes
Message 4 of 11

_gile
Consultant
Consultant

What makes you think you need to regenerate a dwg opened "in memory"?

When using a "side database", the drawing is not opened in the editor (no access to the Document) so a regeneration is a non-sense.

You should clearly explain what you want to achieve instead of how you think you could do it.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 11

fieldguy
Advisor
Advisor

if you look in "Help", "regen" is viewport based (all objects in the current viewport). "regenall" regenerates the entire drawing and refreshes all viewports. for some reason, you are focused on entities.

as @_gile has indicated, regenerating is a visual effect - a regen in a side database does not make sense. autocad regenerates when the file is opened in the editor (again - a visual effect only). 

0 Likes
Message 6 of 11

florian_wenzel
Advocate
Advocate

Hi,

i want to achieve, that when i open next time the DWG Drawing, than each Curves will be regenereted.

Actualy, the Super Goal is that, when i open next time the Drawing, than each Curves are regernerated and the View Zoom is fit to Object length.

But at most imported is, that the Curves are regenerated.

 

So, maybe my Idea is, that a Script, that will Automaticly make very close Zoom to Some Curves, than regenerated .

So i think, than after this, each Curves will be Regenerated.

Or to use the Methode:  Entity.RecordGraphicsModified Method

 

The reason is, that i need to send drawings to Laser Cut, and when they open the Drawings is not complet Ready.

I will loop this  through all Documents.

 

This dwg is only a Example

0 Likes
Message 7 of 11

_gile
Consultant
Consultant

As explained upper, you cannot regen a side Database.

You should post a drawing example and explain what's wrong with this drawing.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 11

florian_wenzel
Advocate
Advocate

Hi,

so for example this 

florian_wenzel_2-1679047411228.png

 

florian_wenzel_3-1679047423841.png

 

florian_wenzel_4-1679047705691.png

 

 

0 Likes
Message 9 of 11

_gile
Consultant
Consultant

What you show in your screenshots is only the display in AutoCAD based on the Zoom value.

This will not influence the use of the file with Laser Cut.

A circle entity will always remain a circle (geometrically defined by a center, a radius and a normal) no matter how it is displayed.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 11

florian_wenzel
Advocate
Advocate

Ok,

in this Case it was a Circle, but sometimes i make a Surface Unfold, and then the Holes is Not exactly a Circle, but a Spline. And then i look very bad.

 

But, other question, is possible to regenerated each Entity, only to Visual look.

 

The Workflow with GUI is like this:

  • Zoom very close to a Circle
  • Command regen

Is Possible to do this with API, or maybe with other Steps or Methods

 

 

0 Likes
Message 11 of 11

_gile
Consultant
Consultant
Accepted solution

One more time, this only concerns the display in the AutoCAD editor.

The Laser Cut won't take in account the curves display. It will read on the geometrical data in the DWG/DXF file.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub