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

0 Members and 1 Guest are viewing this topic.

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 »