Cannot Unwrap Current View - AttributeError: 'str' object has no attribute 'Id'

Hello everyone, I am a noob in python and dynamo but i want to make the most of everything.
(don’t know if this would make it worse but for what it’s worth i do have some basic Java knowledge…)

I found some Python scripts which would make my life a whole lot easier - they create a wire between 2 devices(connectors) following the vertices taken from some detail lines.

Thing is the “create wire” constructor also takes a “viewId” in the parameters list.
So i feed the current view (as done so by the guys in the above mentioned link), which in the Python script is to be unwrapped…and this is where the error shows.

this is the line, no. 42:
viewid=UnwrapElement(IN[1]).Id

sounds / looks pretty straight forward… i feed the current view, it has a valid ID… so why does this happen?

Actually the constructor for C# says “ElementId viewId” - i also tried supplying the ID of the view directly, strangely enough the error is the same, no matter if I add another line the error is still on line 42. (how/what/where???)
*I read that you need to unwrap stuff in order to be able to use it as Revit stuff, and work with Revit API methods so i guess that’s why feeding the view ID directly does not work?

I don’t feed a “str(ing?)” i feed a the current view… which definitely has an “Id” variable.

This is the whole script, copied from the link above, line 42 in bold:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('System')
from System.Collections.Generic import List

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)


clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)


clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB.Electrical import *
import System

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *


wiretypeid=UnwrapElement(IN[0]).Id
viewid=UnwrapElement(IN[1]).Id
wiringtype= UnwrapElement(IN[2])
verpt= UnwrapElement(IN[3])
sconn= UnwrapElement(IN[4])
econn= UnwrapElement(IN[5])

verptxyz=[]
for v in verpt:
	verptxyz.append(v.ToXyz(True))

TransactionManager.Instance.EnsureInTransaction(doc)

errorReport=[]
try:
	wireN=[]
	wireN.append(Autodesk.Revit.DB.Electrical.Wire.Create(doc,wiretypeid,viewid,wiringtype,verptxyz,sconn,econn))
	OUT = wireN
except: 
	import traceback
	errorReport = traceback.format_exc()
	OUT = errorReport
TransactionManager.Instance.TransactionTaskDone()

And this is a picture of the entire graph, with the error, wire c# constructor, my tries…

I can only hope this is the only error that is keeping this script from running and saving my life :smiley:

Hello @bogdan.petrescu63URX
check the line 41, it looks like you are a string instead of an element.
Note:
there is a small bug on the traceback (the line indicates corresponds in fact to the previous line in Dynamo 2.3) the bug is fixed on later versions of Dynamo

@c.poupin : You are a lifesaver!!!

i was picking indeed a string…stupid me. :smiley:

i am really embarrassed… maybe this topic can be deleted?..
really useful stuff to know the error was referring to the previous line.