Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move all objects to snap conformity 1

Status
Not open for further replies.

smandoli9

Programmer
Jun 10, 2002
103
0
0
US
I have a large diagram built by a CAD felon. He didn't use Snap. I'd like to select everything and have each item moved to the nearest snap point. Is there such a command?

[purple]_______________________________
[sub]Never confuse movement with action -- E. Hemingway [/sub][/purple]
 
No, not that I've ever heard of. But you might find a custom routine has been written for this.

But what all items would need to be moved, just line endpoints? If a block or text, the insert point? Polyline vertices?
 
Yes, I wasn't clear. It's all single-line text entries that are the issue. Sure looks like a simple VBA routine don't it?

[purple]_______________________________
[sub]Never confuse movement with action -- E. Hemingway [/sub][/purple]
 
I don't know VBA - but it looks like a fairly simple lisp to me :)

Select all text entities, extract coordinates of insert point, "round" those x & y values to the x & y snap settings, substitute the rounded values into the entity data of the text, "entmod" to update/edit the text location.
 
That's beautiful. All I need is the complete snippet! Oh, and I just discovered that this CAD fraud used only MTEXT. Which was really not the thing to do here. Okay, thanks. Carl.

[purple]_______________________________
[sub]Never confuse movement with action -- E. Hemingway [/sub][/purple]
 
I can give you some code when I get a few minutes.....

In the meantime you could explode all mtext to text, and use the Express Tools "tjust" to make sure all have the same justification (if not a problem).
 
OK here's more than a snippet :)
Try pasting the following lisp code into a file, save and load. Tested briefly on text entities. Starts with "txtsnap".
==========================================

(defun c:txtsnap ()
(command "undo" "be")
(setq SnapStart (getvar "SNAPBASE"))
(setq Xstart (car SnapStart)
YStart (cadr SnapStart)
)
(setq xsnap (getreal "\nEnter x snap spacing: "))
(setq ysnap (getreal "\nEnter y snap spacing: "))
(setq txtset (ssget '((0 . "*TEXT"))))
(setq LenSet (sslength txtSet))
(setq Ecount 0)
(repeat LenSet
(setq Ename (ssname txtset Ecount))
(setq Edata (entget Ename))
(setq InsPt (cdr (assoc 10 Edata)))
(setq Xins (car InsPt)
Yins (cadr InsPt)
)
(setq Xround (roundsnap Xins xsnap xstart)
YRound (roundsnap Yins ysnap ystart)
PtRound (list Xround YRound)
)
(setq NewInsData (cons 10 PtRound))
(setq newdata (subst NewInsdata (assoc 10 Edata) Edata))
(entmod Newdata)
(setq ECount (1+ Ecount))
)
(command "undo" "e")
(princ)
)
;;--------------------------------
(defun roundsnap (val incr base)
(setq Snapdist (- val base))
(setq NewNum (/ Snapdist incr))
(setq NumSteps (atoi (rtos NewNum 2 0)))
(setq Rounded (* NumSteps incr))
(setq NewCoord (+ base rounded))
)
 
With help from thread 682356 to run the LISP, Hooray, a few challenges are solved. Plus I learned how to explode MText, which is logical (so much so you'd think AutoCAD 2002 Help would mention it).

Many thanks, Carl!

[purple]_______________________________
[sub]Never confuse movement with action -- E. Hemingway [/sub][/purple]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top