How do I remove-item from list in turtle attributes? - list

I am trying to implement turtles to move along the shortest path. To do this, I want to incrementally remove the first item from the turtles path (which is a list that is part of it's attributes). Below I have presented to simplest version of how I which to do this in a picture of my current model.
Why do I get the 'expected command' error here? According to the documentation I am using the remove-item function correctly.

ask walker 30 [set path remove-item 0 path] is indeed the proper syntax. remove-item 0 path is not. remove-item returns a new list and you must tell NetLogo where to "put" the list that is returned. set path remove-item 0 path tells NetLogo to replace the old path with the new one. Without the set path part, NetLogo doesn't know what to do with the new list.
Actually, this error is quite common for those of us used to languages that allow mutable objects. We might assume replace-item 0 path would simply take the old path list, drop the first item, and that path would thereafter refer to the new list. But, in NetLogo most objects are immutable and it does not allow these items to be changed in place. NetLogo rather requires that the changed (and therefore new) item be assigned to some variable. In this case, you want it to replace the old path, and that is what set path ... does.
By the way, a more economical way of dropping the first item of a list is to use but-first, as in set path but-first path. but-last is useful for stripping the last item.

Related

How to delete duplicate constructed objects in a list while preserving order and returning a List in dart?

I have a list of constructed objects called RecentCard which is basically an object with user id, pic, and name. I have created a list arranged in order of most recent interaction based on timestamp. However i need to get rid of the second occurence and onwards of any duplicated object. I am comparing just the ids since users may have the same name or photo, and i cannot remove duplicates from a simple list of uids because then i could lose the order of corresponding photos and names.
For example the list would look something like this :
List<RecentCard> recentCards= [RecentCard(uid:as721dn18j2,name:mike,photourl:https://sadadasd1d1),RecentCard(.....]
I have searched for solutions but all of them are dealing with like primitive types like simple lists of strings and the solutions didn't work for me. For example this post: How to delete duplicates in a dart List? list.distinct()? Read below
The first answer's link is no longer available, the next answer with sets is something i tried but it simply doesnt work i have no idea why maybe because its not a primitive type. The next answer with the queries package didn't work because i was using the list to build a listview.builder and so when i called list.length it said i couldnt call that on an iterable or something. The final solution wouldn't work because it said String is not a subtype of RecentCard.
I tried using two forloops with the second just comparing first value to the next couple but that doesnt work because if a duplicate is found, the object is removed and the length is messed up so some elements get skipped.
Any ideas? I feel like its very simple but im not sure how to do it.
You have to use Set to store seen cards and then filter away those ones that are already in the set.
final seenCards = Set<String>();
final uniqueCards = recentCards.where((card) => seenCards.add(card.uid)).toList();

Unnable to modify or query image sequence path with token <f> from file nodes

I have referenced node, which path of the texture used is an image sequence:
path\file.< f >.iff (I put it separated so that the editor doesn't change it)
When i do getAttr
texture_path = cmds.getAttr('{}.fileTextureName'.format(file_node))
I get:
path\file.0001.iff
Which is the first image of the sequence. It is not the regular sequence, but it is an animated texture, meaning sometimes it is 0001, other times 0002... etc, depending on an animation curve attached to the image Sequence.
How do I get the generic name set for the texture with the wildcard?
If I edit that attribute, Arnold Render tells me is an invalid token. Seems like there's something else happening underneath.
EDITED:
import pymel.core as pc
obj = pc.PyNode( 'textureFileNode')
obj.fileTextureName.get()
Returns the path without the wildcard also.
Seems like there are hidden attributes not shown in the Attribute Editor. Took me a very long time to figure all this out.
Searching in the code executed to update the path when you activate "Use Image Sequence" checkbox, I found these three attributes:
fileNode.textureFileNode : This is not hidden in the UI but the contents of the field correspond to the contents of the variable if there is no image sequence on this file node. Otherwise, if you query it, it returns the first item of the sequence.
fileNode.fileTextureNamePattern : Contains the path shown in the
Image Path field with tokens. This is the one you should query if you
want the path with tokens. Can be modified.
fileNode.computedFileTextureNamePattern : Contains the maya generated
path with tokens. It cannot be changed!
Modifying fileTextureNamePattern will not change computedFileTextureNamePattern . To change it, you need to force Maya to regenerate it modifying fileTextureNamePattern first, then the attribute textureFileNode (in that order!).
Important: The files should exist in order to let Maya regenerate the third parameter. Otherwise, It will not be changed and a mix of paths will be there until you update the UI by doing some change. If you are writing a batch script, it will be all mixed!
Why is that third parameter important, why not use just the fileTextureNamePattern attribute?
computedFileTextureNamePattern is used by Arnold Render, for example, to generate the ASS file. To get the pattern, the internal algorithm in maya tries to get each of them, the last, the textureFileNode. In general, if maya regenerates the third attribute, the second one is empty after that, so it's a better idea to get the generated one.

Writing value on the current textbox - Selenium

Well I'm facing an issue here:
I use Selenium to automate test on my application, and I use the following code to fill a textbox:
driver.find_element_by_id("form_widget_serial_number").send_keys("example", u'\u0009')
All the textboxes have the same id (form_widget_serial_number) so it's impossible to select a specific textbox by using selection by id (the code above selects the first textbox and u'\u0009' changes the cursor position to the next textbox).
Anyway, how can I send values to the "current" textbox without using find_element_by_id or another selector, given that the cursor is in the current textbox?
There are several selectors available to you - Xpath and css in particular are very powerful.
Xpath can even select by the text of an element and then access its second sibling1:
elem = driver.find_element(:xpath, "//div[contains(text(), 'match this text')]/following-sibling::*[2]")
If you need to find the current element that has focus:
focused_elem = driver.switch_to.active_element
And then to find the next one:
elem_sibling = focused_elem.find_element(:xpath, "following-sibling::*")
Using this example, you could easily traverse any sequence of sequential elements, which would appear to solve your problem.
Take a close look at the structure of the page and then see how you would navigate to the element you need from a reference you can get to. There is probably an Xpath or css selector that can make the traversal across the document.
1 FYI, I'm using an old version of Selenium in Ruby, in case your version's syntax is different
My approach would be:
Get a list of all contemplable elements by the known id
Loop over them until you find a focused element
Use send_keys to write into that element
To get the focused element something like
get_element_index('dom=document.activeElement')
might work. See this question for more information.
Edit: If the list you get from 1. is accidently sorted properly the index of an element in this list might even represent the number of u'\u0009' you have to send to reach that specific element.
Use ActionChains utility to do that. Use following code:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).send_keys("Hello").perform()

Xpath return node relative to another node

I have done a search for all nodes that have an attribute containing (substring) a String. These nodes can be found at different levels of the tree, sometimes 5 or 6 levels deep. I'd like to know what parent/ancestor node they correspond to at a specified level, 2 levels deep. The result for the search only should be much greater than the results for the corresponding parents.
EDIT to include code:
/xs:schema/xs:element/descendant::node()/#*[starts-with(., 'my-search-string-here')]
EDIT to clarify my intent:
When I execute the Xpath above sometimes the results are
/xs:schema/xs:element/xs:complexType/xs:attribute or
/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element or
/xs:schema/xs:element/xs:complexType/xs:complexContent/xs:extension/xs:sequence/xs:element
These results indicate a place in the Schema where I have added application specific code. However, I need to remove this code now. I'm building an "adapter" schema that will redefine the original Schema (untouched) and import my schema. The String I am searching for is my prefix. What I need is the #name of the /xs:schema/node() in which the prefix is found, so I can create a new schema defining these elements. They will be imported into the adapter and redefine another schema (that I'm not supposed to modify).
To reiterate, I need to search all the attributes (descendants of /xs:schema/xs:element) for a prefix, and then get the corresponding /xs:schema/xs:element/#name for each of the matches to the search.
To reiterate, I need to search all the attributes (descendants of /xs:schema/xs:element) for a prefix, and then get the corresponding /xs:schema/xs:element/#name for each of the matches to the search.
/
xs:schema/
xs:element
[descendant::*/#*[starts-with(., 'my-search-string-here')]]/
#name
This should do it:
/xs:schema/xs:element[starts-with(descendant::node()/#*, 'my-search-string-here')]
You want to think of it as
select the xs:elements which contain a node with a matching attribute
rather than
select the matching attributes of descendant nodes of xs:elements, then work back up
As Eric mentioned, I need to change my thought process to select the xs:elements which contain a node with a matching attribute rather than select the matching attributes of descendant nodes of xs:elements, then work back up. This is critical. However, the code sample he posted to select the attributes does not work, we need to use another solution.
Here is the code that works to select an element that contains and attribute containing* (substring) a string.
/xs:schema/child::node()[descendant::node()/#*[starts-with(., 'my-prefix-here')]]

sifr menu list problems, height of object calculated wrong

I am using Drupal and have sifr set on list items, and also a, a:hover are set via Drupal so that the links hover. I looked at the sifr3-rules.js file drupal's render module creates and it looks good. and in fact my other sifr items look fine... But the list item ones are goofing for some reason... There is extra space below the list,
so if i have a list item, and inside of that, I have a unordered list with more list items, the Flash Object made in the 1st li (which will cover the rest of the sublist items too), is too bid so you see space under the children until the next parent li comes up. (so looks like extra bottom padding on that portion of the list in IE8... in FF almost similar but each subitem has space at bottom... with javascript turned off, you see the list items look fine by themselves)....
Also if the parent list item is shorter than the sub list items text, the width for the flash object is set only as long as the first list item, and therefore cuts off the rest the sublist item's text.
Any idea how to resolve any of these?
Only unusual thing i see i am doing is setting forceSingleLine and preventWrap (which dont make a difference if taken off).
****Edit, I may just try to figure out how to get Drupal's menu-block module to output a around my hyperlinks in the list items... then i can target the div's with my rule (and the a,a:hover rules will apply), so each menu item gets its own sifr object instead of sifr3 trying to figure out how to do the lists and sublists.
Very useful to me is anyone knows a way to target a hyperlink (<a> tag) and also allow a:hover rules. I know how to do it with pretend another tag that includes hyperlinks, like if i had <h2><a>sometitle</a></h2>, i could have a rule for h2, but then use the a, a:hover rules in the sifr3-rules.js file to target that. so i would need a way to target the hyperlink in the list, but also apply a :hover to it (not sure if this can be done since its not underneith for example the h2 tag).
I just overrode theme_menu_item
to return ''. $link ."". $menu ."\n"; (so added a div class). and used a sifr rule to target '.mymenu .menu_item'. then a sifr flash object is created for each list item hyperlink but won't try to wrap the whole list (and its sublists) like before. Seemed to fix both problems :)