in .NET Try but failed to create Document from Template with given Name for the new Document

I Managed to open a new Document from Template using:
AcadApplication app = _AcAp.Application.AcadApplication as AcadApplication;
AcadDocument doc = null;
try{
doc = app.Documents.Add(sPRVorlage);
}catch(System.Exception ex){
}
A New Drawing appears but it has a defaultname "Zeichnung1". I Want to have a given Name.
I Tried several things. At Least i am able to SaveAs with given Name:
Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
acDoc.Database.SaveAs(dlg.Filename,DwgVersion.Current);
And Load the saved Copy of "Zeichnung1"
app.Documents.Open(dlg.Filename,false);
Now it has the given Name, but "Zeichnung1" is still loaded and i am not able to remove that one.

So, is there a way to directly create/load a new Drawing from Template with a given name ?
Or is there a way to remove a Drawing by Code.

Thanks a lot.

Comments

  • FrankHeinen,

    I assume that Zeichnung1 means Drawing1. If so that is the format for every new drawing, regardless of the template. It never takes on a custom name until it is saved, and by such the Zeichnung1 name is expunged. My guess is that you have confused the system by falsely retrieving Zeichnung1. It should not exist.

    Rick

  • @rwills2691 said:
    FrankHeinen,

    I assume that Zeichnung1 means Drawing1. If so that is the format for every new drawing, regardless of the template. It never takes on a custom name until it is saved, and by such the Zeichnung1 name is expunged. My guess is that you have confused the system by falsely retrieving Zeichnung1. It should not exist.

    Rick

    In German Installation "Drawing1" is "Zeichnung1". I Save this drawing with Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument;
    acDoc.Database.SaveAs(dlg.Filename,DwgVersion.Current); where dlg.Filename has the Path and Name i wanted for the Drawing, but after SaveAs in Bricscad its name is still "Zeichnung1", afterwards i can load the just saved File and its name then is correct, but the "Zeichnung1" is still loaded and i want to get rid of that now unnecesarry drawing. Thats my Problem
    Or if any way possible to change the displayed name by Saving the drawing. But how?

  • FrankHeinen,

    I think I understand you better now.

    If you manually create a new drawing, then both save or save-as will have the same result. Drawing1 is changed to your custom name, and there is not a Drawing1 anymore. It should be the same with what you are doing.

    I do COM programming, but it is in Pascal, and its formatting differs from what you are using. Additionally, I have never wanted to start or rename a file by automation. Users usually want to have their own control over doing that.

    Since you are choosing automate you may have to do more than a user would do by menu and icons. You may need to close Drawing1 after renaming by a save or save-as (I would try the save function if you haven't), and you may have to load the saved file afterward.

    Rick

  • Roy Klein Gebbinck
    edited March 2018

    Possible alternative approach:
    Since a .dwt is really a .dwg file, you can just copy the template to a file with the desired name and the .dwg extension and open that file.

  • @Roy Klein Gebbinck said:
    Possible alternative approach:
    Since a .dwt is really a .dwg file, you can just copy the template to a file with the desired name and the .dwg extension and open that file.

    Perfect Solution. Works fine, thanks a lot

  • @rwills2691 said:
    FrankHeinen,

    I think I understand you better now.

    If you manually create a new drawing, then both save or save-as will have the same result. Drawing1 is changed to your custom name, and there is not a Drawing1 anymore. It should be the same with what you are doing.

    with my Bricascad V18 SaveAs don't change Drawing1 ( or Zeichnung1 ) to the custom name. I Expected that but it is not so.

    I do COM programming, but it is in Pascal, and its formatting differs from what you are using. Additionally, I have never wanted to start or rename a file by automation. Users usually want to have their own control over doing that.

    You are wright. But in my Case i build a function that does a lot of things, including that it produces a new Drawing with generated Drawingelements as part of the whole process. The User decides the name and path, bevor the whole process starts. He gets a Dialog for that and all other settings the process need. So he has Control over that but i have to manage that by automation

    Since you are choosing automate you may have to do more than a user would do by menu and icons. You may need to close Drawing1 after renaming by a save or save-as (I would try the save function if you haven't), and you may have to load the saved file afterward.

    Rick

    I just wanted to do that, but i not managed to close Drawing1 by automation. I coded it, but the code had no effect.

    However i got another comment from Klein Gebbinck. He had a simple solution for my problem that solved my problem.
    Thanks a lot Rick for your suggestions and the time you spend.

This discussion has been closed.