Page 1 of 1

Finding parent section name and location

Posted: Fri May 03, 2019 10:22 am
by was2be
I want to be able to return the parent section name and location (e.g., "dend[4](0.3)") for any child section. I see the SectionRef documentation (https://www.neuron.yale.edu/neuron/stat ... ecref.html), but don't know how to implement it in hoc. Would like to see a few lines of sample code which would return the parent name and location for any identified child section. Thanks.

Re: Finding parent section name and location

Posted: Sun May 05, 2019 2:59 pm
by ted
This will report the name of the root section, the name of each child section, and the name of the parent and location on the parent to which the child is attached. I assume you will read about any unfamiliar keywords in the Programmer's Reference.

Code: Select all

// usage: reportparents()
strdef str
proc reportparents() { local x  localobj tobj
  forall {
    str = secname()
    tobj = new SectionRef()
    if (tobj.has_parent()) {
//      tobj.parent {print secname(), " is parent of ", str}
      x = parent_connection()
      tobj.parent {print str, " is attached to ", secname(), "(", x, ")"}
    } else {
      print str, " doesn't have a parent"
    }
  }
}