NewSpotCoordinate in python

NewSpotCoordinate in python

Ysuuny
Contributor Contributor
978 Views
5 Replies
Message 1 of 6

NewSpotCoordinate in python

Ysuuny
Contributor
Contributor

 

    @classmethod  
    def Make_NewSpotCoordinate(cls, points, face):    
      
        ref = face
        
        print('View', __revit__.ActiveUIDocument.ActiveView)
        print('Face', face)

        hasleader = True

        for point in points:
            pointX = point[0]
            pointY = point[1]
            pointZ = point[2]
            
            bend = revit_xyz(pointX + 450, pointY + 450, pointZ) # temp
            end = revit_xyz(pointX+500, pointY+500, pointZ) # temp 
            tempArr = revit_xyz(pointX, pointY, pointZ)
            
            print('Point', point)            
            print('Bend', bend)
            print('End', end)            
            print('TempArr', tempArr)
            print('HasLeader', type(hasleader))
            print('===test==', __revit__.ActiveUIDocument.ActiveView.Document)
try: #Document.NewSpotCoordinate(revit.active_view, ref, point, bend, end, tempArr, hasleader) # E1) NewSpotCoordinate() takes exactly 8 arguments (7 given) c_doc.NewSpotCoordinate(__revit__.ActiveUIDocument.ActiveView , revit.active_view , ref, point, bend, end, tempArr, hasleader) # E2) 'expected Document, got Document except Exception as ex: print('Exception : ', ex)

▲The above code is part of the code.

 

Guys, 

I'm trying to use the 'NewSpotCoordinate' function in python, but there's an error.

First, I used this code 'Document.NewSpotCoordinate(revit.active_view, ref, point, bend, end, tempArr, hasleader)' 

However, an error with the contents 'NewSpotCoordinate() takes exactly 8 arguments (7 given)'  occurred.

So I put anything in to make eight parameters. an error with the contents  'expected Document, got  000 '.

Finally, I put 'document type' in first param. So the error that came out was 'expected Document, got Document'.

Do I have to use the 'Transaction' Class?

 

I really don't know...... What did I miss?

 

▼ The following is the contents of the output.

 

('View', <Autodesk.Revit.DB.View3D object at 0x000000000000044B [Autodesk.Revit.DB.View3D]>)
('Face', <Autodesk.Revit.DB.Reference object at 0x000000000000044C [Autodesk.Revit.DB.Reference]>)
('Point', <Autodesk.Revit.DB.XYZ object at 0x000000000000044D [(-11195.841918861, -14411.389384324, 23143.876630295)]>)
('Bend', <Autodesk.Revit.DB.XYZ object at 0x000000000000044E [(-10745.841918861, -13961.389384324, 23143.876630295)]>)
('End', <Autodesk.Revit.DB.XYZ object at 0x000000000000044F [(-10695.841918861, -13911.389384324, 23143.876630295)]>)
('TempArr', <Autodesk.Revit.DB.XYZ object at 0x0000000000000450 [(-11195.841918861, -14411.389384324, 23143.876630295)]>)
('HasLeader', <type 'bool'>)
('===test==', <Autodesk.Revit.DB.Document object at 0x0000000000000451 [Autodesk.Revit.DB.Document]>)
('Exception : ', TypeError('expected Document, got Document',))

 

 

The translation can be strange......!

Have a nice day 🙂

 

0 Likes
Accepted solutions (1)
979 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk
Accepted solution

First: yes, you definitely have to wrap this in a transaction.

   

You have to wrap any and all database modifications in a transaction.

  

Secondly: watch out! The Revit API defines two different document classes:

 

  • Autodesk.Revit.Creation.Document
  • Autodesk.Revit.DB.Document

 

Hence, the weird error message. 

 

The NewSpotCoordinate method belongs to the former:

 

https://www.revitapidocs.com/2020/c2efc79c-75ff-4505-ef3d-3db94a952227.htm

 

Now, all should be clear.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

Ysuuny
Contributor
Contributor

