LISP TO CHANGE VERTICAL ALIGNMENT TO HORIZONTAL ALIGNMENT

LISP TO CHANGE VERTICAL ALIGNMENT TO HORIZONTAL ALIGNMENT

Anonymous
Not applicable
3,708 Views
11 Replies
Message 1 of 12

LISP TO CHANGE VERTICAL ALIGNMENT TO HORIZONTAL ALIGNMENT

Anonymous
Not applicable

I would like to know if anyone has a LISP for changing the vertical alignment to horizontal alignment, as shown in the attached drawing or screenshot . I would like to run it on open drawing. On running the lisp it should ask to select an area containing the vertical objects and then it would arrange all the object horizontally in a selected rectangle or at least in a straight line with option to define spacing between. We have to perform this work through copy and paste repeatedly in our office . But it takes time , i want to automate this through lisp but have no idea.

Thanks to anyone that has something like this and wants to share.

0 Likes
Accepted solutions (1)
3,709 Views
11 Replies
Replies (11)
Message 2 of 12

cadffm
Consultant
Consultant

Impossible, you or better a program need some objects as reference.. and i can not see such an objects.

For example: For each object heap (i am not sure if you can understand this how i mean that, lol), one closed polyline.

 

And YES, many users in the world use a program that can do that.

 

180920-2.JPG

 

 

 

Sebastian

0 Likes
Message 3 of 12

Kent1Cooper
Consultant
Consultant

