[CONNECT C# COM] Set Workset Custom Properties


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;
        }
    }
}

Parents
  • 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.

Reply
  • 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.

Children
No Data