We are attempting to write an application that will builds a workset programmatically. We are attempting to automate the process of filling out custom workset properties from our Financial Management System via a COM started ORD session. Using property handlers we can get the property handler for the custom fields but cannot get or set the property. When trying to get the value of a custom field the following exception is thrown: "System.Runtime.InteropServices.COMException: 'Not Available'" is thrown. I can access the build-in properties without a problem.
using MicroStationDGN; using System; using System.Windows.Forms; namespace WorksetPropertySetter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MicroStationDGN.ApplicationObjectConnector oMSAppConnector = new MicroStationDGN.ApplicationObjectConnector(); MicroStationDGN.Application oMSApp = oMSAppConnector.Application; DesignFile dgn = oMSApp.OpenDesignFile(@"C:\Worksets\FDOT\0_WORKSET_TEMPLATE.dgnws"); PropertyHandler ph = oMSApp.CreatePropertyHandler(dgn); var props = ph.GetAccessStrings(); //look up build in properties if (ph.SelectByAccessString("WorkSetName")) { Object workSetName = ph.GetValue(); ph.setValue("WorksetName Value"); } if (ph.SelectByAccessString("WorkSpaceName")) { Object WorkSpace = ph.GetValue(); } //look up custom properties if (ph.SelectByAccessString("ContractNumber")) //succesful { Object workSetName = ph.GetValue(); //fails with exception } if (ph.SelectByAccessString("WorkSetDescription")) //succesful { Object workSetName = ph.GetValue(); //fails with exception } oMSApp.Quit(); oMSApp = null; oMSAppConnector = null; } } }
Hi Mike Robertson,
Artur Goldsweer and I can take a look into this further, though it would be helpful to know if using the .NET APIs is a better option for your solution, or if you need to use the older VBA/COM interface for some specific reasons.
Thank you,
Bob and Artur
We are trying to complete this task from an application external to MicroStation (thus COM). I've been able to access the properties from an internal addin but when I get to the point of trying to set the properties everything is readonly (plus the complication of trying to access an internal addin from an external application). I can send the skeleton project solution and workset template if needed.
Hi Mike,
If you like to provide your full simplified VBA/COM test case solution we can certainly test with that. However, like all VBA/COM solutions you should first validate the code running in-process as successful then migrate to out-of-process with a level of confidence. If the code fails for write in-process then it will do so out-of-process and provide less meaningful error codes/messages. Does your workset modify code work as an in-process VBA? If so, please do provide the simplified (skeleton) test case project for review.
My (preferred) suggestion would be to keep external VBA/COM code minimal and simple as possible (just execute keyins) and communicate with a custom in-process addin that provides your needed functionality. Where your custom addin would provide keyins w/arguments like: e.g.
Thank you,
Bob
Looking at DgnWorkSetInfo wsCopy = wsInfo.Clone(); I would assume that only clones the WorksetInfo on an existing file to another file (not cloning the complete workset itself).
Hi Mike,
I did a quick search for "Sheet Index Name" on the communities to see if others may have issues (known or otherwise) related to naming/renaming of sheet names. I found this post where one user appears to be doing a very similar process to what you describe, though possibly addressing things at a higher level to ensure more robust project handling than is currently offered. Can you take a look to see if the post may help provide you in addressing one or more issues you may be trying to resolve, or let me know if not helpful so we can dig into this deeper?
Thank you,
Bob
Hi Mike Robertson,
If you still prefer to use the VBA/COM PropertyHandler path, please feel free to provide a test app for us to troubleshoot the exact code conditions you are using.
If however, you have existing C# code to implement my prior recommendation and can provide key-ins to simplify the potential VBA/COM threshold issues, please feel free to go that route and update us with a reply that this is the path you prefer/choose to resolve the issue.
Lastly, here is a code snip that may be of help if you (or others) wish to Explore an existing .WorkSet file (.dgnws) and add a few properties to get started. We may add or replace this code snip since we have asked development to review and/or provide any better recommendations.
HTH,
Bob and Artur
Thanks for the code, I'd already started looking into an addin using C# and have it working. Guess I'll have to pass the data I need in the addin via some type of temporary file from the external application. Only thing I have left now is how can I set the "Sheet Index" name via code?
Here's my current workflow. Launch external application, copy our workset template folder, workset.cfg, workset.dgnws and rename accordingly. Open the just copied new dgnws file and populate our custom properties. All this is working correctly now. Only thing left is how do I change the "Sheet Index" name? (it shows the name of our workset template, not the new workset). When I create a new workset via the CONNECT GUI the Sheet Index name automatically is updated to match the new workset name.
Hi Mike,
I was unable to find any code snips related to WorkSetClonerOptions other than the implementation code I can provide. Being classified under Internal I am afraid this would be a use at your own risk/caution scenario since it: may change, be removed or completely replaced with new or improved APIs at some point.
Given that, I do see one WorkSpaceManager consumer of WorkSetClonerOptions: CreateWorkSet. CreateWorkSpace if used calls CreateWorkSet and cloneroptions initiated when providing input of a root folder/directory.
Bob
Roberts, thanks for the quick reply. Didn't see anything about Sheet Index Name on the post you mentioned. I have found something in the API that looks interesting. There is a method called Bentley.MstnPlatformNET.Internal.WorkSetClonerOptions, I haven't actually found a method to clone a workset yet (seems the ClonerOptions would be a parameter for a "Clone" method). I'm trying to figure out what the actual parameters are supposed to be used with the ClonerOptions.
Hi Mike,
DgnWorkSetInfo provides a Clone() method.
With the Internal prefix on WorkSetClonerOptions I am not sure how accessible/supportable it may be. I will see if I can find any sample code and if needed check with development on it.
Bob
Correct. It allows you to make local copy changes that you may wish to supersede a prior one.
So if your creating a workset from a stand alone app. Do you have workset specific seed dgn files? We have a couple dgn seed files we put into the workset. we also have a stand alone workset creation tool that does a lot of what you are doing. but how do you associate the seed dgn files to the workset?
i have not found a good solution to this. and the DGNWorkSetInfo class does not let you create one from scratch. you have to get it from a dgn file. but if i just created the workset i dont have a dgn that is associated to it yet.
So im missing how to just assign the workset to the dgn file. the only ways i have found have been a key in or save settings. but both of those ways require you to make the file the active file or load the view. which is overkill.
anyone have an solution to this.
since this post was about having a stand alone app create a workset i thought i would share how i got this to work.
first have a stand alone app that copy's the folder structure and workset cfg file
then that stand alone app will start a process of microstation but specify a MS_INITAPP to run. this post here has my code for that
https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/189649/c-com-connect-save-settings-for-file-opened-with-opendesignfileforprogram
its important to note the the MS_INITAPP there is a line of code that sets the active workset. this was the huge step that i needed to get everything to work. when you set the active workset it will cause microstation to create the dgnws file if it cant find one. you can specify the seed dgnws file with _USTN_WORKSETDGNWSTEMPLATE and then you can set the location the dgnws file for the workset is saved at with this variable _USTN_WORKSETDGNWS.
I know your question was trying to copy the dgnws file and fix the index name (dont know if you have got that working. if so please share that here) but with what i just described you wont have to worry about coping it. set up your template and let microstation copy it, then go in and make any property changes needed.
the last step that MS_INITAPP does is opens the seed files within the workset and associates the workset to them. again after letting microstation create the dgnws file i could just open it and get the WorkSetInfo from it then use that to set the worksetinfo for each of the seed files.
cant tell you how long it took me to get the point where i had a stand alone workset creation app do everything i needed it to do.
hopefully this helps you or anyone else having similar problems.