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

Run Addin without UI

$
0
0

I am using the COM API through Interop assembly code below to scan the document for some reporting. 

public Application ustnApp = new ApplicationClass();

ustnApp.OpenDesignFile(fileName);

  (Blank UI)

Interestingly, when I run it in CONNECT i always get his blank UI popping up, while the blank UI is NOT showing up if I use V8i. How can that be possible?

If I don't want any UI to show up (only want the code to quietly read the Microstation file and generate the report), what should I do?

Thanks,


[Connect C#] Clip Element

$
0
0

Hello,

in V8i I use this class in an Addin to Clip elements.

public class ClipService
    {
        [DllImport("ustation.dll", EntryPoint = "mdlClip_element", CallingConvention = CallingConvention.Cdecl)]
        private static extern int mdlClip_element(ref int insideEdPP, ref int outsideEdPP, int inputEdP, int modelRef, int clipP, int view);

        [DllImport("ustation.dll", EntryPoint = "mdlClip_getFence", CallingConvention = CallingConvention.Cdecl)]
        private static extern int mdlClip_getFence(ref int clipPP);

        [DllImport("ustation.dll", EntryPoint = "mdlClip_free", CallingConvention = CallingConvention.Cdecl)]
        private static extern int mdlClip_free(ref int clipP);

        [DllImport("ustation.dll", EntryPoint = "mdlClip_fromElement", CallingConvention = CallingConvention.Cdecl)]
        private static extern int mdlClip_fromElement(ref int clipPP, int pElement, int outside, int pOutputTransform, int view);

        private int clipPP;
        private int modelRefP;
        private int viewIndex;

        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="clip">Elememt an dem geschnitten werden soll</param>
        /// <param name="modelRef">ModelReference in dem die Elemente liegen</param>
        public ClipService(Element clip, ModelReference modelRef, View view)
        {
            var fence = Utilities.ComApp.ActiveDesignFile.Fence;
            fence.DefineFromElement(view, clip);

            viewIndex = view.Index - 1;
            clipPP = 0;
            modelRefP = modelRef.MdlModelRefP();
            var ret = mdlClip_getFence(ref clipPP);
            //var ret = mdlClip_fromElement(ref clipPP, clip.MdlElementDescrP(false), MSKonstanten.FALSE, 0, viewIndex);
        }

        /// <summary>
        /// Destruktor (Speicher freigeben)
        /// </summary>
        ~ClipService()
        {
            if (clipPP != 0)
            {
                mdlClip_free(ref clipPP);
            }
        }

        /// <summary>
        /// Element wird geclippt
        /// </summary>
        /// <param name="elementToClip">Element welches geclipped werden soll</param>
        /// <returns>Clip Ergebnis oder null</returns>
        public Element DoClip(Element elementToClip)
        {
            int insideEdP = 0;
            int outsideEdP = 0;

            var ret = mdlClip_element(ref insideEdP, ref outsideEdP, elementToClip.MdlElementDescrP(false), modelRefP, clipPP, viewIndex);
            if (insideEdP != 0)
            {
                return Utilities.ComApp.MdlCreateElementFromElementDescrP(insideEdP);
            }
            return null;
        }
    }

Now I search for a clip function in Connect Update 6.

Can someone give me a hint? Is in the DgnPlatformNET Namespace any function to clip elements (line - line, line - shape)?

Thanks

Martin

[CONNECT C++] MSValueDescr

$
0
0

The CONNECT MicroStationAPI introduces the MSValueDescr, which is a wrapper around ValueDescrValueDescr is a variant data type, where the programmer had to take care of memory management for Unicode and multibyte strings.  Is MSValueDescr smarter?  That it, does it manage memory automatically — for example, if I store a string in an MSValueDescr, does its destructor free that string?

Microstation SDK

$
0
0

Hi,

Where may I download Microstation SDK for Microstation Connect Edition Update 6?

I don't find any link of any SDK in Software Download page.

Thanks for help.

Best Regards,

Jean-Claude

[CONNECT C++] How to use MFC Classes CString/CStdioFile

$
0
0

Im not sure that this is even possible with the CONNECT API but is it possible to use the standard MFC classes CString, CStdioFile etc? I am trying to port some legacy code into a working CONNECT application and am running into compiler errors when I include afx.h or afxwin.h. Then I found msmfc.h, tried to include it and get another set of errors, this file seems to just deal with MFC dialogs anyway.

When I search this forum and the API docs I find several posts/entries about using native windows/dialogs but cant find any references about other classes.

Loren.

[CONNECT] Using the ECSchema Editor 1.0

$
0
0

I'd like to use the ECSchema Editor 1.0 to examine my Item Type schema.  The first problem I come across is that my schema is stored in a MicroStation DGNLib and the ECSchema editor can open only XML files.

How can I export my Item Type schema to an XML file?

[CONNECT C++] DgnECInstanceIterable

$
0
0

I'm attempting to enumerate EC instances in a DGN model...

DgnPlatform::FindInstancesScopeOption option (DgnECHostType::Element);
FindInstancesScopePtr scope = FindInstancesScope::CreateScope (*Utilities::GetActiveDgnFile (), option);
ECQueryPtr query = QueryFactory::CreateAreaElementQuery (); UInt32 count { 0 }; DgnECManagerR = SchemaFactory::GetDgnEcManager (); DgnECInstanceIterable instances = manager.FindInstances (*scope,  *query, &count); msg = "Found "; msg += count; msg += " instances"; msg.Output (); // Message Center displays 'Found 8 instances' for (DgnECInstanceIterable::const_iterator it = instances.begin(); it != instances.end(); ++it) { // Compiles and runs OK (but does nothing) }

When I attempt to dereference the iterator I get a run-time crash...

... as before
for (DgnECInstanceIterable::const_iterator it = instances.begin(); it != instances.end(); ++it)
{
   //  Compiles OK but demolishes MicroStation at run-time
   DgnECInstancePtr 	instance = *it;
}

I don't understand the dereference operator in DgnECInstance.h...

typedef iterator_impl::reference reference;
DGNPLATFORM_EXPORT const_iterator (iterator_impl impl);
DGNPLATFORM_EXPORT reference operator*() const;

Because, of course, we cannot see the internals of iterator_impl

[CONNECT C++] Construct ECQuery to get Item Types

$
0
0

If I build an ECQuery like this, to search for, say, DGN shape elements...

ECQueryPtr query = ECQuery::CreateQuery (L"BaseElementSchema",   L"MstnClosedBoundary", true);

Then use it with DgnECManager.FindInstances (... , *query, ...) I get the result I expect.

How do I create a query for my Item Type?  What should the schemaName and className arguments be?  The name of my Item Type library?  The internal name of that library?  The Item Name?  Something else? The screenshot below shows the Item Types dialog with my AreaAnnotator library details...


[CONNECT C++] EC SearchClass

$
0
0

SearchClass Struct Reference

#include <ECQuery.h>

EC SearchClass seems to be an orphan.  It's defined but never used, at least publicly.  Perhaps it's used internally in ECQuery methods that take a schemaName, className pair?

[CONNECT C++] ECQuery::SetPropertyValuePreFilter

$
0
0

I would like to fetch instances of my Item that match a particular property value.  I would like to add a property filter to my ECQuery.  Method  query->SetPropertyValuePreFilter() looks like it should do the job.

However, it takes a IECPropertyValueFilter argument, and I don't see how to populate that struct.  Do I use IECPropertyValueFilter.Accept (ecPropertyValue)?

The only way to make an ECPropertyValuePtr is ECPropertyValue::GetPropertyValue (IECInstanceCR instance, WCharCP propertyAccessor).  But that seems somewhat circular, because it's instances that I'm wanting to find using my ECQuery.

[CONNECT C++] ECQuery::SetPropertyValuePreFilter

$
0
0

In another post I asked about the ECQuery::SetPropertyValuePreFilter method but found that ECQuery::SetSearchCriterion was a much better solution to my problem.

That leaves me with the question: When is it appropriate to use ECQuery::SetPropertyValuePreFilter?  In a rare case there is some helpful commentary in the MicroStationAPI help document about that method...

How to filter before creating instances and applying query where criteria.

How to search for substrings in text-valued properties. A text search is an attribute of a query. The text to search for is associated with a query. The query mechanism used to do text searching is called "property value pre-filtering". Thus, a text search is specified by supplying an ECSubstringPropertyValueFilter to the query. A query containing a text search pre-filter can be set up to search all classes or only specific classes, as usual. The query can contain a where criterion that applies additional tests to the instances that contain the desired text. The query applies its property value pre-filter after filtering on class and before applying where criteria.

FindInstancesScopePtr scope = FindInstancesScope::Create(*model, true);
ECQuery query;
query.SetSearchAllClasses ();
ECSubstringPropertyValueFilter textSearch (L"EQRSVD");
query.SetPropertyValuePreFilter (&textSearch);
for each (DgnElementECInstancePtr inst in dgnECManager.FindElementInstances (*scope, query, model))
	++haveText;

That example uses a ECSubstringPropertyValueFilter to filter on text property values, and is simple to use. All properties a stored as strings: can we use an x to

Its base class IECPropertyValueFilter is more complex.  What would be a good use for IECPropertyValueFilter

That begs the question: When is it useful to perform such pre-filtering?  Is it simply a case of efficiency?  Pre-filtering adds a where clause to an Item Type property search that may be further refined by a subsequent WhereCriterion.

[V8i] VBA to .NET addin or standalone

$
0
0

Hi all,

I have a completed VBA project which I would like to now reproduce it outside of VBA. From what I understand the simplest of my options are to use either VB.Net or C#; I have some experience with the former but not with the latter however this might be a good opportunity to learn C# but I am undecided at the moment. I recall reading that anything written in either of these languages won't give any increase in performance as like VBA, they still use COM and I am absolutely fine with that as the performance of my existing VBA project is perfectly acceptable.

I'm not sure what steps I now need to take and I have some questions:

  1. Addin vs Standalone? I think these are the 2 options I've read which I can aim to create, are there any pro's or con's to either? Can a standalone app interact with an active DGN just like an addin can?
  2. Visual Studio Version? Do I have to create an application with a specific version of Visual Studio (I currently have Visual Studio Community 2015 installed) ?

Any advice would be appreciated

Detaching Attribute-Links by keeping certain valid Links

$
0
0

Hi everyone,

I am writing an MDL-application for Microstation v8i [SS4] that is connected to a database.

To make sure, that only valid MSLinks are attached I want to Stripoff all unneccessary MSLinks, by keeping the valid Links, because this check-function may be called again and existing valid Links should not be deleted.

So my concept is, that there is a callback-Function 'test_CallbackFunct' of a ScanCriteria that Returns an ElementRef, that calls this function 'detachNonValidLinkage'.

The callback-function Looks simplified like this:

Private int test_CallbackFunct
(
ElementRef		elR,			// ElementRef
void			*callbackArg,	// Structur with Parameters for Callback-Funktion
ScanCriteriaP	scP				// ScanCriteria-Object
)
  {
	int numDel=-1;
	CallbackArgStruct	*data = (CallbackArgStruct*)callbackArg;
	MSElementDescr*	edP=NULL;
	EditElemHandle eh(elR, mdlScanCriteria_getModel(scP));	// EditElemHandle from ElementRef

	++(data->numCalls);			// count number of calls
	edP = eh.GetElemDescrP(0);	// create MSElementDescr-Pointer from EditElemHandle

	//	call function 'detachNonValidLinkage'
	if(false == detachNonValidLinkage(&edP, &numDel))
	{
		printf("ERROR in 'test_CallbackFunct': Function-call 'detachNonValidLinkage' returned FALSE, number of deleted links numDel= %i\n", numDel);
	}

    //  Write the changes
    if (eh.ReplaceInModel() != SUCCESS)
	{
		printf("ERROR in 'test_CallbackFunct': Function-call 'ReplaceInModel' NOT successful!\n");
	}

	mdlElmdscr_freeAll(&edP);		// Free allocated MSElementDescr-Object

	return SUCCESS;
  }

The 'detachNonValidLinkage'-function should work like this:
1.) make a copy of the MSElementDescrP

