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

RE: Get Coordinate

$
0
0
As you can see in code example it already contained DoEvents and that is the method which causes issue with zoom as it takes too long to process.
Found out that better GUI response I can get using CommandState.LastView.Redraw instead of Sleep. It is almost acceptable but agree that better response would be if using native code.

What I am trying to achieve by using this example code is to replace "running coordinates" and show GPS position instead. There are no standard tools to read-out GPS position as when using "ACS position" it also changes readout for snaps.

RE: Get Coordinate

$
0
0

[quote user="Oto"] What I am trying to achieve by using this example code is to replace "running coordinates" and show GPS position instead[/quote]

Write a class that Implements IPrimitiveCommandEvents.  The _Dynamics event handler gives you the current cursor location.  You can calculate GPS location in that subroutine.

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

$
0
0

[quote user="Jon Summers"]

Barry Lothian
This could be 1 of 2 possible directions

That's what the cross product help you to resolve.  It's another vector, that will be pointing up or down (i.e. positive or negative Z value).[/quote]

Yes I know that's what the cross product determines, what I was meaning by 2 directions is 2 directions along the chainage element for the 2nd Vector as per the image below:

What I was wanting to confirm is that in order to calculate the cross product, I should firstly be calculating the pink vector and not the yellow vector.

RE: How to activate a model in C# V8i

$
0
0

[quote user="HDR_Coder"]How does one get model refs in C# on V8i?[/quote]

I suggest that you create a prototype of your code in VBA.  If that works, you're in a strong position to analyse why it doesn't work when called from C# as an InterOp.

RE: How to activate a model in C# V8i

$
0
0

I did.  Here is the ugly workaround.

Sub iterateModelsAndRunKeyin()
Dim Model As ModelReference
For Each Model In ActiveDesignFile.Models
        Model.Activate
        Pause 10
        CadInputQueue.SendKeyin "MDL LOAD ExpandPrintBorder,,unique"
        Pause 5
        CadInputQueue.SendKeyin "clr unLOAD domain unique"
        Pause 10
Next Model
End Sub

Public Sub Pause(sngSecs As Single)
    Dim sngEnd As Single
    sngEnd = Timer + sngSecs
    While Timer < sngEnd
        DoEvents
    Wend
End Sub

Then the ExpandPrintBorder is the dll for my app that uses the activemodelreference to do all the work.

I am not sure why this works in VBA but not in C#...I know I can interop with C++ to get this to work, but that seems like a drastic (yet effective) workaround.

Thank you for your help.

RE: How to activate a model in C# V8i

$
0
0

[quote user="HDR_Coder"]ForEachModel InActiveDesignFile.Models[/quote]

[quote user="HDR_Coder"]foreach(ModelReference model innewapp.ActiveDesignFile.Models)[/quote]

Is it an issue with temporary object lifetimes, or other misuse of the class?  There's a note in VBA help: You cannot use the New keyword to create a ModelReferences object.  Unfortunately, C# pays no attention to certain COM qualifiers such as noncreatable.

The VBA iterator uses property ActiveDesignFile.Models.  Nothing new or temporary is created.

The C# iterator creates an anoymous temporary variable to store the result of newapp.ActiveDesignFile.Models. As a new, unitialised, variable it contains no data. What happens if you use the VBA idiom in C#?

foreach (ModelReference model in app.ActiveDesignFile.Models)

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

$
0
0

Jan ... I found the issue but, not sure how to fix it. What I am doing after attaching the reference is running a sub function that will do a text substitution on the attached reference.

Then running a second vba that works off finding Reference with Logical name as "BORDER".

When I remove the sub function for text substitution everything works as expected and the second vba finds the reference with the Reference Logical name as "Border".

Below is the sub function for text substation after attaching the reference file:

Sub ChgTitleBlockYear() ' add to change titleblock year

Dim today As String

    Dim MyDate As String
   
    Dim Mystr As String
    Dim find As String
    Dim replace As String
   
   
    find = "YYYY Delhaize America Shared Services LLC"
   
   
   
    MyDate = Date
   
    Mystr = Format(MyDate, "yyyy")

replace = Mystr & " Delhaize America Shared Services LLC"
 
   CadInputQueue.SendCommand "Reference Activate Border"
   CadInputQueue.SendCommand "xy=0,0,0"

'find and replace text
  
  
   CadInputQueue.SendCommand "mdl load findreplacetext"
  
   CadInputQueue.SendKeyin "FIND DIALOG ZOOM False"
   CadInputQueue.SendKeyin "FIND DIALOG PAN False"
  
   CadInputQueue.SendKeyin "FIND DIALOG SEARCHSTRING " & find
  
  
  
   CadInputQueue.SendKeyin "FIND DIALOG REPLACESTRING " & replace
  
   CadInputQueue.SendKeyin "change text all"

