Spacing text efficiently

Spacing text efficiently

benjamin_sofo
Observer Observer
742 Views
8 Replies
Message 1 of 9

Spacing text efficiently

benjamin_sofo
Observer
Observer

Howdy,

 

A regular task I perform is manually moving text to improve legibility (see images for before and after of this task). Looking for any suggestions for streamlining this process making it less labour/time intensive. Open to using LISP, commands and any other techniques you may think is helpful.

 

Thanks in advance!

 

Pre manual movingPre manual moving

Post manual movingPost manual moving

0 Likes
743 Views
8 Replies
Replies (8)
Message 2 of 9

imadHabash
Mentor
Mentor

Hi and Welcome to AutoCAD Forum,

In AutoCAD ... There are many ways for selecting Objects Based on Shared Properties.

  • SELECTSIMILAR (Command) .. simple method to select objects based on properties such as layer, color, or lineweight, is Select Similar command, accessible from the shortcut menu after you've selected an object.
  • Quick Select (QSELECT), always accessible from the shortcut menu, offers more options and additional properties, such as transparency, for creating selection sets on the fly.
  • Filter (Command) ..To create saved selection filters, use the FILTER command or enter 'filter at the Select Objects prompt.

Imad Habash

EESignature

Message 3 of 9

Pointdump
Consultant
Consultant

Hi Ben,
Welcome to the Autodesk Forums.
Dotsoft has >>>Point Leader Commands<<<.
Dave

Dave Stoll
Las Vegas, Nevada

EESignature

64GB DDR4 2400MHz ECC SoDIMM / 1TB SSD
NVIDIA Quadro P5000 16GB
Windows 10 Pro 64 / Civil 3D 2025
Message 4 of 9

shedgevJVQWW
Enthusiast
Enthusiast

Hi,

 

Create your own template with the required text style in the dimension setting. Then copy your drawing (1st image) & paste it in that template drawing.

 

Message 5 of 9

RSomppi
Mentor
Mentor

I would start with a larger scale. That drawing is pretty hard to read.

Message 6 of 9

jskalaXDDX5
Advocate
Advocate

If you are stuck with doing it all manually, a CUI macro can reduce the number of keystrokes.

*^C^C\_MOVE;\

Great video to get started if you have never used…

https://www.youtube.com/watch?v=OGegAVVT8t0

 

Otherwise, peripheral, this is Macroworks 3.1…reduces each individual move to a single keystroke…in attached video.

jskalaXDDX5_0-1751552968954.png

 

 

Either (both) can be great all around time savers…

Message 7 of 9

daniel_cadext
Advisor
Advisor

Hi, not a trivial task via code. If you are running a full version and are able to use Python (PyRx). You can try a KD-Tree to quickly search and adjust text clusters. This is just a proof of concept, you may have to add in some math since you have text rotation

 

import traceback
from pyrx import Ap, Db, Ed, Ge
from itertools import pairwise

# hold text data, __it__, so we can presort by Y
class MT:
    def __init__(self, id: Db.ObjectId):
        mt = Db.MText(id)
        self.id = id
        self.ext = mt.getGeomExtents()
        # change this value to increase or decrease the search
        self.rad = (self.ext.maxPoint() - self.ext.minPoint()).length() * 0.5
        self.lay = mt.layer()

    def __lt__(self, other):
        return self.ext.maxPoint().y > other.ext.maxPoint().y

# get the data
def getData(ss: Ed.SelectionSet):
    mtdata: list[MT] = []
    for id in ss.objectIds():
        mtdata.append(MT(id))
    return sorted(mtdata)

# return the new ext so we can update
def moveText(id, point):
    mt = Db.MText(id, Db.OpenMode.kForWrite)
    mt.setLocation(point)
    return mt.getGeomExtents()

@Ap.Command()
def doit():
    try:
        # fill up the data
        ps, ss = Ed.Editor.select([(0, "MTEXT")])
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps))
        mtdata = getData(ss)

        # build the kd-tree from extents mid points
        pnts = Ge.Point3dArray()
        for mt in mtdata:
            pnts.append(mt.ext.midPoint())
        tree = Ge.Point3dTree(pnts)

        # search and group
        groups = set()
        for mt in mtdata:
            subgroup = []
            _idxs, _dists = tree.radiusSearch(mt.ext.midPoint(), mt.rad)
            for _i in _idxs:
                subgroup.append(_i)
            groups.add(tuple(sorted(subgroup)))

        # do something with the the groups
        for items in groups:
            for i, j in pairwise(items):
                mtdata[j].ext = moveText(mtdata[j].id, mtdata[i].ext.minPoint())

    except Exception as err:
        traceback.print_exception(err)

 

before.png     

after.png

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 8 of 9

benjamin_sofo
Observer
Observer

Thanks for this! looks like a solid solution, I'll test it out and let you know how it goes.

Message 9 of 9

CGBenner
Community Manager
Community Manager

@benjamin_sofo Hi, have you been able to test this solution yet?

Did you find a post helpful? Then feel free to give likes to these posts!
Did your question get successfully answered? Then just click on the 'Accept solution' button.  Thanks and Enjoy!



Chris Benner

Community Manager - NAMER / D&M


0 Likes