def draw_labels(labels, **kwargs): """Draw labels as text dots and optionally set individual font, fontsize, name and color. Parameters ---------- labels : list of dict A list of labels dictionaries. Returns ------- list of GUID Notes ----- A label dict has the following schema: .. code-block:: python Schema({ 'pos': And(list, lambda x: len(x) == 3), 'text': And(str, len), Optional('name', default=''): str, Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)), Optional('fontsize', default=10): Or(int, float), Optional('font', default="Arial Regular"): str }) """ guids = [] for label in iter(labels): pos = label['pos'] text = label['text'] name = label.get('name', '') color = label.get('color', None) size = label.get('fontsize', 10) font = label.get('font', 'Arial Regular') dot = TextDot(str(text), Point3d(*pos)) dot.FontHeight = size dot.FontFace = font guid = add_dot(dot) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer attr.Name = name obj.CommitChanges() guids.append(guid) return guids
def draw_labels(labels, **kwargs): """Draw labels as text dots and optionally set individual font, fontsize, name and color. Parameters ---------- labels : list of dict A list of labels dictionaries. A label dictionary has the following structure: .. code-block:: python { 'pos' : [x, y, z], 'text' : '', 'name' : '' } """ guids = [] for l in iter(labels): pos = l['pos'] text = l['text'] name = l.get('name', '') color = l.get('color', None) size = l.get('fontsize', 10) font = l.get('font', 'Arial Regular') dot = TextDot(str(text), Point3d(*pos)) dot.FontHeight = size dot.FontFace = font guid = add_dot(dot) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer attr.Name = name obj.CommitChanges() guids.append(guid) return guids
def xdraw_labels(labels, **kwargs): """Draw labels as text dots and optionally set individual name and color.""" guids = [] for l in iter(labels): pos = l['pos'] text = l['text'] name = l.get('name', '') color = l.get('color', None) guid = add_dot(TextDot(str(text), Point3d(*pos))) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer attr.Name = name obj.CommitChanges() guids.append(guid) return guids