Author Topic: Auto Arrange  (Read 9957 times)

0 Members and 1 Guest are viewing this topic.

liuhaixin88

  • Guest
Auto Arrange
« on: April 28, 2014, 10:52:18 AM »
Who has seen anything like it ?  lisp ,fas,vlx ?

Auto Arrange , minimal area . Choose arrange clearance & quantity.

[BTW:Authors blame I issued his pictures , SO I was delete it ]

« Last Edit: May 02, 2014, 03:27:00 AM by liuhaixin88 »

ChrisCarlson

  • Guest
Re: Auto Arrange
« Reply #1 on: April 28, 2014, 10:55:26 AM »
Arrange what?

Blocks?
Text?
Mleaders?


liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #2 on: April 28, 2014, 11:03:38 AM »
Arrange what?

Blocks?
Text?
Mleaders?

I just upload the image.

BlackBox

  • King Gator
  • Posts: 3770
Re: Auto Arrange
« Reply #3 on: April 28, 2014, 11:30:28 AM »
A few Commands come to mind... Array, Measure, Divide, etc.
"How we think determines what we do, and what we do determines what we get."

liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #4 on: April 28, 2014, 12:33:50 PM »
A few Commands come to mind... Array, Measure, Divide, etc.

Hello ,BB

It's Not so easy, need related to the algorithm, Like the minimum bounding box.

First ,I don't know how to arrange for the smallest area.

Found a related demonstration:



« Last Edit: May 02, 2014, 03:27:49 AM by liuhaixin88 »

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Auto Arrange
« Reply #5 on: April 28, 2014, 02:09:13 PM »
Look for nesting algorithms.  Should be several threads here on the subject if memory serves.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Auto Arrange
« Reply #6 on: April 28, 2014, 06:30:40 PM »
This is how I would arrange 23 3D entities in 3D... Like in 2D and in my version linear arrangement prevails - only in Z direction...

See attachment...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #7 on: April 28, 2014, 10:52:27 PM »
This is how I would arrange 23 3D entities in 3D... Like in 2D and in my version linear arrangement prevails - only in Z direction...

See attachment...

Ribarm, I know you proficient algorithm.The first person.

Can you help me?


liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #8 on: April 29, 2014, 10:19:08 PM »
This is how I would arrange 23 3D entities in 3D... Like in 2D and in my version linear arrangement prevails - only in Z direction...

See attachment...

Please,marko, I need your help. Any file formats all ok! (VLX ,FAS,ARX)

ChrisCarlson

  • Guest
