Is there a way to link a custom property value to a Mtext content? - ezdxf

I would like to link the value of a custom property to the contend of a specific Mtext.
Here's what I got so far:
i = 0
while(i<len(Cpro)):
doc.header.custom_vars.append(Cpro[i][0],Cpro[i][1]) # creating new custom properties list
i = i+1
Number = doc.header.custom_vars.__iter__()
for e in Number:
print(e)
I can get the whole list printed and even used to fill an MText(but the text is not linked to the Property value, it's only a copied string). But the goal is to set it in a way that the user of the dxf generated could change the Mtext contend by only changing the custom property value.
On BrisCAD you can use the "Field" command to choose one the custom properties to fill the text.

Related

Django - How to check multiple variables in the view or in the template

I have a site that the user selects a drop-down menu item, inputs some JSON, and then clicks "Parse". Then the JSON data is checked against certain properties based on the drop-down menu item. Basically I have a list that looks like this.
myList = [{'Prop1': ['asdf', 'wefef']}, {'prop3': ['ss']}, {'prop2': ['d']}]
This is all the data I am checking against. It is the property name and then a list of expected values for that property name. Then in the JSON I have to compare those properties against the JSON properties in the list above.
Right now I am not sure where the best way to go about checking these. Should I do it in my views.py or should I do it in the page.html?
Basically I will need to look through myList and check if that property is in the JSON. If so then I need to check it against the expected property. And then I need to print things in a row so that you can view the info like:
Property Excepted Value Actual Value P/F
prop1 asdf, wefef apple F
prop2 d d P
prop3 ss sd F
My issue is, this will be a bunch of logic to build out to parse correctly. I am new to Django and not sure if the amount of code should be done in the HTML file. Else, I would need to build a large string in the views.py that contains all the data and the HTML, then pass to the HTML file and just display a single variable that displays all the data.
It is a good practise not to put too much logic in your page.html - it should just display your data. Therefore, put the logic into your view.
It also has the advantage that you can test the functionality way easier.

How can I define each case of the choice list in a uitable (GUI) and put IF function for each one?

I made a matlab gui that have two uitables, one of them have choice list format on its cells but I dont know how define each case of choice list and put IF function for each one. In other words I want apply numbers to second uitable from another gui with dependency on cases in the choice list of first uitable.
I assume that you use guide to manage your GUI, and that you already have created a uitable with a column in the format of a choice list, and that you have set the ColumnEditable property to true. Is that the case?
Then, create a CellEditCallback function by right clicking on the uitable in the guide window and select "View Callbacks" -> "CellEditCallback". This will create the callback function if it doesn't exist so far.
The automatically created callback function could look like this:
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
In this case, the tag of the uitable is uitable1. If your uitable has a different tag, the function name will be according to that tag.
Now, write your if block into this callback function. For example, if the choice list that you want to query is in the first row and first column of your uitable, and you want to check if the selected text of the decision box is "blabla", then your code would look like this:
if strcmp(handles.uitable1.Data{1,1}, 'blabla')
% put here the code that you want to execute if the user selects 'blabla'
end
Hope it helps ...

How to obtain field values from a sitecore droplist used as a predefined list

In my template I have a field type of Droplist which maps to a Sitecore folder holding values for the Droplist which in this case is Colours. This is so that an editor cannot make a typo or invent a colour this is not in the pre-defined list.
So that colour is based off a template I call TAGS which has a single field type of 'colour' and here I create a series of items using that template to create the colours for the swatch list.
When I access the main template I duly see the colour values in that Droplist so its working as I would expect it because I can access that fields values:
tileValues.Attributes["class"] += " tile-" + Item.Fields["Tile Colour"].Value.ToLower();
However I have realized its not using the field value of the template but rather the name I have called the item. SO its just a happy mistake that its achieving the result I wanted.
However how would I obtain the actual field value for that item in the end code. I have scenarios where there will be multi lingual editors so we may name the tags as rouge, blanc etc which is what the editor will see on selection in the Droplist but we need the colour value of the field to still say red or white etc
I tried:
Item.Fields["Tile Colour"].Item.Fields["Colour"].Value
But this failed despite the API hint implying its valid.
I hope this makes sense and someone can help me obtain the actual field value and not the items name.
As Sitecore Climber wrote, don't use Droplist field type - it stores item name only and you cannot get the item itself in the code behind.
Use Droplink field type - it stores ID of the item.
Then you can get the item:
Item colourItem = Sitecore.Context.Database.GetItem(Item["Tile Colour"]);
if (colourItem != null)
{
string colour = colourItem["Colour"];
|

Sitecore TreelistEx used as a UI for multi-link layouts

I need to present a content editor interface that allows editors to select specific pages in order to generate a link list for website visitors.
It seems treelist/treelistEX is providing the expected interface and I have combined that with a source path to lock the editors to a start destination rather than the entire sitecore tree. Opted for treelist EX as this appears to be the most efficient way as it doesnt render the tree in full each time unless its called upon.
In terms of the output however I'm getting a pipe separated list of GUIDs- is this something I need to iterate through manually using linkmanager or some such to obtain the items title and its sitecore link? Or is there an existing process that manages such a multi-list and breaks it up into its components.
If anyone can provide an example of that code and how to draw out the title and URL that would be great.
Thanks
There is no built-in solution for getting title and url from the items selected in Treelist.
You can treat your Treelist field as a Multilist field (they both store just list of pipe separated IDs in the background) and use GetItems() method:
Sitecore.Data.Fields.MultilistField treelistField = Sitecore.Context.Item.Fields["myTreelistFieldName"];
Item [] selectedItems = treelistField.GetItems();
foreach (Item item in selectedItems)
{
string itemName = item.Name;
string displayName = item.DisplayName; // fallback to Name if not set
string title = item["Title"]; // assuming there is a field called Title
string url = LinkManager.GetItemUrl(item);
}

Sitecore 6 - how to store html-formatted text and reference in codebehind

I would like to be able to store reusable html-formatted text in Sitecore and reference in codebehind for inclusion in a custom user control. What is the best practice for doing this? If a user selects option A, for example, I would reference standard text A in my control. Any examples for how to accomplish this are appreciated. Thanks.
You have a couple options:
Store the text in the Standard Values of the same template that defines your option list. That makes it available on the same item, but standard for all items. Use security to lock down the field if you are worried about it being edited. This could also be accomplished with the new "cloning" feature in 6.4, I believe.
Create a structure outside of your Home element for storing this data. Based on the option selected, find an item in your content tree which corresponds to the selected item, and read the text off of it. You would need to find this item either relative to /sitecore/Content, or relative to your website root if multi-site support is a requirement.
No.2 in pseudo-code:
//get the item where we have the text values
Item textBase = Sitecore.Context.Database.SelectSingleItem(textBasePath);
//find the child w/ the same name as the selected option
Item textItem = textBase.Axes.GetChild(selectedOptionValue);
string value = textItem["text"];
I think I would do something like techphoria414's 2. option:
ie you have your normal "page" templates as per usual, but then you have some fields (multilist, treelist fields), where you put the source pointing to your other items contain the different texts.
then you basically just have to get the items from the current item (with some very quick'n'dirty code/pseudocode):
var CurrentItem = Sitecore.Context.Item;
Sitecore.Data.Fields.MultilistField mlf1 = CurrentItem.Fields["myExternalTexts"];
if(mlf1 != null)
{
foreach (Item itm in mlf1.GetItems())
{
lit += Sitecore.Web.UI.WebControls.FieldRenderer.Render(itm, "richtext");
}
}
You ofc shouldn't just add them to a literal and you should you Sitecore built in Field renderes if using Sitecore 6 or above and it's a Rich text field.
I hope that helps.