LISP TO PLACE A group of blocks on a similar axis

LISP TO PLACE A group of blocks on a similar axis

Anonymous
Not applicable
2,702 Views
19 Replies
Message 1 of 20

LISP TO PLACE A group of blocks on a similar axis

Anonymous
Not applicable

Is there a Lisp that can take a group of selected blocks. For example a block that is a rectangle with a letter in it. and align them all along a similar axis?

0 Likes
2,703 Views
19 Replies
Replies (19)
Message 2 of 20

Anonymous
Not applicable

explain your desires a little better and you may not need a lisp.

You can edit the rotation of a group of blocks all at once in the properties palette, or you can use MEASURE or DIVIDE to string a series of blocks along a path aligned to that path.

0 Likes
Message 3 of 20

imadHabash
Mentor
Mentor

Hi,

 

Would you show us your case please?

Imad Habash

EESignature

0 Likes
Message 4 of 20

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

I see that you are visiting as a new member. Welcome to the Autodesk Community!

 

I am not 100% sure that  I understand your question so I made a video that shows two options.

The first is to select all the blocks and then adjust the rotation angle of all of them at once using Properties.

The second is to use the ALIGN command to move and rotate the blocks along an angled line.

 

If I misunderstand your question, please give me a bit more detail.

 

 

Please select the Accept as Solution button if my post solves your issue or answers your question.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 5 of 20

Anonymous
Not applicable

Hey Guys,

I appreciate the help. Thank you.

Let me explain my question a little more. I do fire alarm design right now. fairly new. I have 10 blocks. each one is a smoke detector and they are scattered around a floor plan in their designated positions. I would like to select them all and somehow get them to all line up. Let me show you in pictures.

I would like to get the objects in picture one to line up like in picture two. Without having to do it one at a time as some projects have multiple tens of devices.

Capture.PNGCapture1.PNG

0 Likes
Message 6 of 20

Kent1Cooper
Consultant
Consultant

Looks easy enough to do, but:

 

Do you need the Lines drawn between them, or just the alignment?

 

Would you want the routine to ask you for a spacing between them, or should it calculate it on the basis of something like the Block's size, or could it always be the same amount and be hard-coded in?

 

Would you want them Moved from their positions around the plan, or Copied so that they also remain in place in the plan?

 

How would you want to designate where to put that row of them?

Kent Cooper, AIA
0 Likes
Message 7 of 20

Anonymous
Not applicable

Do you need the Lines drawn between them, or just the alignment?

I would like the lines to be drawn between them and it could be a set length for the lines.so it's the same length every time.

 

Would you want the routine to ask you for a spacing between them, or should it calculate it on the basis of something like the Block's size, or could it always be the same amount and be hard-coded in?

I would like the lines to be drawn between them and it could be a set length for the lines.so it's the same length every time.

Would you want them Moved from their positions around the plan, or Copied so that they also remain in place in the plan?

I would like them copied, so the originals remain and placed where I designate it with a mouse click.

 

How would you want to designate where to put that row of them?

I would place it using my mouse click.

 

Thank you again for the help. You guys know a lot. I hope to get their one day.

0 Likes
Message 8 of 20

Vinayv4v
Advisor
Advisor

Hi,

 

May be you are looking for the measure command. If you want to draw the schematic diagram for fire alarm this command could be handy.

 

 

Cheers,

Vinay Vijayakumaran

0 Likes
Message 9 of 20

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

I am checking back to see if my post or others helped you with your problem. Please add a post with how you decide to proceed and your results so other Community members may benefit.

 

Please hit the Accept as Solution button if a post or posts solves your issue or answers your question.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 10 of 20

Anonymous
Not applicable

Do you need the Lines drawn between them, or just the alignment?

I would like the lines to be drawn between them and it could be a set length for the lines.so it's the same length every time.

 

Would you want the routine to ask you for a spacing between them, or should it calculate it on the basis of something like the Block's size, or could it always be the same amount and be hard-coded in?

I would like the lines to be drawn between them and it could be a set length for the lines.so it's the same length every time.

Would you want them Moved from their positions around the plan, or Copied so that they also remain in place in the plan?

