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

RE: How to activate a model in C# V8i

$
0
0

Another problem with my posted code is that it only iterates through loaded models.  A workaround is to write a quick VBA to activate each model in the design file and then to run the code.  

A much better solution is posted here.

Here is the new code.  This works much better.  It requires CreateLib.lib, mdlbltin.lib, BentleyDGN.lib to be statically linked.  

#using <ustation.dll>
#using <Bentley.General.1.0.dll>
#using <bentley.interop.microstationdgn.dll>
#using <bentley.microstation.dll>
#using <bentley.microstation.interfaces.1.0.dll>
#include  "ModelIterator.h"
#include "DgnHeaders.h"
using namespace System;
using namespace System::Windows::Forms;
using namespace ExpandPrintBorder;
ref class MyAddin sealed : public Bentley::MicroStation::AddIn
{
public:
	/*MyAddin(System::IntPtr mdlDesc)
		: base(mdlDesc)
		{
		}*/
	MyAddin(System::IntPtr mdlDesc) : Bentley::MicroStation::AddIn(mdlDesc){

	}
public:
	int Run(array<System::String^>^ commandLine) override{
		MessageBox::Show("C++/CLI application started");
		Iterate();
		return 0;
	};
	void Iterate(){
		DgnIndexIteratorP   iterator = mdlModelIterator_create(mdlModelRef_getDgnFile(ACTIVEMODEL));
		DgnIndexItemP       item = mdlModelIterator_getFirst(iterator);
		MSWChar             modelName[MAX_MODEL_NAME_LENGTH];
		while (item)
		{
			mdlModelItem_getName(item, modelName, MAX_MODEL_NAME_LENGTH);
			models_activate(modelName);

			CSharpAddin^ cs = gcnew CSharpAddin();
			cs->Main();

			item = mdlModelIterator_getNext(iterator);
		}
		mdlModelIterator_free(iterator);
		//  Active a model to enable a user to work with it
	}
	BoolInt             models_activate
		(
		MSWChar const*      modelName      //   =>	Activate this model
		)
	{
		BoolInt         activated = FALSE;
		MSWChar         activeName[MAX_MODEL_NAME_LENGTH];
		mdlModelRef_getModelName(ACTIVEMODEL, activeName);
		DgnFileObjP     dgnFileObj = mdlModelRef_getDgnFile(ACTIVEMODEL);
		DgnModelRefP    modelRef = NULL;
		if (SUCCESS == mdlModelRef_createWorkingByName(&modelRef, dgnFileObj, modelName, TRUE, FALSE)&&
			SUCCESS == mdlModelRef_activateAndDisplay(modelRef))
		{
			activated = models_areSame(modelRef, ACTIVEMODEL);
		}
		mdlModelRef_freeWorking(modelRef);
		return activated;
	}
	BoolInt             models_areSame
		(
		DgnModelRefP        modelRef1,
		DgnModelRefP        modelRef2
		)
	{
		return mdlModelRef_getCache(modelRef1) == mdlModelRef_getCache(modelRef2);
	}
};

That code will successfully activate each model in the active design file.  


RE: How to activate a model in C# V8i

$
0
0

Hi,

[quote user="HDR_Coder"]Another problem with my posted code is that it only iterates through loaded models.[/quote]

What do you mean by "only loaded models"?

With regards,

  Jan

RE: How to activate a model in C# V8i

$
0
0

mdlDgnFileObj_getModelRefList description says, "

      Create a DgnModelRefList containing an entry for each of the loaded models in the specified design file. Note, any DgnModelRefList created with this function must be freed by calling

mdlModelRefList_free."

One needs to activate each model beforehand in order for my previously posted code to iterate through each model.  

[CONNECT .NET SDK] All SDK examples do not work right away

$
0
0

When recently trying to test the .NET examples of the latest Connect Update4 SDK, i noticed several problems with them, which i would like to describe/report here.


1. All examples have .NET 4 as Target Framework set. Not 4.5.2. as necessary since Update4
So they don't compile and throw lots of missing namespace error messages as reported here
https://communities.bentley.com/products/programming/microstation_programming/f/343173/p/134163/408497#408497


