0

Can somebody tell me how to create a line geometry by mouse click with python addin?

I am using below code in python addin tool.

class ToolClass8(object):
"""Implementation for Testmsg_addin.tool (Tool)"""
def __init__(self):
 self.enabled = True
 self.cursor = 3 
 self.shape = "Line" 
def onLine(self, line_geometry):
 NewL = "NewL"
 cur = arcpy.da.InsertCursor(NewL, ["SHAPE@"])
 array = arcpy.Array()
 part = line_geometry.getPart(0)
 for pt in part:
 array.add(pt) 
 cur.insertRow(arcpy.Polyline(array))

which throws the error:

cur.insertRow(arcpy.Polyline(array)) TypeError: argument must be sequence of values

Can somebody help me with the code?

Hornbydd
44.9k5 gold badges42 silver badges84 bronze badges
asked Mar 15, 2016 at 4:44

1 Answer 1

2

If you read the help file for a Tool Class the onLine() method returns a polyline object:

def onLine(self, line_geometry):
 cur = arcpy.da.InsertCursor("NewL", ["SHAPE@"])
 cur.insertRow([line_geometry])
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Mar 15, 2016 at 14:48
2
  • Yes Its Working Now, thank you so much. but could not Understand what just happened by adding parenthesis ? Commented Mar 16, 2016 at 3:54
  • 1
    @AkhilKumar It's expecting a list of strings (field names or tokens), and my answer provided only a string with a token, whereas this provides a list of one string. Commented Mar 16, 2016 at 8:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.