Author Topic: Evenly space objects in a linear path.  (Read 15003 times)

0 Members and 1 Guest are viewing this topic.

thunderfoot

  • Guest
Evenly space objects in a linear path.
« on: January 28, 2013, 10:24:41 AM »
I searched for a function to do this but could not find one.  :blank: Does anyone know if there is one located here in the Swamp? Or elsewhere?

Thanks,
     Reuben Shilling

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Evenly space objects in a linear path.
« Reply #1 on: January 28, 2013, 10:54:43 AM »
MEASURE??
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Evenly space objects in a linear path.
« Reply #2 on: January 28, 2013, 10:55:12 AM »
Hi ,

Can you explain your aim of the lisp in more details ?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Evenly space objects in a linear path.
« Reply #3 on: January 28, 2013, 10:55:18 AM »
Or ARRAY??
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Evenly space objects in a linear path.
« Reply #4 on: January 28, 2013, 11:03:40 AM »
« Last Edit: January 28, 2013, 11:08:36 AM by CAB »
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #5 on: January 28, 2013, 11:26:01 AM »
Hi ,

Can you explain your aim of the lisp in more details ?

I want to be able to select already existing objects (usually text but sometimes a block) (one at a time is OK, but i would rather select them all at once and let their individual x or y coordinates determine their current alignment and from that derive their new alignment) and from that selection set specify a distance between the objects along a path determined by 2 user-defined points (to define the angle of array).

Thanks,
    Reuben Shilling

Nibster

  • Guest
Re: Evenly space objects in a linear path.
« Reply #6 on: January 28, 2013, 11:29:28 AM »
DIVIDE

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Evenly space objects in a linear path.
« Reply #7 on: January 28, 2013, 11:30:00 AM »
Hi ,

Can you explain your aim of the lisp in more details ?

I want to be able to select already existing objects (usually text but sometimes a block) (one at a time is OK, but i would rather select them all at once and let their individual x or y coordinates determine their current alignment and from that derive their new alignment) and from that selection set specify a distance between the objects along a path determined by 2 user-defined points (to define the angle of array).

Thanks,
    Reuben Shilling
Looks like you may have already answered your own question.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #8 on: January 28, 2013, 11:31:21 AM »
Hi ,

Can you explain your aim of the lisp in more details ?

I want to be able to select already existing objects (usually text but sometimes a block) (one at a time is OK, but i would rather select them all at once and let their individual x or y coordinates determine their current alignment and from that derive their new alignment) and from that selection set specify a distance between the objects along a path determined by 2 user-defined points (to define the angle of array).

Thanks,
    Reuben Shilling
Looks like you may have already answered your own question.

Doesn't array just copy objects?
I want to evenly space the existing objects.

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #9 on: January 28, 2013, 11:31:51 AM »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Evenly space objects in a linear path.
« Reply #10 on: January 28, 2013, 11:39:06 AM »
This is a routine I use to offset objects.
Originally used for trusses in houses but will work for any object.
This one is X or Y axis only. http://www.theswamp.org/index.php?topic=34092.msg394338#msg394338


This is another version for UCS.
Note that they are rather old & in need of a remake.  8-)
Code: [Select]
;;; TrussOffsetUCS.lsp
;;;
;;; Author: Copyright© 2005 Charles Alan Butler
;;; Version:  1.0 May 01, 2005
;;; Purpose: offset objects user offset distance to fill selected area
;;;          Modified version of TrussOffset.lsp to use UCS
;;;          Will work with any objects
;;;
;;; [Prompts]
;;; Select objects
;;; Enter or select offset distance
;;; Pick start & end point of array distance, these picks establish
;;;  direction and total distance, not start & end points.
;;;
(defun c:trussoucs (/ *error* p1 p2 ss dist num tmp)
  ;;; error function & Routine Exit
(defun *error* (msg)
  (if
    (not
      (member
        msg
        '("console break" "Function cancelled" "quit / exit abort" "")
      )
    )
     (princ (strcat "\nError: " msg))
  ) ; if
  (setvar "osmode" useros)
  (setvar "CMDECHO" usercmd)
  (princ)
) ;
 ;end error function
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq useros (getvar "osmode"))
  (setvar "orthomode" 1)

  (prompt "\nSelect objects to offset")
  (setq ss (ssget))
  (if ss
    (progn
      (if (null to_step); global var
        (setq to_step 24)
        (setq to_step (abs to_step))
      )
      (setq tmp (getdist (strcat "\nEnter or pick offset amount. <"(rtos to_step) "> ")))
      (if tmp
        (setq to_step tmp)
      )
      (setq p1 (getpoint "Pick Starting point"))
      (if p1
        (progn
          (setq p2 (getpoint p1 "Pick End point and the axix of offset"))
          (if p2
            (progn
              (setq dist (distance p1 p2)
                    num  (fix (1+(/ dist to_step)))
                    ang  (angle p1 p2)
              )
              (if (or (equal ang pi 0.2)
                      (equal ang (* pi 1.5) 0.2)
                  )
                (setq to_step (- to_step)); reverse the direction
              )
              (setvar "osmode" 0)
              (cond
                ((or (equal ang 0 0.2) ; Horrizontal
                     (equal ang pi 0.2)
                 )
                 (command "_.array" ss "" "R" "" num to_step)
                )
                ((or (equal ang (/ pi 2) 0.2) ; Vertical
                     (equal ang (* pi 1.5) 0.2)
                 )
                 (command "_.array" ss "" "R" num "" to_step)
                 
                )
                (t
                  (alert "Under condtruction")
                  (setq p3 (polar p1 (+ (angle p1 p2) (/ pi 2)) 50))
                  (command "._ucs" "N" "3" p1 p2 p3) ; origin x y
                  (command "_.array" ss "" "R" "" num to_step)
                  (command "_ucs" "P")
                )

              ) ; end cond stmt
            ) ; end progn
          ) ; endif
        ) ; end progn
      ) ; endif
    ) ; end progn
  ) ; endif