2.) extract all Linkages from original Element

3.) Detach all Attributes from the copy by using 'mdl_detachAttributesElement'

4.) Loop through all found MSLinks and check if the Entity-number of the Link is valid

5.) If Entity-number is valid, attach this MSLink to the copy, otherwise do nothing

6.) Rewrite the changed copy to the original MSElementDescrP, so that changes are written into DGN-file

Here is the Code for this function:

bool	detachNonValidLinkage
(
MSElementDescr**	edPP,		// <=> Pointer to MSElementDescrP
int*				numDetached	//  <= number of detached links
)
  {
	int numLinksBefore, numLinksAfter-1;
	int i, nValid=0, nDel=0, nLinks=-1;
	int entityTable, linkSize=-1;
	UInt32 mslink;						// MSLink-Number
	UInt32 filePos=0L, newfilePos=0L;
	MSElementDescr *newedP=NULL;		// New MSElementDescrP for changes

	LinkProps props;
	short linkage[DBLINKAGE_ARRAY_SIZE];	// Linkage
	DatabaseLink *links=0;					// DB-Link-Structur

	// Element is only changed if Linkages could be extracted
	if(SUCCESS == mdlDB_extractLinkages(&links, &numLinksBefore, &(*edPP)->el))
	{
		if(numLinksBefore <=0)
		{
			*numDetached=0;
			return true;
		}
		mdlElmdscr_duplicate(&newedP, *edPP);		// Create copy of MSElementDescr
		mdlDB_detachAttributesElement(&newedP->el, &newedP->el);	// Detach ALL Links from Copy

		// Define Link-Properties
		memset (&props, 0x00, sizeof (LinkProps));
		props.information = NEWLINK;
		props.user = 1;

		for(i=0; i<numLinksBefore; i++)
		{
			entityTable = (links+i)->entity;
			mslink = (links+i)->mslink;

			// Proofing if valid MSLink
			if(entityTable==validTable1 || entityTable==validTable2 || entityTable==validTable3)
			{
				nValid++;		// count valid links

				// Create Linkage
				if(SUCCESS != mdlDB_buildLink (linkage,&linkSize,OLEDB_LINKAGE,&props,"objatt",mslink,0))
				{
					printf("ERROR in 'detachNonValidLinkage': Function-call 'mdlDB_buildLink' NOT successful!\n");
				}
				else
				{	// Append Attributes to new Element
					mdlElmdscr_appendAttributes (&newedP, linkSize, linkage);
					filePos = mdlElmdscr_getFilePos(newedP);
					if(NULL==(newfilePos=mdlElmdscr_rewrite(newedP, NULL, filePos)))
					{
						printf("ERROR in 'detachNonValidLinkage': %i Function-call 'mdlElmdscr_rewrite' for NEWedP NOT successful! (filePos= %i, newfilePos= %i)\n", i+1, filePos, newfilePos);
					}
				}
			}		// End of IF (valid Entity-number)
			else nDel++;
		}		// End of FOR-Loop

		mdlDB_extractLinkages(&links, &numLinksAfter, &newedP->el);
		if(numLinksAfter==0) *numDetached=numLinksBefore;
		else *numDetached=nDel;

		// Rewriting the changes to the Element
		filePos = mdlElmdscr_getFilePos(*edPP);
		if(NULL==(newfilePos=mdlElmdscr_rewrite(newedP, NULL, filePos)))
		{
			printf("ERROR in 'detachNonValidLinkage': Final Function-call 'mdlElmdscr_rewrite' for 'edPP' NOT successful! (filePos= %i, newfilePos= %i)\n", filePos, newfilePos);
		}

		mdlDB_extractLinkages(&links, &nLinks, &(*edPP)->el);
	}		// End of IF (linkages extracted)
	else {
		*numDetached=0;
		if(Logfile_on) fprintf(f_log, "INFO in 'detachNonValidLinkage': NO Links can be extracted! (numLinksBefore= %i, numLinksAfter= %i, numDetached= %i)\n", numLinksBefore, numLinksAfter, *numDetached);
	}

	printf("INFO in 'detachNonValidLinkage': numLinksBefore= %i, numLinksAfter= %i, (edPP) nLinks=%i, nValid= %i, nDel= %i\n", numLinksBefore, numLinksAfter, nLinks, nValid, nDel);

	// Free allocated memory
	dlmSystem_mdlFree(links);
	mdlElmdscr_freeAll(&newedP);

	return (nDel>0);
  }