2. When trying to Change the examples to .NET 4.5.2., Visual Studio throws an error message


also reported by Jon Summers here
https://communities.bentley.com/products/programming/microstation_programming/f/343173/t/131004

Only by deleting the bugged .csproj and creating a complete new project with VS, then including the .cs resources again, i was able to get them compile with .NET 4.5.2. as target framework.

It seems Bentley wrote (manually?) many variables into the .csproj files (since at least my Visual Studio 2013 is not showing the variables), while these variables are not set (probably only in the Bentley dev Environment set).

<OutputPath>$(MS)mdlapps\</OutputPath>

I don't have an MS variable.

Same as $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) which are used in the project files.

3. The projects contain useless files.


They contain batch and make files. Probably for those who want to compile in a DOS console without any debugger, adding only an inconvenient additional step instead of compiling directly from VS.
Since usually programming, compiling and debugging is done in Visual Studio, there is no need for batch files to be included in the projects, which VS isn't using anyway.

As the included readme states, i would also have to start first MicroStationDeveloperShell.bat, which is not working right away and needs several parameters set that are nowhere explained (see next point).
Then i would have to start Visual Studio out of the console to have the variables also available in VS. (People usually use shortcuts on a desktop or a file manager to start stuff and only rarely use a console nowadays ;-) )

I think a developement environment in a console and based on batch files is not up to date anymore.

4. MicroStationDeveloperShell.bat is not working right away
When starting this batch, it throws a "Path not found" error, but nowhere states which path and why?
Only by opening the batch file, you notice that it needs 2 (optional 3) parameter to work. A very inconvenient way if someone just wants to compile and test one of the examples right away.

The Batch could at least
-have the default MicroStation and SDK installation paths set (if no parameter is given)
-show an error message with a little explanation which path it needs
-include a pause command at the end, since the consoles of a started batch file closes automatically and you can't see any thrown error when first starting the batch

Conclusion:

I think VS example projects should not rely on some batch based console environment.

VS example projects should compile right away, not having me spend hours to find the errors, missing variables, wrong target framework and trying to fix them.

RE: [CONNECT C++] Dialog Layout Manager

$
0
0
There is more descriptive documentation and examples under the "Migrating to Layout Manager" section of MicroStationAPI.chm

[CONNECT C++] Dialog Layout Manager

$
0
0

Some example MicroStationAPI apps have dialog definitions with auto layout management.  For example...

CmdItemListRsc          ItemList_ECSChemaExample =
    {{
    BEGIN_VSTACK_LAYOUT(VSTACKLAYOUTID_ToolSettingsMain,"")
        BEGIN_HSTACK_LAYOUT(0, "")
            STRETCH(1)
            BEGIN_VSTACK_LAYOUT(0, "")
                BEGIN_GRID_LAYOUT(GRIDLAYOUTID_3ColumnsInner, "marginBottom='10'")
                    GRID_ROW(0, "")
                        LAYOUT_LABEL_NEXT_RIGHT(8*XC, "")
                        {{AUTO_XY, 51*XC, 0},     Text,           TEXTID_Processfile,        ON, 0, "", ""},
                        {AUTO_XYWH,                         IconCmdX,       ICONCMDID_BrowseFile,      ON, 0, "", ""},
                    END_ROW
                END_LAYOUT
                {{0, 0, 0, 50*YC},  Tree,        TREEID_ContentList,                  ON, 0, "", ""},
            END_LAYOUT
            STRETCH(1)
        END_LAYOUT

        STRETCH(1)
    END_LAYOUT
    }};

Is there a guide to help us through that maze of macros?

RE: [CONNECT MicroStationAPI help] Typos in 'Best Practices Working With Schemas'

$
0
0
Defect 691335 has been filed to address this issue.

Thank you,
Bob

[CONNECT MicroStationAPI help] Typos in 'Best Practices Working With Schemas'

$
0
0

MicroStationAPI help for CONNECT has a section Best Practices Working With Schemas.  It includes these paragraphs having spelling mistakes...