CadInputQueue.SendCommand "mdl unload findreplacetext"
 
  CadInputQueue.SendCommand "Reference DeActivate Border"
 
CommandState.StartDefaultCommand

End Sub

Not sure why removing the ChgTitleBlockYear() call within the program solves my issue.

TIA,

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

$
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: MicroStation CONNECT or MicroStation V8i. What is the 8-digit version number (e.g. 10.xx.yy.zz) of MicroStation?

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 It makes it much easier for others to follow your code.

VBA References Collection

[quote user="Roland Cyr"]When running the second vba and do a watch on the reference logical name it does not find "BORDER" unless file is closed and reopened before running the second vba. The reference dialog box shows "BORDER" logical name before closing and reopening the dgn file. Is this possibly a bug in the program[/quote]

[quote user="Roland Cyr"]What I am doing after attaching the reference is running a sub function that will do a text substitution on the attached reference[/quote]

You subroutine ChgTitleBlockYear() doesn't just change the title block, does it?  It has a side efffect: it activates a reference and then switches back.  The effect of activating a reference probably invalidates the ModelReference.References collection.


RE: How to activate a model in C# V8i

$
0
0

My bad, the "new app.ActiveDesignFile.Models" was a typo from "foreach(ModelReference model in new List<ModelReference>(){app.ActiveModelReference})."

I already tried foreach(ModelReference model inapp.ActiveDesignFile.Models) to no avail.

The next most simple solution was to implement something in C++ via C++/CLI and just call the functions I already wrote in C#.

Here is the C++/CLI code.

#pragma once
#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");
		DgnFileObjP dgnFile = mdlDgnFileObj_getMasterFile();

		DgnModelRefListP loadedModels = mdlDgnFileObj_getModelRefList(dgnFile);

		int loadedModelsCount = mdlModelRefList_getCount(loadedModels);
		for (int i = 0; i < loadedModelsCount; i++){
			DgnModelRefP modelRef = mdlModelRefList_get(loadedModels, i);
			mdlModelRef_activateAndDisplay(modelRef);
			CSharpAddin^ cs = gcnew CSharpAddin();
			cs->Main();
		}
		return 0;
	};
};

I also had a header file:

#define winNT
#include <mdl.h>
#include <msdgnobj.fdf>
#include <msmodel.fdf>
#include <msdgnmodelref.fdf>
#include <modelindex.fdf>
#include <msdgnobj.fdf>
#include <msdgnmodelref.fdf>

//needed to unload
#include    <cmdlist.h>
#include    <dlogman.fdf>
#include    <mssystem.fdf>
#include "ModelIterator.h"

#include <mdl.h>
#include <msdgnobj.fdf>
#include <msmodel.fdf>
#include <msdgnmodelref.fdf>
#include <modelindex.fdf>
#include <msdgnobj.fdf>
#include <msdgnmodelref.fdf>

I used mdlModelRefList_get and mdlModelRef_activateAndDisplay to get/activate my models.  From there I just made a static C# method with the code I wanted to run.  

Thanks for the help and the comments.  

How to activate a model in C# V8i

$
0
0

I am trying to activate a model.  The below code gives me the error:

An exception of type 'System.EntryPointNotFoundException' occurred in Bentley.Civil.CadSystem.Microstation.2.0.dll but was not handled in user code

Additional information: Entry point was not found.
            Application app = Utilities.ComApp;
            foreach (ModelReference model in new app.ActiveDesignFile.Models)
            {
                model.Activate();

Something is bad about the model reference.

How does one get model refs in C# on V8i?

Thank you!

RE: How to activate a model in C# V8i

$
0
0

Hi,

a few unsorted comments and thoughts that crossed my mind when I read the discussion:

  • It's not mentioned in documentation if VBA method Activate() is (a)synchronous. My feeling is that it behaves more as asynchronous, so it starts the model activation process, but MicroStation is still busy despite off method is finished. Model activation (opening a model or the whole file) is pretty complex and lengthy process. I think the right time to work with newly opened model is affter EnterIdle event is raised, not earlier.
  • I did not try it, but without waiting for the idle state, I can imagine something can go wrong.
  • Yes, I agree, the workaround with using pause is ugly ;-)
  • I am not sure I remember it right, but loading addin to own domain was discussed in the past and I think it's not officially supported by Bentley despite of it's possible. And some posts describe errors or strange behaviour of some API or MicroStation parts if an addin runs in own domain.
  • In my opinion the usage of C++/CLI is overkill in this situation. I think it should be enough to call mdlModelRef_activateAndDisplay using P/Invoke directly from C# code. I assume MdlModelRefP available in VBA API can be passed to mdlModelRef_activateAndDisplay (but have not tested it).
  • There is a memory leak in your C++/CLI code: You has to free DgnModelRefListP using mdlModelRefList_free.
  • When you iterate model list in MDL, you should test and filter received models from hidden ones. I guess you don't want to use your function for such models, created by MicroStation or other application for a specific purposes.