;;;==========  Exit Sequence  ============
  (*ERROR* "")
  (princ); Exit quietly
) ; end defun
(prompt "\nOffset Object Loaded. Enter OOS to run.")
(princ)
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #11 on: January 28, 2013, 11:48:04 AM »
Try the following code Reuben:

Code: [Select]
;; Equispace  -  Lee Mac
(defun c:eqsp ( / a b e i l p s v )
    (if
        (and
            (setq s (ssget "_:L" '((0 . "TEXT,MTEXT,INSERT"))))
            (setq a (getpoint "\nSpecify Basepoint: "))
            (setq b (getpoint "\nSpecify Spacing Vector: " a))
        )
        (progn
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i)))))
                (if (or (wcmatch (cdr (assoc 0 e)) "MTEXT,INSERT")
                        (and
                            (zerop (cdr (assoc 72 e)))
                            (zerop (cdr (assoc 73 e)))
                        )
                    )
                    (setq p (assoc 10 e))
                    (setq p (assoc 11 e))
                )
                (setq l (cons (list p e) l))
            )
            (setq v (mapcar '- b a))
            (foreach e
                (vl-sort l
                    (function
                        (lambda ( a b )
                            (< (last (trans (cdar a) 0 v)) (last (trans (cdar b) 0 v)))
                        )
                    )
                )
                (entmod (subst (cons (caar e) a) (car e) (cadr e)))
                (setq a (mapcar '+ a v))
            )
        )
    )
    (princ)
)

PS: Off topic, your user name seems rather contradictory in nature to your signature...

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #12 on: January 28, 2013, 11:59:39 AM »
Try the following code Reuben:

Code: [Select]
;; Equispace  -  Lee Mac
(defun c:eqsp ( / a b e i l p s v )
    (if
        (and
            (setq s (ssget "_:L" '((0 . "TEXT,MTEXT,INSERT"))))
            (setq a (getpoint "\nSpecify Basepoint: "))
            (setq b (getpoint "\nSpecify Spacing Vector: " a))
        )
        (progn
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i)))))
                (if (or (wcmatch (cdr (assoc 0 e)) "MTEXT,INSERT")
                        (and
                            (zerop (cdr (assoc 72 e)))
                            (zerop (cdr (assoc 73 e)))
                        )
                    )
                    (setq p (assoc 10 e))
                    (setq p (assoc 11 e))
                )
                (setq l (cons (list p e) l))
            )
            (setq v (mapcar '- b a))
            (foreach e
                (vl-sort l
                    (function
                        (lambda ( a b )
                            (< (last (trans (cdar a) 0 v)) (last (trans (cdar b) 0 v)))
                        )
                    )
                )
                (entmod (subst (cons (caar e) a) (car e) (cadr e)))
                (setq a (mapcar '+ a v))
            )
        )
    )
    (princ)
)

PS: Off topic, your user name seems rather contradictory in nature to your signature...

Lee,
   
    Routine does just what I needed!

How so on the contradiction?
Chief Thunderfoot was a nickname I picked up my senior year in high school. It got started because I was running barefoot, and partly because I had just moved to Missouri from Oklahoma I think.

Thanks for the awesome routine, I hope to study it out and learn from it and others.

Sincerely,
     Reuben Shilling

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #13 on: January 28, 2013, 12:10:13 PM »
Routine does just what I needed!

Excellent  :-)