If each set of objects were a Block, I could come up with something, with a fairly simple modification of BlockChart.lsp [see >here< -- it's about Inserting drawings from a folder, but could be adjusted easily enough for selected Blocks].  But with all of the sets made up of individual pieces, it's hard to imagine how a routine could figure out which ones belong in each set, i.e. which to Move together.

Kent Cooper, AIA
0 Likes
Message 4 of 12

Anonymous
Not applicable

OK if each heap of object is enclosed with rectangle, than is it possible to write a lisp to arrange these object enclosed in rectangle from VERTICAL ARRANGEMENT To HORIZONTAL ARRANGEMENT with some offset . The lisp should ask to select the rectangle and then it should ask for offset and then it arranges all the objects enclosed in the rectangles horizontally.

 

 

0 Likes
Message 5 of 12

Anonymous
Not applicable

OK if each heap of object is enclosed with rectangle, than is it possible to write a lisp to arrange these object enclosed in rectangle from VERTICAL ARRANGEMENT To HORIZONTAL ARRANGEMENT with some offset . The lisp should ask to select the rectangle and then it should ask for offset and then it arranges all the objects enclosed in the rectangles horizontally.

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... if each heap of object is enclosed with rectangle....


Is the idea that you would go around and draw that rectangle around each set of objects, and then select all the rectangles for the relocating?  Would it place them horizontally in the same sequence as the vertical sequence, even if the drawing order of the rectangles did not match that?  And then would you want to Erase all the rectangles?

 

If so, how about if a routine were to just ask you to select each set [by whatever means you choose], and [the one thing that would require a little  bit more care on the part of the User] to select the sets in the order  you want them to have in the horizontal arrangement?  It's possible to find the effective overall bounding box of a set of objects, and it could use those for positioning each set with a gap from the previous one.  Then there would be no need to draw, nor to Erase, the rectangles.  And if you had reason to, it would be easy to have the horizontal sequence vary from the vertical sequence.  And the original objects wouldn't need to be in anything like a vertical sequence -- they could be scatter-shot all over the place.

Kent Cooper, AIA
0 Likes
Message 7 of 12

dbhunia
Advisor
Advisor

Dear Karat,

Please check the attached Lisp... Hopefully it will full fill your requirement.....


@Anonymous wrote:

OK if each heap of object is enclosed with rectangle, than is it possible to write a lisp to arrange these object enclosed in rectangle from VERTICAL ARRANGEMENT To HORIZONTAL ARRANGEMENT with some offset . The lisp should ask to select the rectangle and then it should ask for offset and then it arranges all the objects enclosed in the rectangles horizontally.


But there I had considered two things-

1. All Bounding rectangles are drawn from "Left Bottom corner" to "Right Top corner" in the Drawing (So if you change this order, then make the necessary changes in LISP).

2. All Bounding rectangles are in a Layer "RAFT BEAM".

So you have follow these two things for all other drawings, otherwise you have make changes in the LISP.

Now my advise -

1. Always Keep the Bounding Rectangles are in a separate Layer, otherwise you can not differentiate the Bounding rectangles from other Rectangles .

2. In LISP the Input of "Offset Distance" has considered in "mm" (because internally AutoCAD calculate everything in "mm"), so if you want to get Input of "Offset Distance" in "Feet-Inch" then you make the necessary changes in LISP.


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... how about if a routine were to just ask you to select each set ..., and ... to select the sets in the order  you want them to have in the horizontal arrangement?  .... no need to draw, nor to Erase, the rectangles.  ....

Like this [very lightly tested]:

 

;| SetsInRow.lsp [command name: SIR]
To position any number of User-selected sets of objects in a horizontal row,
spaced apart by a User-specified gap size.
Places first set with the bottom of its overall extents aligned with the bottom
of the drawing's overall extents, and its left side to the right of the drawing's
overall right side by the gap size.  Successive sets are placed to the right of
what comes before, aligned at the bottom.
Zooms to Extents initially, but User can Pan and/or Zoom around in process
without affecting results.
Remembers gap size and offers as default on subsequent use.
Kent Cooper, 25 September 2018
|;

(defun C:SIR (/ LR ss n eLL eUR sLL sUR swid); = Sets In Row
  (command "_.zoom" "_extents"); make all visible, reset EXTMIN/EXTMAX
  (initget (if *SIRgap 6 7)); no zero, no negative, no Enter on first use
  (setq
    LR (list (car (getvar 'extmax)) (cadr (getvar 'extmin)))
    *SIRgap
      (cond
        ( (getdist
            (strcat
              "\nGap size between sets"
              (if *SIRgap (strcat " <" (rtos *SIRgap) ">") "")
              ": "
            ); strcat
          ); getdist
        ); User-input condition
        (*SIRgap); prior value on Enter when permitted
      ); cond & *SIRgap
  ); setq
  (while (setq ss (ssget "_:L"))
    (setq sLL nil sUR nil)
    (repeat (setq n (sslength ss))
      (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq n (1- n)))) 'minpt 'maxpt)
      (setq
        eLL (vlax-safearray->list minpt); entity's Lower Left
        eUR (vlax-safearray->list maxpt)
        sLL (if sLL (mapcar 'min eLL sLL) eLL); set's Lower Left
        sUR (if sUR (mapcar 'max eUR sUR) eUR)
        swid (- (car sUR) (car sLL)); set's width
      ); setq
    ); repeat
    (command "_.move" ss "" "_none" sLL "_none" (polar LR 0 *SIRgap))
    (setq LR (polar LR 0 (+ swid *SIRgap)))
  ); while
  (princ)
); defun

(vl-load-com)
(prompt "\nType SIR to put Sets In a Row.")
Kent Cooper, AIA
0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant

@dbhunia wrote:

....

2. In LISP the Input of "Offset Distance" has considered in "mm" (because internally AutoCAD calculate everything in "mm"), so if you want to get Input of "Offset Distance" in "Feet-Inch" then you make the necessary changes in LISP.


 

AutoCAD does not  calculate everything in millimeters.  It calculates everything in drawing units, and the drawing unit can be whatever you want it to be.  Change your Offset Distance to use (getdist) instead of going to the trouble of converting a text string into a number, it will return it in whatever your drawing units are.  That is, change this:


(setq Off_Dist (atof (getstring "\nSpecify Offset Distance (In mm) : ")))

 

to something like this:

 

(setq Off_Dist (getdist "\nSpecify Offset Distance: "))

 

Another advantage of using (getdist) is that if you're in feet-&-inches units, you can type in the distance in that kind of format, i.e. something like 12'6 or 9-1/2, and it will return 150.0 or 9.5 drawing units, whereas (atof) applied to those as text strings would give the wrong result.  And another  advantage is that you can specify the distance by picking two points on-screen, if you prefer that over typing in a value.

Kent Cooper, AIA
0 Likes
Message 10 of 12

dbhunia
Advisor
Advisor
Accepted solution

@Kent1Cooper wrote:

@dbhunia wrote:

....

2. In LISP the Input of "Offset Distance" has considered in "mm" (because internally AutoCAD calculate everything in "mm"), so if you want to get Input of "Offset Distance" in "Feet-Inch" then you make the necessary changes in LISP.


 

AutoCAD does not  calculate everything in millimeters.  It calculates everything in drawing units, and the drawing unit can be whatever you want it to be. 


 

Dear Kent,

 

If internally AutoCAD does not calculate every thing in millimeters, then why the extracted properties gives all values in millimeters all time even the "Drawing Units" are set in "Architectural"? 

Untitled.png

 

 

 

Dear Karat,

 

I am attaching modified lisp go through with this one...

with this LISP-

1. No need to follow Bounding rectangles draw order i.e. from "Left Bottom corner" to "Right Top corner" in the Drawing.

2. There is no boundation in Input of "Offset Distance" unit.

Only advise -

1. To keep All Bounding rectangles in a single Layer.


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

@dbhunia wrote
Dear Kent,

....

If internally AutoCAD does not calculate every thing in millimeters, then why the extracted properties gives all values in millimeters all time even the "Drawing Units" are set in "Architectural"? ….


 

They're not millimeters just because they don't show feet-and-inches marks.  They're just real numbers, representing drawing units.  In Architectural format, a drawing unit is an inch.  If you draw a Line whose start point is at an X coordinate of 3'-6" and a Y coordinate of 2'-1 1/2" [at an elevation of 0], its entity data list will include its start point as (10 42.0 25.5 0.0), which represent the number of inches  of those values, expressed in a "raw" real number without feet-and-inches markings, but they are still in inches.  If it were storing things in millimeters, it would say something like (10 1066.8 647.4 0.0) instead.

 

[By the way, the values in your entity data list image show that you're working a very long way  from the drawing origin -- the X coordinate of the first Circle's center is about 4-2/3 miles  away.  Just be aware that certain problems can sometimes result from working that far from the origin.]

Kent Cooper, AIA
Message 12 of 12

Anonymous
Not applicable

Thanks Debashis Bhunia Sir,

This is what I was trying to do, Thanks once again 

0 Likes