I would like them copied, so the originals remain and placed where I designate it with a mouse click.

 

How would you want to designate where to put that row of them?

I would place it using my mouse click.

 

Thank you again for the help. You guys know a lot. I hope to get their one day.

0 Likes
Message 11 of 20

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

I am checking back to see if Kent @Kent1Cooper has had time to create this routine for you or not. If you like, I can move this thread to the customization forum where others might step in to help as well.


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 12 of 20

Ranjit_Singh
Advisor
Advisor

Try below code, very lightly tested.

(defun c:somefunc  (/ align bldist ctr vlaobj)
  (setq	ctr    0
	vlaobj (vlax-ename->vla-object (setq align (car (entsel "\nSelect align: "))))
	bldist (getdist "\nSpecify distance between blocks: "))
  (and (wcmatch (cdr (assoc 0 (entget align))) "*LINE")
       (mapcar '(lambda	(x)
		  (command-s "._copy"
			     x
			     ""
			     (cdr (assoc 10 (entget x)))
			     (vlax-curve-getpointatdist vlaobj (* ctr bldist))
			     "")
		  (setq ctr (1+ ctr)))
	       (vl-remove-if-not '(lambda (x) (= 'ename (type x)))
				 (mapcar 'cadr (ssnamex (ssget '((0 . "INSERT")))))))))
0 Likes
Message 13 of 20

Anonymous
Not applicable

Thanks for the help, but it didn't work as expected. Nothing really happened.

0 Likes
Message 14 of 20

Ranjit_Singh
Advisor
Advisor

This is what it does at my end.

Try adding (vl-load-com) to the beginning of my code. If it does not work still then please post your drawing with subject blocks.

0 Likes
Message 15 of 20

Ranjit_Singh
Advisor
Advisor

My apologies. Upon reading post 7, I realize that you do not have a pre-drawn alignment (line, polyline etc.). In that case use below routine. It will let you pick a start point and ask for distance. The blocks will be placed in a horizontal line. It can be easily modified to place the blocks at some other straight edge (such as at 45 degrees).

(defun c:somefunc  (/ align bldist ctr endpoint startpoint)
  (setq	ctr	   0
	bldist	   (getdist "\nSpecify distance between blocks: ")
	startpoint (getpoint "\nSelect Point to start placement: "))
  (mapcar '(lambda (x)
	     (command-s	"._copy"
			x
			""
			(cdr (assoc 10 (entget x)))
			(setq endpoint (mapcar '+ startpoint (list (* ctr bldist) 0 0)))
			"")
	     (command-s "._line" startpoint endpoint "")
	     (setq ctr (1+ ctr)))
	  (vl-remove-if-not '(lambda (x) (= 'ename (type x)))
			    (mapcar 'cadr (ssnamex (ssget '((0 . "INSERT"))))))))
0 Likes
Message 16 of 20

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... lines to be drawn between them and it could be a set length for the lines.so it's the same length every time.

....

I would like them copied, so the originals remain and placed where I designate it with a mouse click.

....

Finally got around to working something out [in simplest terms, lightly tested]:

 