The problem is now, that if I have e.g. 2 existing Links before (numLinksBefore = 2), but both of them are not valid and I check the copy-element at the end, than I get that there are no MSLinks (numLinksAfter=0). But after the 'mdlElmdscr_rewrite'-function (which seems to be successful) I still see in the original ElementDescr two MSLinks (nLinks=2).

Why is the original MSElementDescrP not changed, or do I have a General misunderstanding how to Change an Element? In advance I get an error-message, that in the 'test_CallbackFunct' the function-call 'ReplaceInModel' is not successful!

Nevertheless there are no more Links attached in the DGN-file if in the original element were only not valid MSLinks??

Please tell me what causes the Problem or where I am generally wrong!

Many thanks in advance for your help!

Regards,

Ines Wieland

[ADDIN .NET] "Exception has been thrown by target of an invocation" When trying to define Commands.XML

$
0
0

Hey guys I would really appreciate any help on this.  I'm trying to just get to the point where I have a .NET MDL Form application I can launch from a toolbar or Icon.  I am pretty good with .NET, but I am a bit confused by what is going on here. I just want a starting point template project for now that I can compile and add my own methods as I go.  Im using an excellent tutorial from Yongan Fu to start. 

I am good understanding how everything works so far except for the Command Table.  When I added in the Embedded Resource Commands.XML below I started getting the error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Bentley.MicroStation.Exceptions.CommandTableException: Keyin "ImportTraffic CreateElement LineAndLineString" not mapped to method in AddIn ImportTraffic.ImportTraffic.MyAddin
   at Bentley.Internal.MicroStation.CommandTables.RegisterCommandNumbers(KeyinTree tree, AddIn app)
   at Bentley.Internal.MicroStation.CommandTables.LoadKeyinTables(String xmlFileName, AddIn app)
   at Bentley.MicroStation.AddIn.Initialize(IntPtr mdlDescriptor, String appXmlFileFqn)
   at Bentley.MicroStation.AddIn..ctor(IntPtr mdlDescriptor)
   at ImportTraffic.ImportTraffic.MyAddin..ctor(IntPtr mdlDesc) in C:\Users\spen6722\Documents\SharpDevelop Projects\ImportTraffic\ImportTraffic\ImportTraffic.vb:line 48
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
   at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Bentley.MicroStation.AddIn.Load(String[] commandTail, IntPtr mdlDesc)

