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?
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.
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
clr.AddReferenceByName("System.Xml")
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 "_cmd.py"
def RunCommand( is_interactive ):
xml_file = rs.OpenFileName("Please select xml-file to import points (XXXX.xml)")
xdoc = System.Xml.XmlDocument()
xdoc.Load(xml_file)
breaklines = xdoc.GetElementsByTagName("Breakline")
for breakline in breaklines:
# Set up layer and object
attr = breakline.GetAttributeNode("name")
name = attr.Value
layer_name=name
layer=doc.Layers.Add(layer_name,System.Drawing.Color.Yellow)
ObjA=rd.ObjectAttributes()
ObjA.LayerIndex=layer
ObjA.Name=name
# 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)
doc.Objects.AddPoint(pnt,ObjA)
doc.Views.Redraw()
return 0
RunCommand(True)