Re: Auto Arrange
« Reply #9 on: April 30, 2014, 07:56:28 AM »
Download Nestlib Online from the Acad App exchange

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Auto Arrange
« Reply #10 on: April 30, 2014, 11:03:54 AM »
This is similar to your 11.gif... It uses rotate&copy, but not mirror... Tested on simple LWPOLYLINES like on posted 11.gif...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rotarrange ( / adoc msp LM:MinEncCircle LM:RemoveWithFuzz LM:GetInsideAngle LM:3PCircle mid LM:ConvexHull LM:Clockwise-p LM:LWPoly->List pl n ri vl c plc xl ip p ipl d dl dminv dminvl dmaxv dmaxvl dmax1 dmax2 ipp pp ippl tst dmaxl dmin dlst->dmin )
  2.  
  3.   (setq msp (vla-get-modelspace adoc))
  4.  
  5.   (defun LM:MinEncCircle ( lst / _sub )
  6.  
  7.       (defun _sub ( p1 p2 l1 / a1 a2 l2 p3 p4 )
  8.           (setq l2 (LM:RemoveWithFuzz (list p1 p2) l1 1e-8)
  9.                 p3 (car l2)
  10.                 a1 (LM:GetInsideAngle p1 p3 p2)
  11.           )
  12.           (foreach p4 (cdr l2)
  13.               (if (< (setq a2 (LM:GetInsideAngle p1 p4 p2)) a1)
  14.                   (setq p3 p4 a1 a2)
  15.               )
  16.           )
  17.           (cond
  18.               (   (<= (/ pi 2.0) a1)
  19.                   (list (mid p1 p2) (/ (distance p1 p2) 2.0))
  20.               )
  21.               (   (vl-some
  22.                       (function
  23.                           (lambda ( a b c )
  24.                               (if (< (/ pi 2.0) (LM:GetInsideAngle a b c)) (_sub a c l1))
  25.                           )
  26.                       )
  27.                       (list p1 p1 p2) (list p2 p3 p1) (list p3 p2 p3)
  28.                   )
  29.               )
  30.               (   (LM:3PCircle p1 p2 p3)   )
  31.           )
  32.       )
  33.  
  34.       ((lambda ( lst ) (_sub (car lst) (cadr lst) lst)) (LM:ConvexHull lst))
  35.   )
  36.  
  37.   ;; Remove With Fuzz  -  Lee Mac
  38.   ;; Removes items from a list which are equal to a supplied tolerance
  39.  
  40.   (defun LM:RemoveWithFuzz ( l1 l2 fz )
  41.       (vl-remove-if
  42.           (function
  43.               (lambda ( a )
  44.                   (vl-some
  45.                       (function (lambda ( b ) (equal a b fz)))
  46.                       l1
  47.                   )
  48.               )
  49.           )
  50.           l2
  51.       )
  52.   )
  53.  
  54.   ;; Get Inside Angle  -  Lee Mac
  55.   ;; Returns the smaller angle subtended by three points with vertex at p2
  56.  
  57.   (defun LM:GetInsideAngle ( p1 p2 p3 )
  58.       (   (lambda ( a ) (min a (- (+ pi pi) a)))
  59.           (rem (+ pi pi (- (angle p2 p1) (angle p2 p3))) (+ pi pi))
  60.       )
  61.   )
  62.  
  63.   ;; 3-Point Circle  -  Lee Mac
  64.   ;; Returns the Center and Radius of the Circle defined by
  65.   ;; the supplied three points.
  66.  
  67.   (defun LM:3PCircle ( p1 p2 p3 / cn m1 m2 )
  68.       (setq m1 (mid p1 p2)
  69.             m2 (mid p2 p3)
  70.       )
  71.       (list
  72.           (setq cn
  73.               (inters
  74.                   m1 (polar m1 (+ (angle p1 p2) (/ pi 2.)) 1.0)
  75.                   m2 (polar m2 (+ (angle p2 p3) (/ pi 2.)) 1.0)
  76.                   nil
  77.               )
  78.           )
  79.           (distance cn p1)
  80.       )
  81.   )
  82.  
  83.   ;; Midpoint - Lee Mac
  84.   ;; Returns the midpoint of two points
  85.  
  86.   (defun mid ( a b )
  87.       (mapcar (function (lambda ( a b ) (/ (+ a b) 2.0))) a b)
  88.   )
  89.  
  90.   ;; Convex Hull  -  Lee Mac
  91.   ;; Implements the Graham Scan Algorithm to determine the
  92.   ;; Convex Hull of a list of points.
  93.  
  94.   (defun LM:ConvexHull ( lst / hul p0 )
  95.       (cond
  96.           (   (< (length lst) 4)
  97.               lst
  98.           )
  99.           (   t
  100.               (setq p0 (car lst))
  101.               (foreach p1 (cdr lst)
  102.                   (if (or (< (cadr p1) (cadr p0))
  103.                           (and (= (cadr p1) (cadr p0)) (< (car p1) (car p0)))
  104.                       )
  105.                       (setq p0 p1)
  106.                   )
  107.               )
  108.               (setq lst
  109.                   (vl-sort lst
  110.                       (function
  111.                           (lambda ( a b / c d )
  112.                               (if (or (equal (setq c (angle p0 a)) (setq d (angle p0 b)) 1e-8) (and (or (equal c 0.0 1e-8) (equal c (* 2 pi) 1e-8)) (or (equal d 0.0 1e-8) (equal d (* 2 pi) 1e-8))))
  113.                                   (< (distance (list (car p0) (cadr p0)) a) (distance (list (car p0) (cadr p0)) b))
  114.                                   (< c d)
  115.                               )
  116.                           )
  117.                       )
  118.                   )
  119.               )
  120.               (setq hul (list (caddr lst) (cadr lst) (car lst)))
  121.               (foreach pt (cdddr lst)
  122.                   (setq hul (cons pt hul))
  123.                   (while (and (caddr hul) (LM:Clockwise-p (caddr hul) (cadr hul) pt))
  124.                       (setq hul (cons pt (cddr hul)))
  125.                   )
  126.               )
  127.               hul
  128.           )
  129.       )
  130.   )
  131.  
  132.   ;; Clockwise-p  -  Lee Mac
  133.   ;; Returns T if p1,p2,p3 are clockwise oriented or collinear
  134.                    
  135.   (defun LM:Clockwise-p ( p1 p2 p3 )
  136.       (<  (-  (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
  137.               (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
  138.           )
  139.           1e-8
  140.       )
  141.   )
  142.  
  143.   ;; LWPolyline to Point List  -  Lee Mac
  144.   ;; Returns a list of points describing the supplied LWPolyline
  145.  
  146.   (defun LM:LWPoly->List ( ent n / der di1 di2 inc lst par )
  147.       (setq par 0)
  148.       (repeat (cdr (assoc 90 (entget ent)))
  149.           (if (setq der (vlax-curve-getsecondderiv ent par))
  150.               (if (equal der '(0.0 0.0 0.0) 1e-8)
  151.                   (setq lst (cons (vlax-curve-getpointatparam ent par) lst))
  152.                   (if
  153.                       (setq di1 (vlax-curve-getdistatparam ent par)
  154.                             di2 (vlax-curve-getdistatparam ent (1+ par))
  155.                       )
  156.                       (progn
  157.                           (setq inc (/ (- di2 di1) n))
  158.                           (while (< di1 di2)
  159.                               (setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
  160.                                     di1 (+ di1 inc)
  161.                               )
  162.                           )
  163.                           (if (equal (vlax-curve-getpointatdist ent di1) (vlax-curve-getendpoint ent) 1e-8)
  164.                               (setq lst (cons (vlax-curve-getendpoint ent) lst))
  165.                           )
  166.                       )
  167.                   )
  168.               )
  169.           )
  170.           (setq par (1+ par))
  171.       )
  172.       lst
  173.   )
  174.  
  175.   (while (or (not (setq pl (car (entsel "\nPick LWPOLYLINE shape")))) (not (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))))
  176.   (initget 7)
  177.   (setq n (getint "\nSpecify rotational derivation of full rotation - 360 degree / ? : "))
  178.   (setq ri (/ 360.0 n))
  179.   (setq ri (* (/ ri 180.0) pi))
  180.   (setq c (car (LM:MinEncCircle (LM:LWPoly->List pl 25))))
  181.   (repeat n
  182.     (if plc (entdel (vlax-vla-object->ename plc)))
  183.     (vla-rotate (vlax-ename->vla-object pl) (vlax-3d-point c) ri)
  184.     (setq vl (LM:LWPoly->List pl 36))
  185.     (foreach v vl
  186.       (setq xl (vla-addxline msp (vlax-3d-point v) (vlax-3d-point (mapcar '+ v '(1.0 0.0 0.0)))))
  187.       (setq ip (vlax-invoke xl 'intersectwith (vlax-ename->vla-object pl) acextendnone))
  188.       (if (/= (length ip) 3)
  189.         (progn
  190.           (repeat (/ (length ip) 3)
  191.             (setq p (list (car ip) (cadr ip) (caddr ip)))
  192.             (setq ip (cdddr ip))
  193.             (setq ipl (cons p ipl))
  194.           )
  195.           (foreach p ipl
  196.             (setq d (distance v p))
  197.             (setq dl (cons d dl))
  198.           )
  199.           (setq dminv (cadr (vl-sort dl '<)))
  200.           (setq dmaxv (apply 'max dl))
  201.           (if dminv (setq dminvl (cons dminv dminvl)))
  202.           (if dmaxv (setq dmaxvl (cons dmaxv dmaxvl)))
  203.           (setq ipl nil dl nil)
  204.         )
  205.       )
  206.       (entdel (vlax-vla-object->ename xl))
  207.     )
  208.     (setq dmax1 (apply 'max dminvl))
  209.     (setq dminvl nil)
  210.     (setq dmax2 (apply 'max dmaxvl))
  211.     (setq dmaxvl nil)
  212.     (setq plc (vla-copy (vlax-ename->vla-object pl)))
  213.     (vla-move plc (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point (list dmax1 0.0 0.0)))
  214.     (setq ipp (vlax-invoke plc 'intersectwith (vlax-ename->vla-object pl) acextendnone))
  215.     (repeat (/ (length ipp) 3)
  216.       (setq pp (list (car ipp) (cadr ipp) (caddr ipp)))
  217.       (setq ipp (cdddr ipp))
  218.       (setq ippl (cons pp ippl))
  219.     )
  220.     (foreach p ippl
  221.       (if (vl-some '(lambda ( x ) (equal x p 1e-8)) vl) (setq tst (cons t tst)) (setq tst (cons nil tst)))
  222.     )
  223.     (if (not (eval (cons 'and tst)))
  224.       (progn
  225.         (vla-move plc (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point (list (- dmax1) 0.0 0.0)))
  226.         (vla-move plc (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point (list dmax2 0.0 0.0)))
  227.         (setq dmaxl (cons dmax2 dmaxl))
  228.       )
  229.       (setq dmaxl (cons dmax1 dmaxl))
  230.     )
  231.     (setq tst nil ippl nil)
  232.     (vla-regen adoc 1)
  233.   )
  234.   (setq dmin (apply 'min dmaxl))
  235.   (setq dmaxl (reverse dmaxl))
  236.   (setq dlst->dmin (reverse (member dmin (reverse dmaxl))))
  237.   (foreach d dlst->dmin
  238.     (if plc (entdel (vlax-vla-object->ename plc)))
  239.     (vla-rotate (vlax-ename->vla-object pl) (vlax-3d-point c) ri)
  240.     (setq plc (vla-copy (vlax-ename->vla-object pl)))
  241.     (vla-move plc (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point (list d 0.0 0.0)))
  242.     (vla-regen adoc 1)
  243.   )
  244.   (princ)
  245. )
  246.  

HTH
« Last Edit: June 19, 2019, 12:57:07 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3272
  • Marko Ribar, architect
Re: Auto Arrange
« Reply #11 on: May 01, 2014, 02:56:08 AM »
Now, above posted code works and with more complex shapes, but only with LWPOLYLINE with straight segments (edges)...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #12 on: May 01, 2014, 08:48:47 PM »
Now, above posted code works and with more complex shapes, but only with LWPOLYLINE with straight segments (edges)...

M.R.

Marko, Thanks very much for your hard work.

Two objects  are rotated counterclockwise. I think , when rotated counterclockwise later, one objects rotated counterclockwise, one objects rotated clockwise.

Q1241274614

  • Guest
Re: Auto Arrange
« Reply #13 on: May 01, 2014, 11:30:03 PM »
After combination, such a minimum area.


http://www.theswamp.org/index.php?topic=46636.0

« Last Edit: May 01, 2014, 11:34:57 PM by Q1241274614 »

liuhaixin88

  • Guest
Re: Auto Arrange
« Reply #14 on: May 02, 2014, 12:40:17 AM »
After combination, such a minimum area.


http://www.theswamp.org/index.php?topic=46636.0

Thanks for providing ideas.
« Last Edit: May 02, 2014, 03:31:38 AM by liuhaixin88 »