Units should be assigned to all properties that represent a physical quantity (e.g., length, area, volume, time, etc.). By assigning units, the meaning of these values are well understood and can be interrupted in only one way. This is particularly critical when properties are used in calculations. They are also required if unit conversions need to be done.

That should be interpreted, not interrupted.

Avoid assigning class, property and relationship names that exceed 64 characters in length if possible. If unavoidable, define and keep their display labels to 64 or less characters. Microsoft Access limits the length of field names to 64 characters. If the data in an i-model is exported to Access using the i-model ODBC driver or some other means, the field names will be truncated if larger than 64 characters. Though the ODBC driver will ensure the trunicated names are unique, the abbrevated names may be difficult to work with.

That should be truncated, not trunicated, and abbreviated, not abbrevated.

Calculated properties provide a concise and flexible method of concatenating values or performing math calculations involving one or more properties. These are particularly useful for creating busniess key and instance labels.

That should be business, not busniess.


RE: [V8i VBA] Detecting if coordinate is above or below target element

$
0
0
Hi Barry,

I solve this with a 2 dimensional approach in my programs, so I am curious how to do it the way Jon suggests. I've been studying that link about the cross product and I don't fully understand it. Would you be so kind as to post the code snippet if you get it working.

Thanks,
Minion

[V8i VBA] Detecting if coordinate is above or below target element

$
0
0

As a followup to one of my previous threads here, the image below is is my target element (its 22miles long) with the placed cells also shown (very hard to see at this scale)

This is a close-up where the cells are visible and though difficult tell, they are placed perpendicular to the chainage element (turquoise):

I now have a requirement to add text (possibly a text node) near to each cell instance which where each string would be unique like below:

I have 2 issues (a far as I can tell),

  1. I do not know how I can detect if a coordinate is south of the chainage line at its projected intersection perpendicular to the chainage element.
  2. I can't store the text in a cell (even though it does make the most sense) because any cells inserted south of the chainage element would have the text rotated 180° whereas I need to text to be readable in the same direction as above.

Any suggestions how I can achieve the above?

RE: [VBA] Activate a dgnlib textstyle

$
0
0

Modify the function in the article I cited.  The existing MDL function gets a C pointer to the text style.  The following MDL function adds a new text style to the active DGN file...

Declare Function mdlTextStyle_addToFile Lib "stdmdlbltin.dll" ( _
  ByRef pNewTableEntryId As Long , _
  ByVal pStyle As Long , _
  ByVal pStyleName As Long , _
  ByVal bLockEntry As Long ) As Long 

The second argument, pStyle, is the pointer styleAddress you got from the first MDL function.  Here's what the complete function might look like (untested code)...

Public Function AddTextStyle(ByVal name As String, ByVal searchLibs As Boolean) As Boolean
AddTextStyle = False Dim styleAddress As Long Dim styleIdAddress As Long styleIdAddress = -1 If (SUCCESS = mdlTextStyle_getByName( _ styleAddress, styleIdAddress, StrPtr(name), _ ActiveModelReference.MdlModelRefP, searchLibs)) Then Dim newId As Long Const LockEntry As Long = 0 ' No idea what that does! AddTextStyle = (SUCCESS = mdlTextStyle_addToFile ( _ newId, styleAddress, name, LockEntry) End Function

RE: Custom line-style text always horizontal, regardless of line orientation.

$
0
0

[quote user="theGreg"]I have a peculiar problem with my custom line-styles[/quote]

Is this a programming question?  You might be better off posting to the MicroStation Forum.

Custom line-style text always horizontal, regardless of line orientation.

$
0
0

Good day all, 

I have a peculiar problem with my custom line-styles. I do a lot of electrical reticulation work, and with that we have custom line styles we use for representing different cables in our drawings. 

1. 35-B conductor.  This is a cable showing the phase of the line, it is B, which can be any one of R,W or B. 

It clearly shows the custom line has the text aligned to the length of the line. 

2. The issue i have is with line-style number 35-W.

As the image below will show you, the text is always horizontal, unlike the picture above. 

