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.
One more comment: Maybe var and LINQ look cool, but (as I wrote earlier) do not help to understand whether the code is right or not. Plus, LINQ often adds substantial overhead (inefficiency) under the surface.
I think something like this is simpler to check and debug:
using (DgnECInstanceCollection collection = DgnECManager.Manager.GetElementProperties(lineString, ECQueryProcessFlags.SearchAllClasses))
private bool IterateInstances(DgnECInstanceCollection instances)
foreach (IDgnECInstance instance in instances)
foreach (IECPropertyValue ecProperty in instance)
if (ecProperty.AccessString == "LineStyleParams")
IECPropertyValue scaleProperty = (ecProperty as IECStructValue)?.GetPropertyValue("LSScale");
if (null == scaleProperty)
scaleProperty.DoubleValue = 2.468;
It gives me the same result as LINQ, crash at setting scaleProperty.DoubleValue. I think at this moment I will let go this way. I found a way to scale line using transformation but it scale whole line, length too what is not what i want but then I recreate element using transformed one as a template.
If any1 would need it, it looks like this:
LineElement el = new LineElement(dgnModel, null, segment);
DTransform3d transform = DTransform3d.FromUniformScaleAndFixedPoint(segment.FirstPoint, scale);
TransformInfo info = new BNET.TransformInfo(transform);
el = new LineElement(dgnModel, el, segment);
Damian Holubowski said:It gives me the same result as LINQ, crash at setting scaleProperty.DoubleValue.
The code I posted works fine (and probably yours based on LINQ too). I used this approach to set different aspects many times.
So something else, not shared / discussed is causing the problem. Can you share DGN test case with the element you want to change the line style scale? There can be some tiny reason: I tested it on element, created manually (so identified by its ID), that exists in the design file already, not encapsulated in other data structure (e.g. inside cell or complex shape).
My element is not added to model yet so maybe this is the problem?
But ECProperty reads scale value properly, after my tranformation method it reads new scale.
I need to set scale before I add it to model anyway because I use PrimitiveTool Dynamics and RedrawElems to preshow element.
Damian Holubowski said:My element is not added to model yet so maybe this is the problem?
Yes and no.
The access through EC properties, when display parameters are queried, seems throwing exception, when element does not exist in model yet. I guess it's not bug in EC, because Element.GetElementDisplayParameters() does not read line style info correctly also.
So I guess we are back at the discussion beginning: How to use ElementPropertiesSetter, because when it's used (in dynamics, when element exists in memory only), it works fine:
ElementPropertiesSetter setter = new ElementPropertiesSetter();
... but the question is how to obtain LineStyle value (probably from LSMap somehow).
Damian Holubowski said:But ECProperty reads scale value properly, after my tranformation method it reads new scale.
The transformation looks like overkill to set the line style scale only ;-)
The problem, at least what I see in my VisualStudio, is that ECProperty is read properly, but to access its value throws exception.