I have a situation where I am importing a model in code and it works exactly as I want. Except that the model being imported, is referencing a different model in the same file as the model.
The file I am importing it into, has an identically named model in it that I really want the imported model to reference, but what actually happens is that the model continues to reference the now external model.
One reason that it still finds the external file is this all has to function in a ProjectWise environment. So the original attachment looks like this: PW_WORKDIR:d0243249\SHA_border.dgn
According to VBA, my file name is a simple local path - in effect, the variable PW_WORKDIR has been expanded to a local path and then there is a subfolder equal to the "d" & the DMS number - in this case, d0257865. So it is not a simple task to rewrite the reference file, as I need the attachment to read like this PW_WORKDIR:d0257865\ followed by the active file name.
I know I can deconstruct and reconstruct this in code, but I discovered something that is so much simple, except it does not work in code.
I discovered that if I open the Reference Attachment dialog box and simply replace the current reference file path with a period and press return, MicroStation apparently checks the active file to see if the attached mode name matches as model name in the file and it it does, it rewrites the attachment as a self attachment, using the PW_WORKDIR:d0257865\ syntax.
This is a process that needs to go out agency wide for all active projects. So while I can provide the model import code, I wonder if the simplicity of typing a period in the file name field is the best solution or if there is some other way in code to tell MicroStation to check the file as a self attachment - in effect, some type of code that is a elegant and simple as the typing that period?
If there isn't, there should be.
Although I do not know when the origin and first version supporting using a period to self attach; it is a documented and supported (see last line, just above the Note section) workflow. Yes, this is a simple way to create and attach self-references.
Wonder of wonders!
Apparently, my code was flawed. Imagine that!
It is entirely acceptable to use the following code, assuming attachedFile is an valid attachment object and in the active file, there is a model named "Title Block".
attachedfile.Reattach ".", "Title Block"
I was not using Reattach in my original code which did not generate an error but failed.
According to the VBA Help, the model name is optional, but it threw an error when I used the "." without it.
Charles (Chuck) Rheault CADD Manager
MDOT State Highway Administration
Answer Verified By: caddcop
caddcop said:attachedfile.Reattach ".", "Title Block"
To help with maintenance, if you ever feel that way inclined, you might like to add something like this...
Dim modelName As String
modelName = "Title Block"
Const RefModelInSameFile As String = "."
attachedfile.Reattach RefModelInSameFile, modelName
Then package those statements in a subroutine named AttachRefFromSameDgnFile.
Regards, Jon Summers LA Solutions
The code in the post was simplified to share a functional example using minimal content.
I'm already using arguments and/or constants so maintenance and reuse are easier. This is not the first time management has added a new model to this particular file. It's just the first time we are trying to automate its implementation agency-wide.
We did something similar a while back when they had us release an update to our master title sheet. In that case, we had users open their title sheet and run a single macro. It attached the new version of the file to the existing file, placed a fence, deleted the fence contents, clipped the new reference file and finally merged it into master. The end result: an old note was removed and replaced by the new note.
The new note was created taking advantage of many of the new text capabilities of mixed fonts and underlines. The original note was created using techniques in use before that capability was available. The underlines were line elements drawn under specific words and words using different fonts were separate pieces of text placed to fall within gaps left in the rest of the note. After I spent far too much time trying to edit the existing note, getting more and more frustrated in the process, I thought about how many projects we had in the pipeline and tried to imagine how many hours would be wasted by all the persons trying to do the same thing.
I made an executive decision to create a new note using current text capabilities and to also create and a macro to make adding it to any existing title sheets a simple, one step process.
We also have an Alert Message tool that allowed us to push out with a message containing links that would run the tool or open a PDF explaining what was needed and what would happen when the macro was run. We got zero support calls! I'm hoping the same will happen with this process.