Here's a piece of test code that I was running where I am attempting to add a shape and save the document without opening in GUI. I am not getting any errors, but also not seeing the file change. Am I supposed to save some other way?
using (DgnDocument dgnDocument = DgnDocument.CreateForLocalFile(FullFileName))
using (DgnFileOwner dgnFileOwner = DgnFile.Create(dgnDocument, DgnFileOpenMode.ReadOnly))
var dgn = dgnFileOwner.DgnFile;
DPoint3d pntsArr = new DPoint3d;
pntsArr = new DPoint3d(newRange.High.X, newRange.High.Y, 0);
pntsArr = new DPoint3d(newRange.High.X, newRange.Low.Y, 0);
pntsArr = new DPoint3d(newRange.Low.X, newRange.Low.Y, 0);
pntsArr = new DPoint3d(newRange.Low.X, newRange.High.Y, 0);
foreach (var modelId in dgn.GetModelIndexCollection())
var model = dgn.LoadRootModelById(out status, modelId.Id);
ShapeElement shape = new ShapeElement(model, null, pntsArr);
dgn.DoSaveAs(dgnDocument, DgnFileFormatType.Current, true, false);
what AddToModel() method returns?
I guess it is not "success", when you open the file in ReadOnly mode.
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Ah, read-only was a good catch, but that didn't fix it unfortunately. The status is a "0" which I'm assuming is success?
Viktor_Kulik said:The status is a "0" which I'm assuming is success?
Yes, even when I think no int, but enum is returned.
Viktor_Kulik said:but that didn't fix it unfortunately.
Why do you use DoSaveAs?
Isn't something like ProcessChanges and to close the file enough? It's just a guess, I did not write code adding elements to DgnFile at background (yet? ;-)
Well, ProcessChanges did work. It does seem to hang a bit while doing that, but will do for now. Appreciate your help.