Is there any way to select an element using the element selection tool and check its file name using vba code?
An element lives in a model. A model lives in a DGN file.
If the element is selected, then it's in a selection set. Look at the Select Set Example in VBA Help for some code.
An element has a ModelReference property. A ModelReference has a DesignFile property. A DesignFile has a Path property. So, once you've found your element, you can get its file name like this:
Dim oElement As Element ... get element from selection set Dim fileName As String fileName = oElement.ModelReference.DesignFile.Path Debug.Print "Element file: '" & fileName & "'"
Regards, Jon Summers LA Solutions
How would I activate the element selection tool? I know how to use the key within vba but I was looking for a more comprehensive method to select an element using the element selection tool? Does that make sense? This was the main issue I was having?
samson1218 said:How would I activate the element selection tool?
Queue the command CHOOSE ELEMENT or call StartDefaultCommand
samson1218 said:I was looking for a more comprehensive method to select an element
Investigate the ILocateCommandEvents interface. It lets you fine-tune the selection process.
Thanks soooooo much Jon!
Jon, you are gonna hate me. A little background info. I tought myself vb a few years back and have gotten pretty good at what I know but I am struggling with objects methods, elements in microstation vba. I keep getting this error message that says "object variable or with block not set". Not sure what is going on. I have an application that I wrote a few years back that manages all of our projects, workspaces, clients, etc using methods that I have learned along the way. I assume old school from vb forums.Anyway because of this application I have been able to get alot of user information based on files they have accessed, etc etc. I also created an vba that kind of streamlines the reference exchange using 2 icons. An exchange icon is displayed whenever the user has yet to select the exchange icon and went into another file. After the user exchanges into another file an additional icon is displayed to return to the previous file. The user can exchange forward as many times and he/she wants and can return all the way back to the original file before the return icon goes away. Our users like it becaue of the quick icon back and forth between refernce files. anyway my problem is that we are starting to now use models more and because of that when the user exchanges into a model he or she hits return and actually goes back to the last file he/she was in because I am keeping track of the last file and not the last model/file. I was hoping to prevent the user from exchanging into a model by checking its info somehow. Thats the reason for all of this. My the better answer would be if there is a way to not only get the path but the path of the file including the model as well. Is this possible? I am using Application.ActiveDesignFile.FullName to get the path. Is there a way to also get the model as well?
Thanks a bunch!
samson1218 said:Jon, you are gonna hate me
This is a public Forum, not a personal messaging service. I don't suppose anyone, least of all me, hates you for sharing a problem.
samson1218 said:The user can exchange forward as many times and he/she wants and can return all the way back to the original file
Have you investigated Project Explorer, which is part of MicroStation?
samson1218 said:The better answer would be if there is a way to get the path of the file including the model as well
Public Function CreateFullModelPath (ByVal oModel As ModelReference) As String Dim fileName As String Dim modelName As String fileName = oModel.DesignFile.Path modelName = oModel.Name CreateFullModelPath = fileName & ":" & modelName End Function
I actually have. I have found that the users where I work like to be able to just kind point and click to have quck access back and forth when dealing with files that have multiple reference. For example. A user starts out in a plan sheet. Select the reference exchange icon and click the appropriate file to move text out of the way. After the user gets in that file he/she realizes that the text was there because another file that it is reference to had something in its way. The user then goes into that file. After he/she adjusts that file then he/she gos directly back to the file to fix the original problem. The user may do this several times and with couple quick clicks of the icon and they are able to jump forward back or forward forward back back or any combination and still end up in the original plan sheet at the end. Or they can always just open another file the traditional way and it resets the whole process. I have introduced other methods but they all refuse to work any other way. It worked great untill models were introduced. Thanks again Jon! I think the code you sent should do the tricck.