How so on the contradiction?
Chief Thunderfoot was a nickname I picked up my senior year in high school. It got started because I was running barefoot, and partly because I had just moved to Missouri from Oklahoma I think.

If you Google the name 'thunderfoot' you will discover that it is the name of a reasonably well-known online atheist; the contradiction being that you are quoting bible verses.

Thanks for the awesome routine, I hope to study it out and learn from it and others.

You're very welcome, ask if you have any questions about the code.

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #14 on: January 28, 2013, 12:19:58 PM »
Routine does just what I needed!

Excellent  :-)

How so on the contradiction?
Chief Thunderfoot was a nickname I picked up my senior year in high school. It got started because I was running barefoot, and partly because I had just moved to Missouri from Oklahoma I think.

If you Google the name 'thunderfoot' you will discover that it is the name of a reasonably well-known online atheist; the contradiction being that you are quoting bible verses.

In light of that fact and "Abstain from all appearance of evil." ~ I Thessalonians 5:22 I have changed my username to my wife's personal nickname for me (even using her spelling as opposed to my preferred "Roo").

Thanks for the awesome routine, I hope to study it out and learn from it and others.

You're very welcome, ask if you have any questions about the code.

On the code, when I tried to use it on a dynamic block, it only moved part of the block? I'm assuming this is because of (ssget "_:L" '((0 . "TEXT,MTEXT,INSERT")?


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #15 on: January 28, 2013, 12:38:08 PM »
In light of that fact and "Abstain from all appearance of evil." ~ I Thessalonians 5:22

Evil? Let's not open that can of worms.

On the code, when I tried to use it on a dynamic block, it only moved part of the block?

I haven't tested it, but looking at the code I see no reason why the program shouldn't work with dynamic blocks, since the code is only altering the insertion point of the block reference - what dynamic parameters does your dynamic block contain? (i.e. Visibility States / Linear Parameters etc.)

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #16 on: January 28, 2013, 12:48:16 PM »
In light of that fact and "Abstain from all appearance of evil." ~ I Thessalonians 5:22

Evil? Let's not open that can of worms.

No intention to open anything, just stating my position, and my gratitude at your revelation.

On the code, when I tried to use it on a dynamic block, it only moved part of the block?

I haven't tested it, but looking at the code I see no reason why the program shouldn't work with dynamic blocks, since the code is only altering the insertion point of the block reference - what dynamic parameters does your dynamic block contain? (i.e. Visibility States / Linear Parameters etc.)

Is there a way to keep either the 'x' or 'y' coordinate the same if the user should so desire?

Due to my almost nil knowledge of dynamic blocks I have attached the block in question.
« Last Edit: January 28, 2013, 01:00:10 PM by Reu »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #17 on: January 28, 2013, 01:00:57 PM »
Is there a way to attach .dwg files to here?

Sure, click the 'Attachments and other options' button at the base of the post:


thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #18 on: January 28, 2013, 01:01:52 PM »
Is there a way to attach .dwg files to here?

Sure, click the 'Attachments and other options' button at the base of the post:



Thanks, I found it shortly after posting that. :ugly:

andrew_nao

  • Guest
Re: Evenly space objects in a linear path.
« Reply #19 on: January 28, 2013, 01:48:49 PM »
what about the code i think Lee made for a dynamic array?

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #20 on: January 28, 2013, 01:54:29 PM »
what about the code i think Lee made for a dynamic array?

Not if it copies objects, I'm wanting to space existing objects.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #21 on: January 28, 2013, 04:21:58 PM »
what about the code i think Lee made for a dynamic array?

Thanks andrew, but this particular problem requires modification to a set of existing objects, rather than generating copies of objects, as per an array. However, for those that are interested, here are a few array programs:

Dynamic Incremental Array (and on my site here)
Various Dynamic Array programs

I'll now take a look at your block Reuben  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #22 on: January 28, 2013, 04:53:45 PM »
On the code, when I tried to use it on a dynamic block, it only moved part of the block?

The problem is because the program does not update the position of the block attributes after altering the block insertion point; a quick workaround for the time being would be to use the ATTSYNC command following use of the program.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #23 on: January 28, 2013, 05:01:17 PM »
Here is a better solution:

Code: [Select]
;; Equispace  -  Lee Mac
(defun c:eqsp ( / a b e i l p s v )
    (if
        (and
            (setq s (ssget "_:L" '((0 . "TEXT,MTEXT,INSERT"))))
            (setq a (getpoint "\nSpecify Basepoint: "))
            (setq b (getpoint "\nSpecify Spacing Vector: " a))
        )
        (progn
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i)))))
                (if (or (wcmatch (cdr (assoc 0 e)) "MTEXT,INSERT")
                        (and
                            (zerop (cdr (assoc 72 e)))
                            (zerop (cdr (assoc 73 e)))
                        )
                    )
                    (setq p (cdr (assoc 10 e)))
                    (setq p (cdr (assoc 11 e)))
                )
                (setq l (cons (list p (vlax-ename->vla-object (cdr (assoc -1 e)))) l))
            )
            (setq v (mapcar '- b a))
            (foreach e
                (vl-sort l
                    (function
                        (lambda ( a b )
                            (< (last (trans (car a) 0 v)) (last (trans (car b) 0 v)))
                        )
                    )
                )
                (vla-move (cadr e) (vlax-3D-point (car e)) (vlax-3D-point a))
                (setq a (mapcar '+ a v))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #24 on: January 28, 2013, 05:49:09 PM »
Here is a better solution:

Code: [Select]
;; Equispace  -  Lee Mac
(defun c:eqsp ( / a b e i l p s v )
    (if
        (and
            (setq s (ssget "_:L" '((0 . "TEXT,MTEXT,INSERT"))))
            (setq a (getpoint "\nSpecify Basepoint: "))
            (setq b (getpoint "\nSpecify Spacing Vector: " a))
        )
        (progn
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i)))))
                (if (or (wcmatch (cdr (assoc 0 e)) "MTEXT,INSERT")
                        (and
                            (zerop (cdr (assoc 72 e)))
                            (zerop (cdr (assoc 73 e)))
                        )
                    )
                    (setq p (cdr (assoc 10 e)))
                    (setq p (cdr (assoc 11 e)))
                )
                (setq l (cons (list p (vlax-ename->vla-object (cdr (assoc -1 e)))) l))
            )
            (setq v (mapcar '- b a))
            (foreach e
                (vl-sort l
                    (function
                        (lambda ( a b )
                            (< (last (trans (car a) 0 v)) (last (trans (car b) 0 v)))
                        )
                    )
                )
                (vla-move (cadr e) (vlax-3D-point (car e)) (vlax-3D-point a))
                (setq a (mapcar '+ a v))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

Nicely done. That solved the problem of the block. . .

However is it possible to put an option in for the user to specify whether the vector direction will be aligned with the 'x' 'y' or 'neither' and based upon that input to leave either the 'x' or 'y' coordinate as is? E.g. if the user specified that the spacing would be in the 'x' direction, the program would space the objects in that direction without changing the 'y' coordinate and vice versa.
Hopefully the attached drawing will help explain.

Once again thanks for all your hard work Lee.

Sincerely,

     Reuben Shilling

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #25 on: January 28, 2013, 06:17:00 PM »
However is it possible to put an option in for the user to specify whether the vector direction will be aligned with the 'x' 'y' or 'neither' and based upon that input to leave either the 'x' or 'y' coordinate as is?

Just turn ORTHO on  :-)

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #26 on: January 28, 2013, 06:25:51 PM »
However is it possible to put an option in for the user to specify whether the vector direction will be aligned with the 'x' 'y' or 'neither' and based upon that input to leave either the 'x' or 'y' coordinate as is?

Just turn ORTHO on  :-)

Didn't work for me?   :blank:
Attached drawing shows results I obtained with ortho turned on.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Evenly space objects in a linear path.
« Reply #27 on: January 28, 2013, 06:37:49 PM »
However is it possible to put an option in for the user to specify whether the vector direction will be aligned with the 'x' 'y' or 'neither' and based upon that input to leave either the 'x' or 'y' coordinate as is?

Just turn ORTHO on  :-)

Didn't work for me?   :blank:
Attached drawing shows results I obtained with ortho turned on.

Sorry, I'm not sure I understand - that looks like the correct result to me?

thunderfoot

  • Guest
Re: Evenly space objects in a linear path.
« Reply #28 on: January 28, 2013, 06:42:58 PM »
However is it possible to put an option in for the user to specify whether the vector direction will be aligned with the 'x' 'y' or 'neither' and based upon that input to leave either the 'x' or 'y' coordinate as is?

Just turn ORTHO on  :-)

Didn't work for me?   :blank:
Attached drawing shows results I obtained with ortho turned on.

Sorry, I'm not sure I understand - that looks like the correct result to me?

The "correct" or rather desired result in the case shown in the drawing is for the blocks to retain their individual 'x' coordinates and for the spacing to apply to their 'y' coordinates from the specified base point. Notice how they are "stacked" on one another? That will not work as the stationing is horizontally based and the callouts need to retain their horizontal location.

I have reattached the drawing with a modification to show the desired result, hopefully the picture will explain clearly what my words bungle.

~The clearest man alive I am not.
     Reuben Shilling
« Last Edit: January 29, 2013, 12:38:49 PM by Reu »