Hi, I can not figure out how to place a fence in C# on another model.
This is with Bentley Map 08.11.09.864
The process is :
1) Read the current fence information2) Switch to another model3) Place the fence in this model - same place as it was in the other one.
Here is what I'm trying :
BCOM.Fence oFence = null;BCOM.Element oElement = null;
if (KortAddin.ComApp.ActiveDesignFile.Fence.IsDefined){ oFence = KortAddin.ComApp.ActiveDesignFile.Fence; oElement = oFence.CreateElement(); foreach (BCOM.ViewGroup vg in KortAddin.ComApp.ActiveDesignFile.ViewGroups) { if ((vg.Name.Length >= 6) && (vg.Name.Substring(0, 6) == ModelName)) { if (!vg.Name.Contains("Temp Views")) { vg.Activate(); _wfsModel = KortAddin.ComApp.ActiveModelReference;
KortAddin.ComApp.ActiveDesignFile.Fence.Undefine(); KortAddin.ComApp.ActiveDesignFile.Fence.DefineFromElement(oFence.View, oElement);
The last line is not working - throwing this error :System.Runtime.InteropServices.COMException (0x80040000): Fence is not definedat Bentley.Interop.MicroStationDGN.Fence.get_View()
If I change the code - and comment out the "vg.Activate" - so the model is not changed - everything is working ok. But I need the defined fence in the current model - to be placed in another model.
Are the oFence and/or oElement destroyed somehow when switching the view/model ? and if so - how to make it work ?
Thanks for any input.
Thanks Jan,
The code was created by other coworkers and build upon through the years. I got the assignment to build some more onto it ;)
Thanks for the guide and help !
Best regards
Julian
Hi Julian,
at first, please read and follow this forum best practices and also common best practices. There are recommended rules defined about subject format and used tools (e.g. to use Insert > Insert code for EVERY shared code) that ensure the communication will be efficient and all necessary information will be shared from beginning.
Also, I am not sure whether MicroStation Programming forum is the best place where to ask when Bentley Map is used. On the other hand the fence placement is probably more MicroStation topic than Bentley Map ;-)
Julian Karolini said:Here is what I'm trying :
Honestly, the code is ugly ... but functional.
I think the problem is, as you asked yourself, that fence instance is invalidated when another model is activated. It is how MicroStation works, so it should be not a surprise that when another model is activated, oFence.View throws exception (because oFence is not valid reference).
Julian Karolini said:and if so - how to make it work ?
It's very simple: Fence is always shape, so remember the fence vertices and create a new fence using this list.
Julian Karolini said:Thanks for any input.
A couple of comments to the shared code:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point