Hi,
I'm using a VBA script to drop all elements of an active file and its attachments and copy them into another file. It has worked fine for years - until now.
Example: I have an active dgn file with one attachment to it. Exporting elements from the active file is no problem at all, no matter what type. Now the attachment: inside of it there is a complex chain with a few linestrings and arcs.If I use Microstations property dialog it shows level "A" for complex chain header and also level "A" for child elements.When I debug my script it shows level "A" for complex chain header and after dropping that and stepping through returned ElementEnumerator elements those elements have level "B".
It seems like Microstation is not able to get right level information when dropping complex elements that came from an attachment.
Did someone else stumbled across that behavior? What did you do? Any help would be greatly appreciated!
RegardsStephan
Hi Jan,
copy context was the problem. Once again. I'm not sure but I think we had that topic before... The problem was that I took some complex chain/polygon element from attachments directly out of an element enumerator and dropped it to iterate through its child elements.
The solution is to copy the complex element from the attachment into the active model (by using the copy context) before dropping it. Then after dropping it the child elements will have correct level settings and stuff.
Thank you for your help!
Hi Stephan,
Stephan L. said:As far as I know (I'm not at office right now) I don't use any kind of CopyContext there.
I recommend to use CopyContext every time you copy an element from reference to active model. I think the role of CopyContext cannot be substituted by other code easily, because it takes care about managing situation when e.g. level exists in reference but not in the target model.
Stephan L. said:At that point the debugger already shows "wrong" values.
It's important information. I am not sure how exactly drop method is implemented in VBA, but it should work as you expect. Antoher thing is how the element was created and whether it's correct ... unfortunately MicroStation is tolerant to many errors when complex element is created.
Stephan L. said:and then I can post some code and data here
It would be great :-)
Have a nice weekend,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
thank you for your fast reply. As far as I know (I'm not at office right now) I don't use any kind of CopyContext there. It is just that I enumerate through all of the elements from the attachment and if I get a complex chain I drop it and enumerate through it's subelements. At that point the debugger already shows "wrong" values. Copying to another file is done later.
But you are right: I will try to simplify the code and the main file/attachment as much as possible while keeping the error and then I can post some code and data here.
Regards,Stephan
Hi Stepha,
it's hard to guess without code snippet and test dataset (probably a main file with one referece would be enough).
But ususally when the direction from reference to main model does not work, the question "How CopyContext is implemented?"
With regards,
Answer Verified By: Stephan L.