Forum

Author Topic: vertices cannot be called when markers attached  (Read 1355 times)

Abe Whaanga

  • Newbie
  • *
  • Posts: 15
    • View Profile
vertices cannot be called when markers attached
« on: August 09, 2020, 10:46:42 PM »
Hello,

After attaching markers to a shape it is no longer possible to call the shape vertices and run the add attributes script below.  I get Error:  object of type 'NoneType' has no len ().

Our current process we create shapes on the non referenced model with markers attached, then reference the model and the shapes combined.  After this process we can't draw on the model anymore as the shape's appear to be drawn at 0'0'0 coordinates.  We then have to take off attach markers and draw on a camera image before attributes can be attached. 

How do we draw shapes on a referenced model?  and is it possible to call the shape vertices and add attributes to a shape with markers attached?

Thanks,

Abe

def add_channel_attributes():
   import Metashape
   
   chunk = Metashape.app.document.chunk
   #loop chunk shapes   
   for shape in chunk.shapes:
      
      #check for CHANNEL layer
      if shape.group.label == 'CHANNEL':         
         #check shape is a polyline with only 2 vertices         

         if (shape.type == Metashape.Shape.Type.Polyline and len(shape.vertices) == 2):               
            channel_vertices = shape.vertices
            #calculate dip and bearing, attach as attribute                  
            
            shape.attributes['dip'] = str(calculate_dip(channel_vertices[1][0], channel_vertices[1][1], channel_vertices[1][2], channel_vertices[0][0], channel_vertices[0][1], channel_vertices[0][2]))
            shape.attributes['bearing'] = str(calculate_bearing(channel_vertices[1][0], channel_vertices[1][1], channel_vertices[1][2], channel_vertices[0][0], channel_vertices[0][1], channel_vertices[0][2]))   

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: vertices cannot be called when markers attached
« Reply #1 on: August 10, 2020, 01:03:29 AM »
Abe,

if a shape has attached markers then shape.vertex_ids is non empty (contrary to shape.vertices) and the shape vertices coordinates are stored in the attached marker.position for each vertex so you can use following code:
Code: [Select]
if shape.vertex_ids:
    if (shape.type == Metashape.Shape.Type.Polyline and len(shape.vertex_ids) == 2):
        channel_vertices = [chunk.shapes.crs.project(chunk.transform.matrix.mulp(i.position)) for i in chunk.markers if i.key in shape.vertex_ids]
        #calculate dip and bearing, attach as attribute    ...     
else:
    if (shape.type == Metashape.Shape.Type.Polyline and len(shape.vertices) == 2):
        channel_vertices = shape.vertices
        #calculate dip and bearing, attach as attribute    ...
« Last Edit: August 10, 2020, 05:03:07 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor