OpenDesignFileForProgram and Views

Hi,

I do this in V8i:

Set oDesign = OpenDesignFileForProgram(DesignPath_other_than_ActiveDesignFile, readOnly)
set oModel = oDesign.Views(1).Model

Then, oModel is the active Model of the ACTIVE DesignFile rather than a Model of the opened DesignFile! Obviously already the Views collection is related to the ACTIVE DesignFile.

So, I wonder what I'm doing or understanding wrong. My intend is to determine which model would be active if a certain designfile would be opened as the active file.

Robert

 

Parents
  • Hi,

    I was afraid to get this answer. But now I'm aware of these issues.

    Many thanks.

    Robert

  • Active Model & Design File

    The normal, 'user', view presented by MicroStation uses the active model of the active design file. In VBA terms, you have an ActiveModelReference and an ActiveDesignFile object. You can make any model in the ActiveDesignFile the active model. You can open a new design file an make it active using the OpenDesignFile method.

    Working Models & Design Files

    With VBA you can do something that a normal user cannot do: you can open a working model in a working design file. The term working describes a mode that is available to you as a programmer and not to a normal user.

    Use the OpenDesignFileForProgram method to open a DGN file for that type of programmer access. You can do things with the models in that DGN file, but they are working models and can never be active models. As Gerald notes, those working models cannot be seen in a MicroStation view.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Hi Bert,

    Here's a thread to look at:

    communities.bentley.com/.../165344.aspx

    The bottom line, use dgnToOpen.DefaultModelReference.Levels and then dgnToOpen.Save when you're done making changes.  

    --Robert

  • Unknown said:
    When you open a dgn with OpenDesignFileForProgram, what can and can't you do?

    OpenDesignFile

    With VBA you can operate on the ActiveModelReference in the ActiveDesignFile. Your VBA code can do whatever a MicroStation user can do, but quicker. If you're writing VBA code in another application such as Excel, which is what you appear to be doing, then use those Active objects. Your code opens a CAD file using OpenDesignFile, operates on its contents, then closes the file.

    OpenDesignFileForProgram

    OpenDesignFileForProgram is used when you want to do something behind-the-scenes while a user is in charge of MicroStation.

    There are two files open …

    1. the ActiveDesignFile that the user sees
    2. the file that your code has opened using OpenDesignFileForProgram

    You might want to save some elements selected by a user to a different file, for example. You would copy elements from the ActiveModel to another model provided by OpenDesignFileForProgram, then save that file without affecting what the user is doing.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • OK, I have tried referencing the levels using this dgnToOpen.DefaultModelReference.Levels and i can get the count, but when I iterate the levels and try to do something, I get a bad ModelRef error

    dim lev as Level

    for each lev in dgnToOpen.DefaultModelReference.Levels

     lev.IsActive = false   ''error occurs here

    next

    I am running this code from inside Microstaiton, not another program.

    Something I did just think of, I am using version 8i for the code, but the files are version 7, is that the issue?

  • Unknown said:
    I am using version 8i for the code, but the files are version 7, is that the issue?

    Could be. Why not test your code on a real V8 format DGN file?

    A V7 file has a fixed no. of levels. Level IDs are numeric. V8 translates V7 levels into the first 63 levels of your active model's level table. Depending on your MicroStation settings, they may be named Level 1 to Level 63.

    When you open a DGN file that is not V8 format, you have the option of converting it to V8 format (thus obtaining the benefit of V8 features) or operating in compatibility mode, when V8 features are not available. Probably, since V7 levels are always active, you can't make a V7 level inactive in V7 compatibility mode.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • I have converted some files to v8 and still get the same error, I started looking at the properties of the model object that is returned from - theDGN.DefaultModelReference  - and I noticed that the IsActive property returns false is that normal?? It is a read-only so how do you set it to true? Or is that something you have to do through Microstation itself?

  • Hi,

    The model that "is active" is the file that you have really open-not the one that you have "open for program".  Perhaps that's where the error is occurring.  The "is active" attribute can not be set because there is no way you can have anything active in a "non active" file that is "open for program" only.  

    So the next question is "Why do what to the IsActive state of the level?"  Remember that this file is open for the VBA program only.  Anything you do to the file, you have to do through VBA, not through Microstation (via key-ins, etc.).

    --Robert

  • Ok, so then this taks me back to my question i my first posted on this subject

    "So when you open a dgn with OpenDesignFileForProgram, what can and can't you do"

    Can you effect level visibility? or can you delete levels? my guess is that no one knows, because there is no documentation addressing it.

  • Robert,

    Because levels are not just defined in one file you would not get a complete picture unless you load the file and workspace to get the dgnlibraries added in.  In the open for program mode you can query the contents of the file things like the elements and get the information directly on them.  What are you looking to get out of this?  It would help me to understand the goal and I will be glad to offer up direction to get there.

    marka

  • To give a broad overview - I am copying a set a dgn files to a new location and renaming the files, that's easy, then in each dgn turning on certain levels and off all the others and possibly deleting levels. Then manipulating the values of some text elements that are part of cells, ie. the title block portion of the drawing. I have done all of this from within an open dgn.

    Ideally I would like to accomplish this without opening each design file, but the more I learn, I guess I am going to have to open each file.

    Just to clarify, the Open for Program Mode is just for querying contents of teh dgn, not really for manipulating the contents of the dgn?

  • Hi,

    You can manipulate both the level structure and the elements in a OpenDesignFileForProgram.  I think was Mark is refering to is that you could have levels in libraries, which you would not have access to.  I have a routine that I use on a regular basis that deletes levels in a OpenForProgram file.  

    What you can not do is anything related to the views, because you have no views open.  I think you could adjust the global display and the global freeze of levels, but you would not be able to adjust the level-view display.

    As you mentioned, if you need to, VBA can have Microstation open up a file, do a function, then open the next file, do the function again, etc. and to be nice to the user, open the original file again and then stop.

    --Robert

Reply
  • Hi,

    You can manipulate both the level structure and the elements in a OpenDesignFileForProgram.  I think was Mark is refering to is that you could have levels in libraries, which you would not have access to.  I have a routine that I use on a regular basis that deletes levels in a OpenForProgram file.  

    What you can not do is anything related to the views, because you have no views open.  I think you could adjust the global display and the global freeze of levels, but you would not be able to adjust the level-view display.

    As you mentioned, if you need to, VBA can have Microstation open up a file, do a function, then open the next file, do the function again, etc. and to be nice to the user, open the original file again and then stop.

    --Robert

Children
No Data