pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.33k stars 337 forks source link

CPython - IronPython Differences #777

Closed DaveMalek closed 4 years ago

DaveMalek commented 4 years ago

Hi All,

I am new to programming and I am trying to create an extension using pyrevit. Well, I need to use numpy for a part of this extension so I am using new CPython engine. The first issue that I have encountered is that I used to define points like this (in IronPython): point = XYZ(1,1,2)

but now (using CPython) when I am using the exact same thing as above and print the point, it always give me (0,0,0).

The codes are pretty simple, you can see them below:

####################### in IronPython:

from Autodesk.Revit.DB import* print(XYZ(0,1,0))

######################## in CPython:

! python3

from Autodesk.Revit.DB import* print(XYZ(0,1,0)) # this gives me (0,0,0) !

Any help would be much appreciated. Thanks, Dave

vengelhard commented 4 years ago

Hi,

I experienced the same for CPython when I was trying to create an instance of the TopographySurface class. I'd like to use pandas for fast data operations on an external points file (user input). Therefore it would be great if the XYZ class would also work correctly with CPython.

Is there any news about that issue? I'm doing my master thesis in Revit automation relying on pyRevit. So I would be very happy to know about how to solve this or if there is any work-around.

Thank you so much, Verena

Update Actually there were two things that I did wrong. If anybody's interested in, here's the solution. In order to try both, IronPython and CPython, I didn't import pandas, instead I used for-loops. Find the code below (the right one which works).

  1. Instead of obj = XYZ(point[0], point[1], point[2]) I previously wrote obj = XYZ(point) which works for CPython and gives the result of all coordinates being zero, whereas for IronPython this completely fails.

  2. You have to create the dotnet list manually. I found the hint in issue #685. So TopographySurface.Create(doc, topo_points) is the right way for CPython and not TopographySurface.Create(doc, points) which only works for IronPython.

#! python3

# for creating an IList using CPython
from System.Collections.Generic import List 

# autodesk modules
from Autodesk.Revit.DB.Architecture import TopographySurface
from Autodesk.Revit.DB import Transaction, XYZ

doc = __revit__.ActiveUIDocument.Document
trans = Transaction(doc)

# list of coordinate tuples e.g. snippet
pre_points = [
    (9.4926, 32.604, -10.5),
    (9.5025, 32.58, -10.5),
    (9.4989, 32.549, -10.5),
    (9.4684, 32.287, -10.5),
    (9.4633, 32.218, -10.5), 
]

# create list of 3D Revit point objects
points = []
for point in pre_points:
    obj = XYZ(point[0], point[1], point[2]) 
    points.append(obj)

# manually create the dotnet list
topo_points = List[XYZ]()
for point in points:
    topo_points.Add(point)

# start a transaction
trans.Start("Create topography from point cloud")
TopographySurface.Create(doc, topo_points)
trans.Commit()
eirannejad commented 4 years ago

@vengelhard I tested your script in ironpython 277 and python 372 engines and I get the exact same results

Screen Shot 2020-03-16 at 09 10 55 Screen Shot 2020-03-16 at 09 11 47

Not sure what the issue is here

vengelhard commented 4 years ago

@eirannejad Thank you for your reply. The script I posted is already meant to be the solution. So... I'm happy that it works also for you. In section Update I described what I did wrong and how I resolved this. Before, I didn't manually create a .NET list in CPython which IronPython does automatically. Also I passed one coordinate tuple to XYZ class instead of three coordinate values (just wondering about why I was thinking that this would work). Almost sure that DaveMaleks result was caused by something else. Thanks again Ehsan!

eirannejad commented 4 years ago

@vengelhard You are most welcome and thanks for sharing your answer/script here :)

arielsemik-warbud commented 3 years ago

Hi, in my example this result dont work. for example XYZ(1,0,0) dont work

but I find resolved

XYZ(1.0, 0.0, 0.0) - it works