Hi I am trying to move the linked file to a point xyz using python taken from Moving a linked RVT file along the vector X and Y with Dynamo.
But I am getting this error as shown in the snip. Please help me out for this.
Thanks in Advance
Hi I am trying to move the linked file to a point xyz using python taken from Moving a linked RVT file along the vector X and Y with Dynamo.
But I am getting this error as shown in the snip. Please help me out for this.
Thanks in Advance
Hi again @shashank.baganeACM,
Even though you are feeding the python node a single link, it is still a list with that single link object.
You could flatten the list before feeding the python node.
This is the python code
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
l = UnwrapElement(IN[0])
v = UnwrapElement(IN[1]).ToXyz()
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
OUT = l.Location.Move(v)
TransactionManager.Instance.TransactionTaskDone();
Ah that was gibberish. Sorry, i just woke up
I now see that its not the link input thats failing.
You dont have to unwrap the vector, as it is not a revit object. This wont help with the error though .
Ill probably need to be at a computer to investigate further.
This works fine for me:
import clr
import System
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Import ToDSType(bool) extensions method
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument
#---###Start scripting here:###---#
link = UnwrapElement(IN[0])
vec = IN[1].ToXyz()
#Transaction start:
TransactionManager.Instance.EnsureInTransaction(doc)
OUT = link.Location.Move(vec)
TransactionManager.Instance.TransactionTaskDone()
Mind that you may need to perfom some unit conversion.
Can you share your dyn and a dummy rvt file?
Cool, will take a look a little bit later
The rvt was empty.
Theres a couple of packages i dont have installed, so i just selected the Link manually.
But the python works now.
Move linked file.dyn (36.9 KB)
The reason it went wrong is that rather than feeding the Python a Vector you were feeding it a list containing 1 Vector.
This explains the error given of ‘list object has no attribute ToXyz’ as it is trying to get that value from the list itself rather than the vector in the list.
This can be seen below as the same code reacts differently when instead you feed it just an item:
A more robust way of coding this would be to include a catch on the input to determine whether it is a list or not, putting the item in a list if it is not and then processing the list to get the xyz.
See below:
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
items = IN[1] if isinstance(IN[1],list) else [IN[1]]
l = UnwrapElement(IN[0])
v = [i.ToXyz() for i in items]
OUT = v
Hope that helps
Thank you so much @haganjake2 I got the solution. Yes you were right I was feeding list.
Thank you @MartinSpence @haganjake2