Thank for your quick reply.
I was already using 'Autodesk.Revit.Creation.Document / NewSpotCoordinate'.
c_doc is 'from Autodesk.Revit.Creation import Document as c_doc' alias.
And I'm try to transation class but I keep getting errors.

 

Q1) What is the relationship between view3d and view class?
Q2) Is it okay if view3d goes into the first parameter?
Q3) Is the use of transation class(method) correct?

Q4) ......Also What did I miss?

 

from Autodesk.Revit.DB import Document 
from Autodesk.Revit.DB import Face 
from Autodesk.Revit.DB import XYZ as revit_xyz
from Autodesk.Revit.Creation import Document as c_doc
from Autodesk.Revit.DB import View as view
from Autodesk.Revit.UI import UIDocument as r_ui
from Autodesk.Revit.DB import Reference as r_ref
from Autodesk.Revit.UI import UIApplication as r_uiapp
from Autodesk.Revit.DB import Transaction

▲ Define the class and alias

    @classmethod  
    def Make_NewSpotCoordinate(cls, points, face):    
        document = __revit__.ActiveUIDocument.Document
        app = __revit__.Application;
        ref = face
        hasleader = True

        transV = Transaction(__revit__.ActiveUIDocument.Document, 'NewSpotCoordinate')
        transV.Start("new spot coordinate")

        try:    
            for point in points:
                pointX = point[0]
                pointY = point[1]
                pointZ = point[2]
                
                bend = revit_xyz(pointX + 450, pointY + 450, pointZ) # temp
                end = revit_xyz(pointX+500, pointY+500, pointZ) # temp 
                tempArr = revit_xyz(pointX, pointY, pointZ)
                
                c_doc.NewSpotCoordinate( revit.active_view , ref, point, bend, end, tempArr, hasleader)
        except Exception as ex:
            print('Error: ' , ex )
        finally:
            transV.Commit()      

▲The above code is part of the code.

 

View / <Autodesk.Revit.DB.View3D object at 0x000000000000044B [Autodesk.Revit.DB.View3D]>
Face(reference) / <Autodesk.Revit.DB.Reference object at 0x000000000000044C [Autodesk.Revit.DB.Reference]>
Point(origin) / <Autodesk.Revit.DB.XYZ object at 0x000000000000044D [(-11195.841918861, -14411.389384324, 23143.876630295)]>
Bend / <Autodesk.Revit.DB.XYZ object at 0x000000000000044E [(-10745.841918861, -13961.389384324, 23143.876630295)]>
End / <Autodesk.Revit.DB.XYZ object at 0x000000000000044F [(-10695.841918861, -13911.389384324, 23143.876630295)]>
TempArr(refPt) / <Autodesk.Revit.DB.XYZ object at 0x0000000000000450 [(-11195.841918861, -14411.389384324, 23143.876630295)]>
HasLeader /  <type 'bool'>

▲ Each parameter type

Result(Error) : TypeError('NewSpotCoordinate() takes exactly 8 arguments (7 given)


* The translation can be strange 😄

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Q1) What is the relationship between view3d and view class?

 

View3D is derived from View.

 
Q2) Is it okay if view3d goes into the first parameter?

 

Yes.

 
Q3) Is the use of transation class(method) correct?

 

Looks fine to me.

 

Q4) ......Also What did I miss?

 

No idea.

 

There was a recent issue on converting a Revit API document to a wrapped object for a zero touch node:

 

https://thebuildingcoder.typepad.com/blog/2019/08/zero-touch-node-element-wrapper-and-load-from-stre...

 

Do you need to wrap something somewhere?

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

jeremytammik
Autodesk
Autodesk

Maybe you cannot create a spot elevation in a 3D view.

 

Maybe you must be in an elevation view, like in this example:

 

https://thebuildingcoder.typepad.com/blog/2010/01/spot-elevation-creation-on-top-of-beam.html

 

You should always test that what you are trying to do is possible at all in the user interface before trying to attack it programmatically.

  

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 6

Ysuuny
Contributor
Contributor

Thank for your quick reply,  

But, I want to use 'NewSpotCoordinate' method.... not 'NewSpotElevation' method....!

Is they the same function?

 

0 Likes