I have problem with setting scale for linestyle in c#. If anyone found working solution please share it.
So far I tried to use ElementPropertiesSetter SetLineStyle function because this function takes LineStyleParameters as param but i can't create LineStyleParameters because it does not have constructor.
I tried to get LineStyleParameters from ElementPropertiesGetter and I get some but I can't change Scale for that object, it stays unchanged after lineStyle.Scale = scale.
Damian Holubowski said:but i can't create LineStyleParameters because it does not have constructor.
When you will check documentation carefully (and e.g. will evaluate classes dependencies), you will find that LineStyleParameters are part of element display parameters, so they have to be obtained from there. In this situation the constructor makes no sense, because display parameters exists only when element is is displayable. And some parameters (as LineStylesParameters for example) exist only in certain situations, like when linear element has line style assigned.
Damian Holubowski said:I can't change Scale for that object, it stays unchanged after lineStyle.Scale = scale.
My feeling is that it does not work. I do not know whether it's a bug in API implementation or wrong code is used, but even with LineStyleParameters existing, it does not work for me (but maybe I did something wrong).
Damian Holubowski said:I don't know how this "byLevel" feature works.
It's crucial MicroStation (and also AutoCAD) feature, so this knowledge is mandatory, because represented in many aspects of MicroStation API.
Damian Holubowski said:I need to set this value codebehind:
Because I can see this value (LSScale) in EC schemas delivered with MicroStation, it should be accessible as element's EC property. And because it's not defined as read-only, I am pretty sure you can change it this way (which is popular and common workaround when a feature is not accessible or not work in API ;-)
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
If you provided a code with an example of using EC property, I would be grateful.
Damian Holubowski said:Any tip what I am doing wrong?
I guess you are searching for wrong class name, but without some debugging, it's hard to say.
But you choose, in my opinion, the most complicated way. To use ECQuery is powerful, but it requires to know exactly how ECQuery works (not very intuitive, because more graph than query) and also the structure of queried data. The problem is that hide complex logic, so when anything is wrong, it's usually not simple to find out what.
Even when maybe less efficient, to use DgnECManager.GetElementProperties() is far simpler. Moreover, it allows easily understand, what EC classes and properties are available at specific element. Sometimes there is even no reason to rewrite code to ECQuery later, because it "just work".
The only disadvantage of GetElementProperties (but it can be applied to all EC API) is a requirement to cast values to proper data type to access relevant methods. But it's common problem of OOP, when interfaces and inheritance is used. In the discussed case, everything is IECPropertyValue, but individual items can be containers like structures or arrays. But, fortunately, every IECPropertyValue knows what type it represents ;-)
Using GetElementProperties microstation crash on "scaleParam.DoubleValue = scale" line.
using (var ecInstances = DgnECManager.Manager.GetElementProperties(element, ECQueryProcessFlags.SearchAllClasses))
var instance = ecInstances.Where(x => x.ClassDefinition.Name == "LineElement").FirstOrDefault();
if (instance != null)
var lsParams = instance.GetPropertyValue("LineStyleParams");
if(lsParams != null)
var scale = Util.GetScale(dgnModel);
var scaleParam = lsParams.ContainedValues.Where(x => x.Property.Name == "LSScale").FirstOrDefault();
if(scaleParam != null)
scaleParam.DoubleValue = scale;
Damian Holubowski said:Using GetElementProperties microstation crash on "scaleParam.DoubleValue = scale" line.
And? You are developer and author of the code. What analysis you did? What exception is thrown?
Maybe you should not overuse var keyword, that hides real types. Right now, I do not see any option how your code can be discussed, because it's not clear what LINQ returns.
When it's something like IECPropertyValue, to set the scale should work.
Another test, before anything is changed, should be to evaluate whether line style scale can be read and whether the value is correct (when compared with thew scale available in Element properties dialog.
As Jan suggested, please make sure you are able to update property value using property pane.
Also, can you please share "Exception.log" & "MiniDump". And, let us know what Util.GetScale() is returning.
Also, try simple line without named group.