i have an item type that contains a property. this property has Is Array set to true and its type is a custom property type that i made.
trying to figure out how to add a value to this array property.
Not seeing it in the sdk. i see there is a XmlStringValue that is a get/set. but when i try to set it, it just crashes. assuming i cant use that to add a new value to an array but could use it to change existing values??
Anyways anyone see a way to do this. i hope im just missing it.
EDIT:
adding some code that i have, the array property is named Values, the custom type is named linker. the custom type contains several string properties...
CustomItemHost host = new CustomItemHost(Views.LinkSetup._MainWindowViewModel.selTextElement, false); IList<BD.DgnEC.IDgnECInstance> ItemTypes = host.CustomItems; //loop each itemtype attached to element foreach (BD.DgnEC.IDgnECInstance curItemType in ItemTypes) { //find item type with specfied name if (curItemType.ClassDefinition.Name.ToUpper().Contains(Globals.itemTypeName.ToUpper())) {//found, update //find array property (its named Values) foreach (var curprop in curItemType) { if (curprop.Property.DisplayLabel.ToUpper() == "VALUES") { //add entry to values array //stuck on how to do this.. //try and modify xml string to add another value to the VALUES propety (which is a custom propety tyoe named linker) string newxmlstring = curprop.XmlStringValue; newxmlstring.Replace("</Values>", ""); newxmlstring += "<linker><isFromReference>False</isFromReference><ElementID>5</ElementID><ModelName>f</ModelName><PropertyName>df</PropertyName><FilePath>test2</FilePath><PropertyType>Element</PropertyType><PropertyValue>df</PropertyValue><AccessString>afsdfdfasf</AccessString><ItemTypeName /></linker></Values>"; //causes crash curprop.XmlStringValue = newxmlstring; } } } }
i was thinking i would need to get the custom property type and populate it with what i want, then add it as a value to the item type property. but see nothing in the SDK for this...i starting to do this to get the property type...
BD.ItemTypeLibrary OHDOTLinkersLib = BD.ItemTypeLibrary.FindByName(Globals.itemTypeLibName, activeFile); BD.ItemType it_TextFieldLinker = OHDOTLinkersLib.GetItemTypeByName(Globals.itemTypeName); BD.CustomProperty itProp = it_TextFieldLinker.GetPropertyByName("Values"); BD.CustomPropertyType itPropType = OHDOTLinkersLib.GetCustomTypeByName("linker");
wow i cant believe i forgot to use .WriteChanges() on my item type to apply the changes...ugh that was stupid my code above works.
Hi John,
John Drsek said:wow i cant believe i forgot to use
Welcome to the club! :-))) ... such things happen every day
John Drsek said:here is my code
The code looks a bit weird to me, even when I guess functional (when WriteChanges() is used). Maybe it's only because of using full classes names including namespaces (which I treat as very bad habit personally). But e.g. to use DisplayString to evaluate anything is wrong idea generally.
Not sure whether I will find enough time, but I should think whether better code (whatever it means) can be written.
John Drsek said:So im remaking that for CONNECT and thought text fields and item types would be easier.
I agree. Not because of text fields and item types specifically, but because of using standard MicroStation features.
And item types are always good, because when not sufficient, can be extended to general EC data, that can handle ... anything ;-)
John Drsek said:basically i want to do exactly what a text field does.
Well, you can ... but you can't. The text fields background is (I guess) really complex, implemented using more other technologies (DependencyManager at the first case), so to achieve the same functionality is about to use C++ (NET is not enough) and many months of work. But it's probably not your aim in fact.
John Drsek said:so i dont actually have to edit the text element itself to update the value.
This behavior makes the whole solution much (much much much) easier :-)
John Drsek said:hopefully that made sense
Yes, it does :-)
Of course when I read your explanation, some questions arose, but the main idea is fine I think.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
John Drsek said: i want to do exactly what a text field does
The API for text and text node elements in CONNECT revolves around the TextBlock class. The C++ MicroStationAPI provides TextBlock.InsertField() etc., but I don't see those methods in the DgnPlatformNet .NET API.
TextBlock
TextBlock.InsertField()
File a request to have the .NET TextBlock expanded to include TextField manipulation.
John Drsek said:all the app needs to do to update the values is to just update the item type value and the text field will automatically get updated
Correct! Unfortunately, C++ is again ahead of .NET. The MicroStationAPI provides the TextField class, but I can't find that in the .NET documentation (but that could be me — I often fail to find things in the multi-file .NET documentation).
TextField
File another request to have the TextField included in .NET.
Jan Ĺ legr said:the main idea is fine I think
I agree with Jan, but you're hamstrung by deficiencies in the .NET API.
Regards, Jon Summers LA Solutions
Jan Ĺ legr said:The code looks a bit weird to me, even when I guess functional (when WriteChanges() is used). Maybe it's only because of using full classes names including namespaces (which I treat as very bad habit personally).
i dont normally use full namespaces but when i post code i copy the part and edit it up to either show the using statements or add in the full namespaces to help other users. i guess i could also add what dll they are coming from to be complete. Also this code was after 2 hours of trying many different ways of doing the same thing trying to get it to work so it got a little messy in my frustration (until i remembered the write changes). i have since cleaned it up a little bit.
Jan Ĺ legr said:But e.g. to use DisplayString to evaluate anything is wrong idea generally.
i just gravitate towards the display string because i normally try to write the app as dynamic as i can so others can apply it. so ill have the app read a config variable to get names of things like item types. and its easier for others to use the name they see in their item types when setting the config variable. I still have a validation method to ensure the found item type meets the min. requirements. so i see what your saying but i think i built in enough safe guards to use it. so i hardcoded some text with i will be reading in instead in the final app.
Jan Ĺ legr said:The text fields background is (I guess) really complex, implemented using more other technologies (DependencyManager at the first case), so to achieve the same functionality is about to use C++ (NET is not enough) and many months of work. But it's probably not your aim in fact.
yeah i have figured that out. i had another post where i posted my c++ function exported to C and then wrapper in c# to just add the text field.for now thats all i need.
as always thanks for your input
Jon Summers said:Correct! Unfortunately, C++ is again ahead of .NET. The MicroStationAPI provides the TextField class, but I can't find that in the .NET documentation (but that could be me — I often fail to find things in the multi-file .NET documentation). File another request to have the TextField included in .NET.
Correct! Unfortunately, C++ is again ahead of .NET. The MicroStationAPI provides the TextField class, but I can't find that in the .NET documentation (but that could be me — I often fail to find things in the multi-file .NET documentation).
yes i had to export a c++ function to c and then wrap it in C# to add a text field, it was a pain but got it working. thats all i need for now. didnt even try to figure out how to enter the field to a specific spot..maybe version 2.
i can put in a S.R. for get it added. last time i submitted a defect on an api call can was told all SDK related stuff should be posted to the communities.
John Drsek said:Last time I submitted a defect on an API call can was told all SDK related stuff should be posted to the communities
Others have implied that to summon Robert Hook is our best (and possibly only) recourse. Prepare a pentagram and light candles.
Jon Summers said:Prepare a pentagram and light candles.
Maybe also to make a floral sacrifice and to do some invocation? :-)
Regards,
Enhancement # 1040579
has been filed to add textfield to .net