With regards,

  Jan

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

$
0
0
Hi Rolands,

I agree with Jon that the method side effect - the activation of a reference - probably invalidates existing VBA objects, so the code does not work as expected.

I also dislike to use Find and Replace Text tool and using key-ins. Better would be to open the reference at background using OpenDesignFileForProgram. To open a file in "for program" mode brings some limitations, but to iterate a model and find and replace texts should work fine.

With regards,

Jan

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

$
0
0

[quote user="Jan Slegr"] I also dislike to use Find and Replace Text tool and using key-ins[/quote]

Yes, it does make the code look rather messy.

Here's a VBA text find-and-replace tool...

The VBA project is not protected and includes the source code, so anyone is free to pull it apart and add whatever is need to their own code.

RE: [CONNECT C++] mdlRaster_clipBoundarySet

$
0
0

I join a small dgn with  18 rasters with clip boundary. If the dgn is opened with MicroStation V8i, it is Ok. But opened with MS CONNECT the clip boundary is randomly ignored. I join a screen copy of the result. It is more a display problem than the mdlRaster_clipBoundatySet function.  (Please visit the site to view this file)

Best regards,

Patrice

[CONNECT C++] mdlRaster_clipBoundarySet

$
0
0

Hello,

Is mdlRaster_clipBoundarySet obsolete in CONNECT ?

I use Windows 7. That function works well in V8i, but the clip boundary is sometimes ignored in CONNECT.

Best regards.

Patrice

 


RE: How to apply the textures to the surface?

$
0
0
Hi Karthik,

it's not quite clear if you don't know how to do it in MicroStation (how a material should be attached to an object) or you don't know how to implement it in a code.

I recommend to try it using standard MicroStation tools (material editor, attach material to the surface). It will help you to find a right settings (should it be drapped over surface or attached, in what scale etc.), which will be necessary to repeat the same process using MDL.

With regards,

Jan

RE: How to apply the textures to the surface?

$
0
0

[quote user="Karthik M"]I am using Microstation v8i Select series 3. I Have tiff image and 3d Polygon surfaces i need to be apply the textures from the tiff image to 3d Polygon surfaces[/quote]

I assume that you're using MDL (since other languages don't support materials or textures).  Take a look at the mdlMaterial_xxx API.  It's not especially easy to use (it has pointers all over the place that you must follow to poorly-documented destinations) and there are few examples.  There's also a Materials section in the MDL Function Reference.

FWIW that API is replaced in MicroStation CONNECT.

How to apply the textures to the surface?

$
0
0

Dear all,

             I am using Microstation v8i Select series 3. I Have tiff image and 3d Polygon surfaces i need to be apply the textures from the tiff image to 3d Polygon surfaces. Frankly i don't know how to do this any one give me the reference.

Thanks & regards,

Karthik M

RE: [CONNECT C++] How do I read EC Units Schema data?

$
0
0
auto attr = unitClass->GetCustomAttribute(L"Unit_Attributes", L"Unit_Attributes"); // schema name, class name
ECValue v;
attr->GetValue(v, L"ShortLabel");
auto shortLabel = v.GetString();

[CONNECT C++] How do I read EC Units Schema data?

$
0
0
<ECClass typeName="YARD" displayLabel="yards" isDomainClass="False"><ECCustomAttributes><Unit_Attributes xmlns="Unit_Attributes.01.00"><Dimension>L</Dimension><UnitSystem>usCustomary</UnitSystem><Label>yards</Label><ShortLabel>yd</ShortLabel><ConversionType>Factor Converter</ConversionType><BaseUnit>METRE</BaseUnit><ConversionFactor>1.0936132983377078</ConversionFactor></Unit_Attributes></ECCustomAttributes></ECClass>

The above EC class for YARD is taken from the Units_Schema.  I can create a C++ ECClass for that fragment, but it has no properties...

ECN::ECSchemaPtr      pSchema;
if (TextPropertyManager::GetUnitsSchema	(pSchema))
{
  ECN::ECClassCP      unitClass  { pSchema->GetClassCP (L"YARD") };
  //    unitClass->GetDisplayLabel ()  == 'yards'
  //	unitClass->GetPropertyCount () == 0

What should I do to obtain the Unit_Attributes sub-elements of that class? For example, I want to know the value of ShortLabel, in this example...

<ShortLabel>yd</ShortLabel>

Viewing all 7260 articles
Browse latest View live


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