Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all 7260 articles
Browse latest View live

[CONNECT C#] Placing cells

$
0
0

I am trying to Place a cell which is defined in a cell library.

 

In V8i this was easily accomplished, assuming the cell is in an attached cell library.

 

cell = _ComApp.CreateCellElement3(cellName, ref origin, true);

cell.ScaleUniform(ref origin, scaleFactor);

cell.RotateAboutZ(ref origin, rotation));

 

Using the CONNECT Api this seems to be less obvious.

 

I *believe* that I need to create a CellHeaderElement using the following:

 

CellHeaderElement cell = new CellHeaderElement(activeDgnModel, cellName, origin, DMatrix3d.Zero, cellElements);

 

The process seems to be that you create the Header and then add child elements to the cellElements parameter above.

My problem is, where to get these elements from. The obvious answer is from the library, and this is where I have ground to a halt.

 

Here is where I have got to so far…

 

     public static void PlaceCellKeyin(string cellName) {

 

         CellLibraryCollection cellLibraryCollection = new CellLibraryCollection(CellLibraryOptions.DefaultAll);

 

         foreach(CellLibraryInfo cellLibraryInfo in cellLibraryCollection) {

 

           if(cellLibraryInfo.Name == cellName) {

               ModelIndexCollection modelIndexCollection = cellLibraryInfo.File.GetModelIndexCollection();

 

               foreach (ModelIndex modelIndex in modelIndexCollection)

                 if (modelIndex.CellPlacementOptions == CellPlacementOptions.CanBePlacedAsCell && modelIndex.Name == cellName) {

                     //Now what?

                 }

}

}

 

The Cell Library file appears as a Dgn with a Model for each cell. I can iterate through the models using the ModelIndexCollection. What I cannot do is get at the cell model's graphics.

 

I am sure there must be a more straightforward way to do this. Please help.


RE: Units not correct in Microstation plug-in

$
0
0

Hi Dave,

[quote user="Daverode"]Anyone have any idea what I'm doing wrong?[/quote]

In my opinion there is nothing wrong with your code and because master units are used in VBA COM API, it should work as you described.

Some questions to better understand your configuration and environment and also ideas what you can try:

  • Is MicroStation only used or is there any other application active?
  • How your application is created: Is it exe started outside MicroStation accessing to MicroStation using interop or it's add-in (derived from addin class)?
  • Can you try the same code from VBA?
  • How do you check the coordinates: In GUI or using e.g. "analyze element" key-in?
  • Is this problem file-dependent? Can you try another one, can you try metric?
  • Is it possible to create working project (not only code snippet) and to share it?

[quote user="Daverode"]Here is a sample of code[/quote]

A few notes about the code, a bit more in a subjective way "how the code is written":

  • In my opinion to declare all variables at the beginning is wrong style. It's not required by the language itself and often recommended style is to declare a variable when it's used, not earlier.
  • Don't set X,Y,Z separately, use e.g. pt3dOrigin = ustnApp.Point3dFromXYZ(71, 44, 0);
  • Don't use .Redraw, it's not required. MicroStation takes care about element redraw when an element is added to active model automatically.

With regards,

  Jan

RE: VB.Net: Capture native form open or close event via Microstation Add-in

$
0
0

Hi Dave,

[quote user="Daverode"] I was interested in getting some of the promis.e form events[/quote]

Tools to monitor or access promis.e events have to be published by promis.e API itself. From this perspective, MicroStation API allows to access "basic platform" features and events.

In my opinion the idea to hook a form events is not good and leads to fragile code. If an application is well and properly developed, its GUI is only view to business (internal) data. There should be a way how to monitor data events, not form events.

[quote user="Daverode"]so that I could monitor what symbols are being inserted[/quote]

I don't know how promis.e is integrated into MicroStation and how it works, so I am not sure what does it mean "to be inserted". But if you want to monitor how active model is modified, you can use ElementChanged Event. See VBA help for more details. But this feature is still limited and the only way how to get maximum "monitoring functionality" is to use native C/C++ code.

With regards,

  Jan

RE: VB.Net: Capture native form open or close event via Microstation Add-in

$
0
0
Jan,
Thanks for the response. The ElementChangedEvent sounds like it might be the way to go. Looks like I'll have to do a little more research.
Regards
Dave

VB.Net: Capture native form open or close event via Microstation Add-in

$
0
0

Hello,

I've written an Addin (or I should say using modified Addin Jan Slegr had written...very nice, by the way) and I'm wondering if there is some way I can capture load and unload events of native forms or forms from other Addins? I wrote a plug in for Promis.e and was able to add form opening and closing event using the eventcenter in their ECT.ECAD.API dll and I was wondering if there was some equivalent in the Bentley.MicroStation.AddIn Namespace?

Thanks Dave

RE: Units not correct in Microstation plug-in

$
0
0
Jan,
Thanks again for the information. I'm not sure where I got into the habit of declaring variables at beginning. I'll look into some of the questioned you had for me, but in the meantime I notice that in my "Locks" toolbox the "unit distance" is 3.937 and if I change it to 1 manually it solves the problem.
Thanks
Dave

Units not correct in Microstation plug-in

$
0
0

Hey Everyone,

I'm developing a plug-in for Microstation that inserts several text elements in the Active Model. It seems that everything I insert, the units (such as Point3dOrigin(71,44,0))

end up being multiplied by 39.73 even though the Master and Subunits in the design file settings are both set to "inch". Anyone have any idea what I'm doing wrong?

Here is a sample of code

        Dim rotmatrix As B_Interop_UstnDGN.Matrix3d
        Dim pt3dOffSet As B_Interop_UstnDGN.Point3d
        Dim pt3dOrigin As B_Interop_UstnDGN.Point3d
        Dim el As B_Interop_UstnDGN.TextElement

        rotmatrix = ActiveUstn.Matrix3dIdentity

        pt3dOrigin.X = 71
        pt3dOrigin.Y = 44
        pt3dOrigin.Z = 0

        pt3dOffSet.X = 0
        pt3dOffSet.Y = -0.5
        pt3dOffSet.Z = 0

        'start in upper left corner
        For Each row_Tags As DataRow In datatbl_Tags.Rows

            el = ActiveUstn.CreateTextElement1(Nothing, row_Tags.Item("name").ToString, pt3dOrigin, rotmatrix)

            el.Redraw()

            ActiveUstn.ActiveModelReference.AddElement(el)

            pt3dOrigin = ActiveUstn.Point3dAdd(pt3dOrigin, pt3dOffSet)

        Next

Thanks

Dave

RE: Abstract Vertices Coordinates

$
0
0

Hi John,

a few comments:

  • Please don't post the same question to more (sub) forums! It causes confusions only. If a question is accidentally created in a wrong forum, you can ask to move it to another one.
  • Read and follow Programming Forum best practices and use correct subject format etc.
  • Accordingly to the best practices, share important information, especially what MicroStation version (build number) do you use.
  • Use Syntaxhighlighter tool (yellow pencil icon) and set a correct language when posting any code snippet.

[quote user="-"]how to extract all its vertices coordinates?[/quote]

Dim vertices() As Point3d
vertices = oElement.AsVertexList.GetVertices()

The code is correct, mostly. In my opinion it's a bad style to cast general Element object to a specific one using "As*". If working with line string only, more robust code would be similar to this:

Dim el As Element
set el = ... // obtain an element

If (el.IsLineElement) Then
    Dim line As LineElement
    Set line = el.AsLineElement
    
    Dim vertices() As Point3d
    vertices = line.GetVertices()
End If

It can be extended to a general form whether not only line string should be used as an input element:

If (el.IsVertexList) Then
    Dim vertexListElement As VertexList
    Set vertexListElement = el.AsVertexList
    
    Dim vertices() As Point3d
    vertices = vertexListElement.GetVertices()
End If

[quote user="-"]But all Micro Station VBA help examples are not clear at all[/quote]

MicroStation VBA examples demonstrate how to use a specific class or method, not where to use them, because a decision about VBA application architecture is a responsibility of developer.

[quote user="-"]which code to write in the module and which code to write in the class module[/quote]

With all respect, it's not the question related to MicroStation VBA API, because API can be used both in normal VBA code (from module) or in class definition code. It's a developer decision how the code will be structured and if classed will be used or not. There are several situations where you have to create a class to use MicroStation VBA functionality (IPrimitiveCommandEvents and ILocateCommandEvents objects), but the most of MicroStation VBA macro can be written as normal module code.

I recommend to check general VBA tutorials like www.cpearson.com and also use Google to find articles about the difference between normal and class VBA modules.

With regards,

 Jan


RE: Abstract Vertices Coordinates

$
0
0
One more note: See and study also C:\ProgramData\Bentley\MicroStation V8i (SELECTseries)\WorkSpace\System\vba\examples folder, where examples delivered with MicroStation installation are installed. The examples domenstrate how MicroStation VBA macro can be written.

Abstract Vertices Coordinates

$
0
0

Just beginning working in Micro Station VBA

We begin transforming our Micro Station Basic Macros into VBA.

We have a three points Line string.

Is there a very simple example in VBA on how to extract all its vertices coordinates?

Apparently with

Dim vertices() As Point3d

vertices = oElement.AsVertexList.GetVertices)

