Hello,
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.
Regards.
Hi Damian,
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 ;-)
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
If you provided a code with an example of using EC property, I would be grateful.
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.
Thanks,
Mangesh
Yes, scaleParam is IECPropertyValue:
But when I want to set value for this object i receive this msg from visual studio:
Microstation crash and code don't even catch this exception. All freeze and I must kill Microstation process.
I pasted code because maybe I do this wrong way and maybe there is other way to set LSScale value.
I get instance of LineElement ECClass, then I get IECPropertyValue of LineStyleParams param and LineStyleParams Contains LSScale.
Damian Holubowski said:Microstation crash and code don't even catch this exception.
It's because the exception is not thrown by code, but by MicroStation itself.
Damian Holubowski said:I pasted code because maybe I do this wrong way and maybe there is other way to set LSScale value.
When you received IECPropertyValue, it should be fine. In this case there is also no problem with LINQ, that is some situations (if I remember right) returns, because of its functional implementation, copies instead of original data.
So the problem should be somewhere else.