Is there a way i can fix this. 

Thank you.  I have attached the .rsc resource file here.[View:/cfs-file/__key/communityserver-discussions-components-files/343173/ElecLines.rsc:0:0]

RE: [VBA] Activate a dgnlib textstyle

$
0
0

[quote user="Jon Summers"]

      ConstLockEntry                     AsLong= 0  ' No idea what that does!
      AddTextStyle = (SUCCESS = mdlTextStyle_addToFile ( _
        newId, styleAddress, name, LockEntry)

[/quote]

FYI.  This was used in MicroStation V8 to get/set the locked flag in the element header.

[Connect - CPP] Problems with pattern angle

$
0
0

Hi all

I got some problems with the pattern angle in Connect. The angle of the pattern is relative to the angle between the first two points in the shape. I expected it to be relative to a horizontal line. To illustrate my problem I've made a small test program:

DPoint3d pts[5];
	pts[0].x = pts[0].y = 0;
	pts[1].x = 10000;
	pts[1].y = 3000;
	pts[2].x = 3000;
	pts[2].y = 8000;
	pts[3].x = -2000;
	pts[3].y = 2000;
	pts[4].x = pts[4].y = 0;
	for (int i = 0; i < 5; i++)
		pts[i].z = 0;
	EditElementHandle eeh;
	ShapeHandler::CreateShapeElement(eeh, NULL, pts, 5, true, *ISessionMgr::GetActiveDgnModelRefP());

	PatternParamsPtr	patPar = PatternParams::Create();
	patPar->SetPrimarySpacing(500.0);
	patPar->SetPrimaryAngle(fc_piover180*45);

	patPar->SetSecondarySpacing(500.0);
	patPar->SetSecondaryAngle(fc_piover180*135);

	ShapeHandler::GetInstance().AddPattern(eeh, *patPar, NULL, 0);
	eeh.AddToModel();

If you close the designfile and open it in V8i you will see that the pattern is now displayed correctly - the angle of the pattern is relative to a horizontal line. What can I do to make the pattern look that way in Connect ?

TIA...

Regards, Evan


RE: VBA does not recognize reference logical name change unless file is closed and reopened

$
0
0

Hi Rolands,

[quote user="Roland Cyr"]My guess is that the following only opens the Default model.[/quote]

No. The name is OpenDesignFileForProgram, not OpenModelForProgram. And it's mentioned also in the method description: Opens a DesignFile that the program controls.

The method opens the design file and it's up to VBA code what part of the file it will access. It's also VBA code responsibility to close the file (.Close() method) after a processing is finished.

[quote user="Roland Cyr"]The actual model I need open is attached as a reference and is given Logical Name as Border.[/quote]

The code can be similar to this one:

Dim reference As Attachment
set reference = ' get right attachment there

Dim refFile As DesignFile
Set refFile = OpenDesignFileForProgram(reference.DesignFile.FullName, False)

Dim model As ModelReference
Set model = refFile.Models(reference.Name)

' access elements in the same way as for e.g. ActiveModelReference

With regards,

 Jan

RE: How to activate a model in C# V8i

$
0
0

[quote user="HDR_Coder"]One needs to activate each model beforehand in order for my previously posted code to iterate through each model.  [/quote]

Thanks for your explanation, I missed this specific feature of the function.

In the past, when I need to create a list of models in a design file, I used mdlDgnFileObj_traverseModelIndex. As far as I remember there is no requirement to "activate  / load" models first.

With regards,

  Jan

RE: [CONNECT C++] Need to modify text/textNodes in a cell

RE: [CONNECT C++] Need to modify text/textNodes in a cell

$
0
0

For a single line of text, how do I get a TextString from a TextBlock ?

RE: [CONNECT C++] Need to modify text/textNodes in a cell

$
0
0
By 'TextString', you mean the DgnPlatform::TextString class? That's pretty much only used for rendering.
From the description of that class:
> To create a TextString from a text element, see TextElemHandler::InitTextString.

If you just want the range as per your original question, see TextBlock::GetNominalRange().
Viewing all 7260 articles
Browse latest View live


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