But all Micro Station VBA help examples are not clear at all, on which code to write in the module and which code to write in the class module.

Thank you very much in advance

John Kapopoulos

RE: [CONNECT C#] Attach raster

$
0
0

Hi Francesc,

I agree with Maury to use the key-in is probably the simplest way now.

Based on DgnPlatformNet documentation it seems that the right way is to use RasterAttachmentEdit handler, but I was not able to find a way how to access geo reference data, so the raster is attached to 0,0 in a minimum size.

An alternative is to "go back" and to use Interop assembly and to use VBA RasterManager object.

With regards,

 Jan

RE: [CONNECT C#] Placing cells

$
0
0

Hi Olcay,

[quote user="Olcay EBCIN"]isn't this a bit confusing algorithm to attach a cell from library? [/quote]

Yes, it is :-(

[quote user="Olcay EBCIN"]May be something changed and I hope there is a quick way of attaching cell now. is it?[/quote]

As far as I know nothing has changed so far. Maybe in CONNECT Edition Update 4?

With regards,

  Jan

RE: [CONNECT C#] Attach raster

$
0
0
Many thanks, Maury and Jan

I will use Interop assembly. It's a pity can't do it directly with NET API.

RE: [CONNECT C#] Attach raster

$
0
0

[quote user="Francesc Calaf"]It's a pity can't do it directly with NET API.[/quote]

Maybe there is a way simpler than discussed in this thread, but nobody from Bentley has confirmed the situation. Right now it seems there is a gap between DgnModel, that can be retrieved from attached cell library and a proper element handler.

Regards,

  Jan

RE: THIS CODE DON'T WORK WELL CAN ANYONE HELP ME "V8i" "VBA"

$
0
0

Hi DMA,

I don't see any simple way how to answer your question, because it seems you made such task nearly impossible and very time consuming.

  • It's not clear what the description does.
  • It's not clear what problems do you encounter. A specification "some errors appear" is not sufficient.
  • It depends on external data (design file, point cloud...) we don't have, so the code is not testable.
  • The code is badly written (in my opinion very bad style, eg. 100 line with - end with block?, but it's always a matter of subjective opinion), so it's quite hard to understand how it's structured and what it should do.
  • The code is very long to be posted as a code, why not post it as runnable mvba?

To ensure it will be easier to analyse the code, can you post it as a testable (runnable) mvba file including a data?

I also recommend to read and follow MicroStation Programming Forum best practices and more general Communities Forums best practices. Also it's often accepted rule on many webs (and it comes probably from good style e-mail communication) that to use ALL CAPS SUBJECTS is treated as a bit aggressive style or spam.

To find where the problem is, because you are probably the only who understand your code, I recommend to split it into short functions or subs (about 20 - 30 lines at max) with clearly defined functionality. It's easy (or at least easier) to test such short functional blocks and to hunt the bug quickly.

With regards,

 Jan


RE: THIS CODE DON'T WORK WELL CAN ANYONE HELP ME "V8i" "VBA"

$
0
0

thanks for your fast reply

the main function for this macro is for highlighting the clashes location by using the exported XLS file from navigator

the main problem face me is the out put for these macro is not accurate
the clouds made is very far even the coordinates entered is right

*i upload the macro and the dgn file and xls as sample


thanks

RE: this code don't work well can anyone help me "v8i" "vba"

$
0
0

Please follow the MicroStation Programming forum best practices.

Identify Your Platform

Please identify the version of MicroStation, or other product such as PowerDraft, that you are using. What is the 8-digit version number (e.g. 10.xx.yy.zz) of MicroStation?

If you're using MicroStation in a ProjectWise (PW) managed environment, let us know that too.

Code Syntax Highlighting

When you post code, use the Forum advanced editor's syntax highlighting tool. That's the icon that resembles a pencil:  Syntax Highlighter

this code don't work well can anyone help me "v8i" "vba"

$
0
0

this macro make highlite on the clashes point that i already entered in excel format for this macro below

but i face some problems

1- the cloud on clash point are very far from the model

2-there some errors appear in run time of this macro

How to Automatically Label Many Elements at Once using Property Fields

$
0
0

I have many line strings that I wish to label with a property field using the annotate - place text along command. I can only label one string at a time. Is there a way to select all strings and automatically label them all at once?

RE: Run Microstation macro from Excel

$
0
0

Thank you very much sir. 

After few modification in Your macro finally  i am able to get all text to excel. i will just now add few lines into it so that macro can do this same process for all DGN files kept at same folder.

Thanks again for help. I am also here attaching final macro as text file to help other people searching for the same sollution in future..

(Please visit the site to view this file)

Viewing all 7260 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>