Python script works differently on Rhino WIP and Rhino 6

Hi to all,

I just tried my Python script (written for Rhino 6) in Rhino WIP and it does not work properly.
It is script for reading xml file generated in Bentley Microstation. Script read all points coordinates in written in xml and generate points in rhino. However, it seems that some parts of coordinates are left out in Rhino WIP. Any suggestions?

Thanks for any kind of reply.

Ondřej (1.4 KB)

DTM usek SO203.xml (148.2 KB)

Hi @janotaondrej91,

If you add some print statements to your script, you’ll see that, when split one of the xml’s PntList3D, the resulting array is not evenly divisible by 3. Basically, the list is short one z coordinate.

– Dale

I came up with that too, at about the 65th point, but why does V6 get through that and V7 not?

Yeah I don’t know. Much much Rhino involved in the string parsing.

– Dale

@Alain - any thoughts here?

For some reason the third <Breakline> isn’t read completely. The length of the list I get is 340, but there are 768 numbers in it.

Interesting is that when I copy the text of the breakline “vozovka osa” into a python script and split that I get the expected 768 items.

I don’t know why this happens though.

I’m guessing a bug in ElemenTree. Here a version of your script using System.Xml:

import Rhino.Geometry as rg
import System.Guid, System.Drawing.Color
from scriptcontext import doc
import Rhino.DocObjects as rd
import rhinoscriptsyntax as rs

import clr


import System
import System.Xml

__commandname__ = "Read_XML2"

# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus ""
def RunCommand( is_interactive ):
    xml_file = rs.OpenFileName("Please select xml-file to import points (XXXX.xml)")
    xdoc = System.Xml.XmlDocument()
    breaklines = xdoc.GetElementsByTagName("Breakline")
    for breakline in breaklines:
        # Set up layer and object
        attr = breakline.GetAttributeNode("name")
        name = attr.Value
        # load and create points 
        points = breakline["PntList3D"].InnerText.strip().split()
        for z in range(int(len(points)/3)):
            px = float(points[3*z])
            py = float(points[3*z+1])
            pz = float(points[3*z+2])
            pnt=rg.Point3d(px, py, pz)
    return 0
RunCommand(True) (1.4 KB)

Thank you very much guys. I will go with the System.Xml

Thanks a lot, this forum is miracle. :smiley: