I try to create line using coordinate but it show these error AttributeError: 'type' object has no attribute 'CreateBound'

These is code I used to get coordinate

# Load the Python Standard and DesignScript Libraries
# Import Common Language Runtime
import clr
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

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

import System
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(number1, number2, number3, number4, number5, number6, number7):
    x1 = number1
    y1 = number2
    z1 = number3
    x2 = number4
    y2 = number5
    z2 = number6
    nx1 = number1 + number7
    count = 0
    while (count < 2):
	    pt1 = XYZ(x1, y1, z1)
	    pt2 = XYZ(x2, y2, z2)
	    pt3 = XYZ(nx1, y1, z1)
	    pt4 = XYZ(nx1, y2, z2)
	    y1 = y1 + number7
	    y2 = y2 + number7
	    count = count + 1
	    mylist.append(pt1)
	    mylist.append(pt2)
	    mylist.append(pt3)
	    mylist.append(pt4)
	
num1 = IN[0]
num2 = IN[1]
num3 = IN[2]
num4 = IN[3]
num5 = IN[4]
num6 = IN[5]
num7 = IN[6]

mylist = []

result = line(num1, num2, num3, num4, num5, num6, num7)

OUT = mylist

Which I successfully build loop creation of pt but when I try to add create line into these loop function to looping create line but it shown error AttributeError: ‘type’ object has no attribute ‘CreateBound’. However, I have been searching for command used to create line by coordinate even RevitAPIdoc give me these scripts

Line1 = Line.CreateBound(pt1, pt2);

So I try to insert these line of code into my while loop as follow

# Load the Python Standard and DesignScript Libraries
# Import Common Language Runtime
import clr
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

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

import System
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(number1, number2, number3, number4, number5, number6, number7):
    x1 = number1
    y1 = number2
    z1 = number3
    x2 = number4
    y2 = number5
    z2 = number6
    nx1 = number1 + number7
    count = 0
    while (count < 2):
	    pt1 = XYZ(x1, y1, z1)
	    pt2 = XYZ(x2, y2, z2)
	    pt3 = XYZ(nx1, y1, z1)
	    pt4 = XYZ(nx1, y2, z2)
                line1 = Line.CreateBound(pt1, pt2)
                line2 = Line.CreateBound(pt3, pt4)
	    y1 = y1 + number7
	    y2 = y2 + number7
	    count = count + 1
	    mylist.append(pt1)
	    mylist.append(pt2)
	    mylist.append(pt3)
	    mylist.append(pt4)
	
num1 = IN[0]
num2 = IN[1]
num3 = IN[2]
num4 = IN[3]
num5 = IN[4]
num6 = IN[5]
num7 = IN[6]

mylist = []

result = line(num1, num2, num3, num4, num5, num6, num7)

OUT = mylist

My target is to repeat create 2 line for each time while loop looping but it keep notice me of these error AttributeError: ‘type’ object has no attribute ‘CreateBound’. Did I forgot to import some function?

Hello @somphon
you have a conflict between 2 namespaces (Revit API , and Dynamo Proto API)

remove this if you don’t use it

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

or use an alias

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#.... // ...

Line1 = DB.Line.CreateBound(pt1, pt2)
2 Likes

Thank you for reply I really appreciate and I have a bit curiosity because I tried ur suggestion and it successfully run without any error but instead I didnt saw graphical line drawing on my dynamo screen these is my code after I made an adjustment about namespace conflict.

# Load the Python Standard and DesignScript Libraries
# Import Common Language Runtime
import clr
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

import System
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(number1, number2, number3, number4, number5, number6, number7):
    x1 = number1
    y1 = number2
    z1 = number3
    x2 = number4
    y2 = number5
    z2 = number6
    nx1 = number1 + number7
    count = 0
    while (count < 2):
	    pt1 = XYZ(x1, y1, z1)
	    pt2 = XYZ(x2, y2, z2)
	    pt3 = XYZ(nx1, y1, z1)
	    pt4 = XYZ(nx1, y2, z2)
	    line1 = DB.Line.CreateBound(pt1, pt2)
	    line2 = DB.Line.CreateBound(pt3, pt4)
	    y1 = y1 + number7
	    y2 = y2 + number7
	    count = count + 1
	
num1 = IN[0]
num2 = IN[1]
num3 = IN[2]
num4 = IN[3]
num5 = IN[4]
num6 = IN[5]
num7 = IN[6]

mylist = []

result = line(num1, num2, num3, num4, num5, num6, num7)

OUT = line

It turn out that result said IronPython.Runtime.Pythonfunction. I have no idea what is mean. Im actually plan is to used this curve to later create rebar by curve.

@somphon
a few comments

  • your function return null, you need to use the “return” keyword to return a result (instead of using global variable)
  • Try to avoid not reassigning multiple variable names for the same reference
  • To convert Revit geometry to Dynamo geometry, you will find very useful information here https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration

an example with your code

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

import System
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(x1, y1, z1, x2, y2, z2, increment):
	outLine = []
	nx1 = x1 + increment
	count = 0
	while (count < 2):
		pt1 = XYZ(x1, y1, z1)
		pt2 = XYZ(x2, y2, z2)
		pt3 = XYZ(nx1, y1, z1)
		pt4 = XYZ(nx1, y2, z2)
		line1 = DB.Line.CreateBound(pt1, pt2)
		outLine.append(line1)
		line2 = DB.Line.CreateBound(pt3, pt4)
		outLine.append(line2)
		y1 = y1 + increment
		y2 = y2 + increment
		count = count + 1
	return outLine   
	
NumX1 = IN[0]
NumY1 = IN[1]
NumZ1 = IN[2]
NumX2 = IN[3]
NumY2 = IN[4]
NumZ2 = IN[5]
increment = IN[6]


result = line(NumX1, NumY1, NumZ1, NumX2, NumY2, NumZ2, increment)

OUT = [x.ToProtoType() for x in result]
2 Likes