(defun C:BAL (/ osm bss pt rad len blk n); = Block Align with Lines between
  ;; for Blocks with primary Circle, with insertion point at its center
  (setq osm (getvar 'osmode))
  (prompt "\nTo Align Blocks with connecting Lines,")
  (if
    (and
      (setq bss (ssget '((0 . "INSERT"))))
      (setq pt (getpoint "\nPosition of left-most copy: "))
      (setq rad (getdist "\nRadius of circle part of Blocks: "))
      (setq len (getdist "\nLength of Lines between copies: "))
    ); and
    (progn ; then
      (setvar 'osmode 0)
      (command
        "_.copy" (setq blk (ssname bss (setq n (1- (sslength bss))))) ""
          (cdr (assoc 10 (entget blk))) pt
      ); command
      (repeat n
        (command
          "_.line" (setq pt (polar pt 0 rad)) (setq pt (polar pt 0 len)) ""
          "_.copy" (setq blk (ssname bss (setq n (1- n)))) ""
            (cdr (assoc 10 (entget blk))) (setq pt (polar pt 0 rad))
        ); command
      ); repeat
      (setvar 'osmode osm)
    ); progn
  ); if
); defun

If you have a fixed and constant value for 'rad' and 'len', you can pull those out of the User-input area and the localized variables list, and just put those values into the code in place of those variable names.

 

EDIT:

Now that I look back at the lower image in Post 5, with a Line also to the right of the last one, that's also possible [in fact, a little simpler]:

 

(defun C:BAL (/ osm bss pt rad len blk n); = Block Align with Lines between
  ;; for Blocks with primary Circle, with insertion point at its center
  (setq osm (getvar 'osmode))
  (prompt "\nTo Align Blocks with connecting Lines,")
  (if
    (and
      (setq bss (ssget '((0 . "INSERT"))))
      (setq pt (getpoint "\nPosition of left-most copy: "))
      (setq rad (getdist "\nRadius of circle part of Blocks: "))
      (setq len (getdist "\nLength of Lines between copies: "))
    ); and
    (progn ; then
      (setvar 'osmode 0)
      (repeat (setq n (sslength bss))
        (command
          "_.copy" (setq blk (ssname bss (setq n (1- n)))) ""
            (cdr (assoc 10 (entget blk))) pt 
          "_.line" (setq pt (polar pt 0 rad)) (setq pt (polar pt 0 len)) ""
        ); command
        (setq pt (polar pt 0 rad))
      ); repeat
      (setvar 'osmode osm)
    ); progn
  ); if
); defun

It could also restrict selection to only a specific Block name, so you could select an area with a window and any other Blocks would be ignored.  And it could put the Lines on a designated Layer, and it could ....  . . . .   .  .  .  .

Kent Cooper, AIA
0 Likes
Message 17 of 20

Kent1Cooper
Consultant
Consultant

@Ranjit_Singh wrote:

....

....
			(setq endpoint (mapcar '+ startpoint (list (* ctr bldist) 0 0)))
....
	     (command-s "._line" startpoint endpoint "")
....

Not a single Line through the entire string of copies of the Blocks -- look again at the lower image in Post 5, and the first answer in Post 7 [lines (plural) between them].

Kent Cooper, AIA
0 Likes
Message 18 of 20

georg_holter
Contributor
Contributor

Hello,

This is my first post...I'am only reading usually. 🙂 And i'm beginner in lisp! 😞

 

I used "BAL" lips and it works perfectly!! thanks to Kent1Cooper for this awesome lisp!!!

What i wanna do is that this lisp is sorting the selected blocks by its attribute values for example "NL1/1" the next block has value "NL1/2", the next "NL1/3" and so forth... these are different blocks (and names) but they have all the same attribute tag: "STROMKREIS" with values: "NL1/1" next block "NL1/2" another block "NL1/3".....so i would have all the blocks sorted in a row... 🙂

I tried but i failed! Here's the modified code:

 

(defun C:BAL (/ osm bss pt rad len values blk n spc); = Block Align
;; for Blocks with primary Circle, with insertion point at its center
(setq osm (getvar 'osmode))
(prompt "\nBlöcke wählen, welche aufzulisten sind!")
(if
(and
(setq bss (ssget '((0 . "INSERT"))))
(setq pt (getpoint "\nLinken Startpunkt der Reihe angeben: "))
(setq rad 2)
(setq len 2)
); and
(progn ; then
(setvar 'osmode 0)
(setq values (cons (cadr
(assoc
"STROMKREIS"
(mapcar '(lambda (at)
(list (vla-get-tagstring at)(vla-get-textstring at)))
(vlax-invoke
(vlax-ename->vla-object (ssname blk (Setq i (1- i))))
'GetAttributes)
)
)
)
values
)
)
(repeat (setq n (sslength bss))
(command
"_.copy" (setq blk (ssname bss (setq n (1- n)))) ""
(cdr (assoc 10 (entget blk))) pt
); command
(setq pt (polar pt 0 rad))
); repeat
(setvar 'osmode osm)
); progn
); if
); defun

 

Do you have any ideas!? please help me! 🙂

Thank you!!!!

0 Likes
Message 19 of 20

georg_holter
Contributor
Contributor

For better understanding, here is such sample dwg! 🙂

0 Likes