Here is where I am at so far:

ImportTraffic.vb

Imports System
Imports System.Windows.Forms
Imports Bentley.MicroStation.WinForms
Imports Bentley.MicroStation.InteropServices
Imports System.Runtime.InteropServices
Imports Bentley.MicroStation

Namespace ImportTraffic

	''' <summary>''' Import Traffic Microstation Plugin''' By Matt Spencer 2017.09.11''' Maatspencer@gmail.com''' Written in VB.Net using Sharp Develop'''''' This is the primary startup file that is called by Microstation via the MDL Load ImportTraffic Key-in'''''' Setup:''' 1. Create a new class Library''' 2. Change the Build to Target .NET 3.5  Which is a bastardised version based on .NET 2.0 to pull XP users along I believe.''' 3. Add References to Bentley.General.1.0.dll , ustation.dll, Bentley.Microstation.Interfaces.1.0.dll System.Windows.Forms''' 4. Set the output path'''''' Rules For Compilation:''' If a .NET assembly can be executed as an Addin under Mstn, it must meet three conditions:''' a) Includes one class derived from Bentley.MicroStation.Addin;''' b) This derived class must supply a single argument constructor that take an MDL descriptor as an int;''' That constructor must chain to the base class constructor and pass the argument along;''' c) This derived class must override the virtual Run() method of the base Addin class'''''' How to run:''' 1. Build the Dll file to your output Path''' 2. In microstation Append the directory path to MS_ADDINPATH''' 3. Run the Add In With MDL Load ImportTraffic,,MyDomain''' 4. CLR Dialog will show you the run status''' 5.  CLR UNLOAD DOMAIN MyDomain - Will unload the project for debugging'''''' </summary>' Commands for the Key-in' Derive the base class from Bentley.Microstaton.Addin<Bentley.MicroStation.AddInAttribute(KeyinTree := "ImportTraffic.Commands.xml", MdlTaskID := "ImportTraffic")> _
	Friend NotInheritable Class MyAddin
		Inherits Bentley.MicroStation.AddIn' MDL Load Description requires a sinle integer argument to run
		Private Sub New(mdlDesc As System.IntPtr)
			MyBase.New(mdlDesc)
		End Sub' Override the Run() Function in the AddIn Class' This is where we call the program via Key-In
		Protected Overrides Function Run(commandLine As String()) As Integer
			Return 0
		End Function



	End Class
End Namespace


Create Element.vb

Imports System
Imports Bentley.MicroStation.InteropServices
Imports Bentley.Interop.MicroStationDGN

Namespace ImportTraffic
	Class CreateElement
		Public Shared Sub LineAndLineString(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim startPnt As Point3d = app.Point3dZero()
			Dim endPnt As Point3d = startPnt
			startPnt.X = 10
			Dim oLine As LineElement = app.CreateLineElement2(Nothing, startPnt, endPnt)
			oLine.Color = 0
			oLine.LineWeight = 2
			app.ActiveModelReference.AddElement(oLine)

			Dim pntArray As Point3d() = New Point3d(4) {}
			pntArray(0) = app.Point3dZero()
			pntArray(1) = app.Point3dFromXY(1, 2)
			pntArray(2) = app.Point3dFromXY(3, -2)
			pntArray(3) = app.Point3dFromXY(5, 2)
			pntArray(4) = app.Point3dFromXY(6, 0)
			oLine = app.CreateLineElement1(Nothing, pntArray)
			oLine.Color = 1
			oLine.LineWeight = 2
			app.ActiveModelReference.AddElement(oLine)
		End Sub


		Public Shared Sub ShapeAndComplexShape(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim pntArray As Point3d() = New Point3d(5) {}
			pntArray(0) = app.Point3dFromXY(0, -6)
			pntArray(1) = app.Point3dFromXY(0, -2)
			pntArray(2) = app.Point3dFromXY(2, -2)
			pntArray(3) = app.Point3dFromXY(2, -4)
			pntArray(4) = app.Point3dFromXY(4, -4)
			pntArray(5) = app.Point3dFromXY(4, -6)
			Dim oShape As ShapeElement = app.CreateShapeElement1(Nothing, pntArray)
			oShape.Color = 0
			oShape.LineWeight = 2
			app.ActiveModelReference.AddElement(oShape)

			Dim elmArray As ChainableElement() = New ChainableElement(1) {}
			For i As Integer = 0 To 5
				pntArray(i).X += 5
			Next
			elmArray(0) = app.CreateLineElement1(Nothing, pntArray)
			pntArray(2).Y = -8
			elmArray(1) = app.CreateArcElement3(Nothing, pntArray(5), pntArray(2), pntArray(0))
			Dim oComplexShape As ComplexShapeElement = app.CreateComplexShapeElement1(elmArray)
			oComplexShape.Color = 1
			oComplexShape.LineWeight = 2
			app.ActiveModelReference.AddElement(oComplexShape)
		End Sub


		Public Shared Sub TextAndTextNode(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim savedTextHeight As Double = app.ActiveSettings.TextStyle.Height
			Dim savedTextWidth As Double = app.ActiveSettings.TextStyle.Width
			Dim savedFont As Font = app.ActiveSettings.TextStyle.Font
			Dim savedAnnotationScaleEnabled As Boolean = app.ActiveSettings.AnnotationScaleEnabled
			app.ActiveSettings.TextStyle.Height = 0.7
			app.ActiveSettings.TextStyle.Width = 0.6
			'app.ActiveSettings.TextStyle.Font = app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "Arial Unicode MS")
			app.ActiveSettings.AnnotationScaleEnabled = False

			Dim origin As Point3d = app.Point3dFromXY(0, -7.5)
			Dim rMatrix As Matrix3d = app.Matrix3dIdentity()
			Dim oText As TextElement = app.CreateTextElement1(Nothing, "Text String", origin, rMatrix)
			oText.Color = 0
			app.ActiveModelReference.AddElement(oText)

			origin = app.Point3dFromXY(2, -9)
			Dim oTN As TextNodeElement = app.CreateTextNodeElement1(Nothing, origin, rMatrix)
			oTN.AddTextLine("Text Node Line 1")
			oTN.AddTextLine("Text Node Line 2")
			oTN.Color = 1
			app.ActiveModelReference.AddElement(oTN)

			app.ActiveSettings.TextStyle.Height = savedTextHeight
			app.ActiveSettings.TextStyle.Width = savedTextWidth
			app.ActiveSettings.TextStyle.Font = savedFont
			app.ActiveSettings.AnnotationScaleEnabled = savedAnnotationScaleEnabled
		End Sub


		Public Shared Sub CellAndSharedCell(unparsed As String)
			Dim app As Application = Utilities.ComApp
			app.AttachCellLibrary("sample2.cel")
			Dim origin As Point3d = app.Point3dFromXY(1, -13)
			Dim xScale As Double = 0.1 * app.ActiveModelReference.UORsPerMasterUnit / 1000.0
			Dim scale As Point3d = app.Point3dFromXYZ(xScale, xScale, xScale)
			Dim rMatrix As Matrix3d = app.Matrix3dIdentity()
			Dim oCell As CellElement = app.CreateCellElement2("DECID", origin, scale, True, rMatrix)
			oCell.Color = 0
			app.ActiveModelReference.AddElement(oCell)

			Dim oSC As SharedCellElement
			xScale = 0.02 * app.ActiveModelReference.UORsPerMasterUnit / 1000.0
			scale = app.Point3dFromXYZ(xScale, xScale, xScale)
			For x As Integer = 4 To 8 Step 2
				origin = app.Point3dFromXY(x, -14)
				oSC = app.CreateSharedCellElement2("NORTH", origin, scale, True, rMatrix)
				oSC.OverridesComponentColor = True
				oSC.Color = 1
				app.ActiveModelReference.AddElement(oSC)
			Next
		End Sub


		Public Shared Sub LinearAndAngularDimension(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim ds As DimensionStyle = app.ActiveSettings.DimensionStyle
			ds.OverrideAnnotationScale = True
			ds.AnnotationScale = 1
			ds.OverrideTextHeight = True
			ds.TextHeight = 0.5
			ds.OverrideTextWidth = True
			ds.TextWidth = 0.4
			ds.MinLeader = 0.01
			ds.TerminatorArrowhead = MsdDimTerminatorArrowhead.Filled
			Dim rMatrix As Matrix3d = app.Matrix3dIdentity()
			Dim pnts As Point3d() = New Point3d(2) {}
			pnts(0) = app.Point3dFromXY(0, -17)
			pnts(1) = app.Point3dFromXY(3, -17)
			Dim oDim As DimensionElement = app.CreateDimensionElement1(Nothing, rMatrix, MsdDimType.SizeArrow)
			oDim.AddReferencePoint(app.ActiveModelReference, pnts(0))
			oDim.AddReferencePoint(app.ActiveModelReference, pnts(1))
			oDim.Color = 0
			oDim.DimHeight = 1
			app.ActiveModelReference.AddElement(oDim)

			ds.AnglePrecision = MsdDimValueAnglePrecision.DimValueAnglePrecision1Place
			oDim = app.CreateDimensionElement1(Nothing, rMatrix, MsdDimType.AngleSize)
			pnts(0) = app.Point3dFromXY(7, -13)
			pnts(1) = app.Point3dFromXY(5, -15)
			pnts(2) = app.Point3dFromXY(9, -15)
			oDim.AddReferencePoint(app.ActiveModelReference, pnts(0))
			oDim.AddReferencePoint(app.ActiveModelReference, pnts(1))
			oDim.AddReferencePoint(app.ActiveModelReference, pnts(2))
			oDim.Color = 1
			oDim.DimHeight = 1
			app.ActiveModelReference.AddElement(oDim)
		End Sub


		Public Shared Sub CurveAndBsplineCurve(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim pntArray As Point3d() = New Point3d(4) {}
			pntArray(0) = app.Point3dFromXY(0, -19)
			pntArray(1) = app.Point3dFromXY(1, -17)
			pntArray(2) = app.Point3dFromXY(2, -19)
			pntArray(3) = app.Point3dFromXY(3, -17)
			pntArray(4) = app.Point3dFromXY(4, -19)
			Dim oCurve As CurveElement = app.CreateCurveElement1(Nothing, pntArray)
			oCurve.Color = 0
			oCurve.LineWeight = 2
			app.ActiveModelReference.AddElement(oCurve)

			For i As Integer = 0 To 4
				pntArray(i).X += 5
			Next
			Dim oInterpolationCurve As InterpolationCurve = New InterpolationCurveClass()
			oInterpolationCurve.SetFitPoints(pntArray)
			Dim oBsplineCurve As BsplineCurveElement = app.CreateBsplineCurveElement2(Nothing, oInterpolationCurve)
			oBsplineCurve.Color = 1
			oBsplineCurve.LineWeight = 2
			app.ActiveModelReference.AddElement(oBsplineCurve)
		End Sub


		Public Shared Sub ConeAndBsplineSurface(unparsed As String)
			Dim app As Application = Utilities.ComApp
			Dim basePt As Point3d = app.Point3dFromXYZ(2, -23, 0)
			Dim topPt As Point3d = app.Point3dFromXYZ(2, -20, 0)
			Dim rMatrix As Matrix3d = app.Matrix3dFromAxisAndRotationAngle(0, app.Pi() / 6)
			Dim oCone As ConeElement = app.CreateConeElement1(Nothing, 2, basePt, 1, topPt, rMatrix)
			oCone.Color = 0
			app.ActiveModelReference.AddElement(oCone)

			Dim aFitPnts As Point3d() = New Point3d(3) {}
			Dim oFitCurve As InterpolationCurve = New InterpolationCurveClass()
			Dim aCurves As BsplineCurve() = New BsplineCurve(2) {}

			aFitPnts(0) = app.Point3dFromXYZ(5.9, -21, -0.5)
			aFitPnts(1) = app.Point3dFromXYZ(6.9, -20, 1)
			aFitPnts(2) = app.Point3dFromXYZ(7.9, -20.3, 1.3)
			aFitPnts(3) = app.Point3dFromXYZ(8.9, -20.8, 0.3)
			oFitCurve.SetFitPoints(aFitPnts)
			oFitCurve.BesselTangents = True
			aCurves(0) = New BsplineCurveClass()
			aCurves(0).FromInterpolationCurve(oFitCurve)

			aFitPnts(0) = app.Point3dFromXYZ(6.4, -22, 0)
			aFitPnts(1) = app.Point3dFromXYZ(7.1, -21.2, 0.7)
			aFitPnts(2) = app.Point3dFromXYZ(7.7, -21, 1)
			aFitPnts(3) = app.Point3dFromXYZ(8.4, -21.7, -0.2)
			oFitCurve.SetFitPoints(aFitPnts)
			oFitCurve.BesselTangents = True
			aCurves(1) = New BsplineCurveClass()
			aCurves(1).FromInterpolationCurve(oFitCurve)

			aFitPnts(0) = app.Point3dFromXYZ(5.9, -23, 0)
			aFitPnts(1) = app.Point3dFromXYZ(7.2, -23.1, 1.2)
			aFitPnts(2) = app.Point3dFromXYZ(7.8, -23.3, 0.8)
			aFitPnts(3) = app.Point3dFromXYZ(8.7, -22.8, 0.2)
			oFitCurve.SetFitPoints(aFitPnts)
			oFitCurve.BesselTangents = True
			aCurves(2) = New BsplineCurveClass()
			aCurves(2).FromInterpolationCurve(oFitCurve)

			Dim oBsplineSurface As BsplineSurface = New BsplineSurfaceClass()
			oBsplineSurface.FromCrossSections(aCurves, MsdBsplineSurfaceDirection.V, 4, True, True)
			Dim oSurfaceElm As BsplineSurfaceElement = app.CreateBsplineSurfaceElement1(Nothing, oBsplineSurface)
			oSurfaceElm.Color = 1
			app.ActiveModelReference.AddElement(oSurfaceElm)
		End Sub
	End Class
End Namespace

Comannds.xml (Embedded Resource)

<?xml version="1.0" encoding="utf-8" ?><KeyinTree xmlns="http://www.bentley.com/schemas/1.0/MicroStation/AddIn/KeyinTree.xsd"><RootKeyinTable ID="root"><Keyword SubtableRef="CreateElement"
            CommandClass="MacroCommand" CommandWord="ImportTraffic" ><Options Required ="true"/></Keyword></RootKeyinTable><SubKeyinTables><KeyinTable ID="CreateElement"><Keyword SubtableRef="Commands" CommandWord="CreateElement"><Options Required ="true"/></Keyword></KeyinTable><KeyinTable ID="Commands"><Keyword CommandWord="LineAndLineString"> </Keyword><Keyword CommandWord="ShapeAndComplexShape"> </Keyword><Keyword CommandWord="TextAndTextNode"> </Keyword><Keyword CommandWord="CellAndSharedCell"> </Keyword><Keyword CommandWord="LinearAndAngularDimension"> </Keyword><Keyword CommandWord="CurveAndBsplineCurve"> </Keyword><Keyword CommandWord="ConeAndBsplineSurface"> </Keyword></KeyinTable></SubKeyinTables><KeyinHandlers><KeyinHandler Keyin="ImportTraffic CreateElement LineAndLineString"
        Function="ImportTraffic.CreateElement.LineAndLineString"/><KeyinHandler Keyin="ImportTraffic CreateElement ShapeAndComplexShape"
        Function="ImportTraffic.CreateElement.ShapeAndComplexShape"/><KeyinHandler Keyin="ImportTraffic CreateElement TextAndTextNode"
        Function="ImportTraffic.CreateElement.TextAndTextNode"/><KeyinHandler Keyin="ImportTraffic CreateElement CellAndSharedCell"
        Function="ImportTraffic.CreateElement.CellAndSharedCell"/><KeyinHandler Keyin="ImportTraffic CreateElement LinearAndAngularDimension"
        Function="ImportTraffic.CreateElement.LinearAndAngularDimension"/><KeyinHandler Keyin="ImportTraffic CreateElement CurveAndBsplineCurve"
        Function="ImportTraffic.CreateElement.CurveAndBsplineCurve"/><KeyinHandler Keyin="ImportTraffic CreateElement ConeAndBsplineSurface"
        Function="ImportTraffic.CreateElement.ConeAndBsplineSurface"/></KeyinHandlers></KeyinTree>

[CONNECT C++] ECQuery: ECExpressionCriterion and HostExpressionCriterion

$
0
0

ECQuery::WhereCriterion does the job when filtering EC instances using string selection.

I notice that two other classes,   ECExpressionCriterion and HostExpressionCriterion, inherit from WhereCriterion.  However, the API is limited to creation and nother more..

I would like to be able to filter EC instance based on chained queries.  In particular, I want to select instances whose EC properties match a value and whose DGN properties match another value.  For example, I want to select all shapes having an Item Type property value 'office' that are also on level 'interior walls'.

I may be barking up the wrong tree, but  HostExpressionCriterion looks like it is intended for that purpose, but lacks a public API that can be used.

If that's a wrong approach, is there another way to combine queries about EC properties with DGN element properties?


C# Power InRoad SS4 Modify Link Segment

$
0
0

Hi,

I'm Trying to modify an existing Link Segment between two nodes. but changes not applying on Link Segment.

Below code will add a node to an existing Link at given coordinate, But  not modifying the Link path through added Node. How can I rectify this issue?

                int utilityID = 329; //link ID

               SUB.UtilityEntity ent = model.GetUtility<SUB.UtilityEntity>(utilityID);

                if (ent != null)

                {

                    if (ent is SUB.LinkEntity)

                     (ent as SUB.LinkEntity).BendPoints.Add((new DPoint3d(254573.1440,6140052.4694))); //Added the Node

                      model.PersistChanges(ent); //added a node at outside from the Link at give coordination point. but the Link entity not bended. still the link is in straight line between two nodes.

                    ent.Refresh();

                    model.Refresh();

                    MessageBox.Show("Done"); //Executed

                }

Forum Icon Test - Please Delete This Thread

$
0
0

I posted this on 18-Sep-17 to see how the Be Communities site deals with icons in my signature in a new post.

What are the differences between the MacroStation .Net and MDL Native Code APIs?

$
0
0

I took a quick look at MicroStationAPI.chm and MSTNPlatformNET.chm. Seems MicroStationAPI are Native C++/C APIs, and MSTNPlatformNET are .Net APIs like C#, and VB net. Both have object model. But the Object Models of MicroStationAPI and MSTNPlatformNET are different, e.g. MSTNPlatformNET  has Application object, but MicroStationAPI  has not. So what should I learn MSTNPlatformNET  or MicroStationAPI ?  Why not have consistent Object Model? Another question does MicroStation C++ API support binary compatibility, e.g. what will happen if a C++ addin dll built on MicroStation Version 1, and run on a later Version 2 without building again?

Thanks.

2 models, temporary visible of the mouse position, vba

$
0
0

Hi all,

I have 2 models in the same dgn. 1 model is for a rasterfile ("Radargrammen") and the other for the overview ("Model"). In the model Radargrammen i hover with my mouse over the raster and i am able to calculate a distance from teh beginning of the raster. At the same time i want to show where on the line in the model "Model" i hover with my mouse. In attached code it is possible, but it seems to be impossible to add a cell  temporary. So i add it to the model, and when i move the mouse then i delete the old cell. It seems that this works good, but in model "Model" the old cell does not disappear immidiately. Does anyone have a solution?

Sorry for my bad english.....;=)

Regards, Aart

Option Explicit

Implements IPrimitiveCommandEvents
Private m_strCellName   As String

Public Property Let cellName(ByVal name As String)
    m_strCellName = name
End Property

Public Property Get cellName() As String
    cellName = m_strCellName
End Property

Private Sub IPrimitiveCommandEvents_Cleanup()
End Sub

Private Sub CreateCell(ByRef Point As Point3d, ByVal DrawMode As MsdDrawingMode)
    
    Dim i As Long
    Dim oCell As CellElement

    Set oCell = CreateCellElement2(m_strCellName, Point, Point3dOne, True, Matrix3dIdentity)
    If DrawMode = msdDrawingModeNormal Then
        ActiveModelReference.AddElement oCell
    Else
        oCell.Redraw DrawMode
    End If
    
End Sub

Private Sub IPrimitiveCommandEvents_DataPoint(Point As Point3d, ByVal view As view)

    CreateCell Point, msdDrawingModeNormal

End Sub

Private Sub IPrimitiveCommandEvents_Dynamics(Point As Point3d, ByVal view As view, ByVal DrawMode As MsdDrawingMode)
    
    Call DeleteOldCell
    Call DistanceFromBegin(Point)
    CreateCell Point, DrawMode

End Sub

Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)

'    m_strCellName = Keyin

End Sub

Private Sub IPrimitiveCommandEvents_Reset()
    
    CommandState.StartDefaultCommand

End Sub

Private Sub IPrimitiveCommandEvents_Start()
    
    CommandState.CommandName = "TerraCarta"
    ShowCommand CommandState.CommandName
    ShowPrompt "Plaats type"
    CommandState.StartDynamics
    'CommandState.EnableAccuSnap

End Sub

Sub DistanceFromBegin(Punt As Point3d)

Dim ee As ElementEnumerator, esc As New ElementScanCriteria
Dim RadarLijn As LineElement, RadarGramAfstandsPoint As Point3d, Cirkel As EllipseElement

esc.ExcludeAllLevels
esc.ExcludeAllTypes
esc.IncludeLevel ActiveDesignFile.Levels("RadarGram")
esc.IncludeType msdElementTypeLine

Set ee = ActiveModelReference.Scan(esc)

While ee.MoveNext
    Set RadarLijn = ee.Current
    
    RadarGramAfstandsPoint = RadarLijn.ProjectPointOnPerpendicular(Punt, Matrix3dIdentity)
 
    Call AfstandOpMeetlijn(RadarGramAfstandsPoint.X)
 
'    Set Cirkel = CreateEllipseElement2(Nothing, RadarGramAfstandsPoint, 1, 1, Matrix3dIdentity)
'    Cirkel.Redraw msdDrawingModeTemporary
    
Wend
    
End Sub

Sub AfstandOpMeetlijn(Afstand As Double)

Dim ee1 As ElementEnumerator, esc1 As New ElementScanCriteria
Dim Meetlijn As LineElement, PuntOpMeetlijn As Point3d, HulpPunt As CellElement
Dim Ellips As EllipseElement, Flags As MsdTransientFlags

esc1.ExcludeAllLevels
esc1.ExcludeAllTypes
esc1.IncludeLevel ActiveDesignFile.Levels("Meetlijn")
esc1.IncludeType msdElementTypeLine

Set ee1 = ActiveDesignFile.Models("Model").Scan(esc1)

While ee1.MoveNext
    Set Meetlijn = ee1.Current
    TijdelijkPunt = Meetlijn.PointAtDistance(Afstand)
    Set HulpPunt = CreateCellElement3("Hulppunt", TijdelijkPunt, True)
    ActiveDesignFile.Models("Model").AddElement HulpPunt '' > I have to,  ;-(
    HulpPunt.Redraw msdDrawingModeTemporary
      
Wend

End Sub

Sub DeleteOldCell()

Dim ee As ElementEnumerator, esc As New ElementScanCriteria

esc.ExcludeAllLevels
esc.ExcludeAllTypes
esc.IncludeLevel ActiveDesignFile.Levels("Hulppunt")
esc.IncludeType msdElementTypeCellHeader

Set ee = ActiveDesignFile.Models("Model").Scan(esc)

While ee.MoveNext
    ActiveDesignFile.Models("Model").RemoveElement ee.Current
Wend
ActiveDesignFile.Models("Model").UnselectAllElements

End Sub


Is there a way to read the DGNLIB name of a level in a dgn file in VBA?

$
0
0

I was looking to see if as I step through a Levels collection, if it is possible to derive the file that is providing the level? There does not appear to be a VBA property, so I was wondering if anyone had a wrapper function for an MDL function that could be used.

Viewing all 7260 articles
Browse latest View live


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