### Author Topic: Array Question  (Read 6850 times)

0 Members and 1 Guest are viewing this topic.

#### hudster

• Gator
• Posts: 2848
##### Array Question
« on: October 06, 2005, 05:13:39 AM »
This is a stump the swamp question.

I don't know how to do it, and it's something i'm thinking about.

How woudl you array an object a set distance from a central location, arraying in all directions as per the following diagram.

Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #1 on: October 06, 2005, 06:11:59 AM »
2 separate polar array calls wrapped in a little ditty of a function.
Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #2 on: October 06, 2005, 06:50:49 AM »
Ok, I've had a coffee. My logic is flawed, one would have to calculate the matrix of offsets and then copy from the basepoint to each target offset. Seems to me I did something like this but it was about 12 years ago. Ackkk, searching ...
« Last Edit: October 06, 2005, 07:28:20 AM by MP »
Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #3 on: October 06, 2005, 07:56:55 AM »
Consider ...

Code: [Select]
`(setq matrix   '(        (-2  2) (-1  2) (0  2) (1  2) (2  2)        (-2  1) (-1  1) (0  1) (1  1) (2  1)        (-2  0) (-1  0) (0  0) (1  0) (2  0)        (-2 -1) (-1 -1) (0 -1) (1 -1) (2 -1)        (-2 -2) (-1 -2) (0 -2) (1 -2) (2 -2)    ))(setq scale 42.0)(setq scaledMatrix    (mapcar       '(lambda (point)            (mapcar               '(lambda (ordinate) (* scale ordinate))                point            )        )        matrix    ))(setq ReferencePoint '( 100 100 ))(setq offsetMatrix    (mapcar       '(lambda (point)            (mapcar '+ point ReferencePoint)        )        scaledMatrix    ))`
« Last Edit: October 06, 2005, 08:01:31 AM by MP »
Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: Array Question
« Reply #4 on: October 06, 2005, 08:16:42 AM »
Consider ...

I don't care what anyone else says, That IS pretty ...
kdub in one timeline.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<-

#### Keith

• Villiage Idiot
• Seagull
• Posts: 16899
• Superior Stupidity at its best
##### Re: Array Question
« Reply #5 on: October 06, 2005, 08:30:02 AM »
It'd be a roll yer own routine for sure ... something like a rectangular array with a "from center" option
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am

Find me on https://parler.com @kblackie

#### hudster

• Gator
• Posts: 2848
##### Re: Array Question
« Reply #6 on: October 06, 2005, 09:06:39 AM »
OK then,  just to add a wee bit to this.

How would you do it if you had to array an object the same way but it was off centre? As shown in this image.

Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #7 on: October 06, 2005, 09:32:31 AM »
I believe you may be looking for the MatrixOmatic ...

Code: [Select]
`(defun MatrixOmatic ( m n / *error* foo )    (defun *error* (msg)        (princ            (strcat                "Syntax: "                (chr 40)                "MakeMatrix m n"                (chr 41)                " where m and n are positive integers."            )        )        (princ)    )    (if        (not            (vl-every               '(lambda (x)                    (and                        (eq 'int (type x))                        (< 0 x)                    )                    )                (list m n)            )        )        (exit)    )    (defun foo ( x / result )        (   (lambda (k)                (repeat x                    (setq result                        (cons                            (setq k (1- k))                            result                        )                    )                )            )            (+ 0.5 (/ x 2.0))        )    )    (apply 'append        (mapcar           '(lambda (y)                (mapcar                   '(lambda (x) (list x y))                    (foo m)                )            )            (foo n)        )    ))`
(MatrixOmatic 4 3)

Code: [Select]
`(    (-1.5 -1.0) (-0.5 -1.0) (0.5 -1.0) (1.5 -1.0)     (-1.5  0.0) (-0.5  0.0) (0.5  0.0) (1.5  0.0)     (-1.5  1.0) (-0.5  1.0) (0.5  1.0) (1.5  1.0))`
« Last Edit: October 06, 2005, 10:20:22 AM by MP »
Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client

#### CAB

• Global Moderator
• Seagull
• Posts: 10401
##### Re: Array Question
« Reply #8 on: October 06, 2005, 09:45:00 AM »
WOW - neat stuff
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970

#### whdjr

• Guest
##### Re: Array Question
« Reply #9 on: October 06, 2005, 10:01:41 AM »
You could set the first option up as a dynamic block with 4 rect. arrays.

#### Sdoman

• Guest
##### Re: Array Question
« Reply #10 on: October 06, 2005, 03:23:40 PM »
I haven't had a chance to run your code MP, but it looks awesome.  Elegant algorithm.

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #11 on: October 06, 2005, 03:46:54 PM »
Thanks Steve, nice of you to say.

Here's a quick and dirty implementation of what Mr. Hudster wants (I think):

Code: [Select]
`(defun ArraySelectionAndDelete    (        ss        basepoint        rows        columns        xoffset        yoffset        /        *error*        makematrix        matrix        cmdecho    )    ;;  our help message    (defun *error* (msg)        (princ            (strcat                "Syntax: "                (chr 40)                "ArraySelectionAndDelete "                "ss "                "basepoint "                "rows "                "columns "                "xoffset "                "yoffset"                (chr 41)                "\nWhere ss        is a valid selection set\n"                "      basepoint is a 2D or 3D point\n"                "      rows      is a positive integer\n"                "      columns   is a positive integer\n"                "      xoffset   is a positive real\n"                "      yoffset   is a positive real\n"            )        )        (princ)    )    ;; this does the real grunt work    (defun makematrix ( m n / foo )        ;;  no need to error trap me, my        ;;  parent coding takes care of        ;;  making sure I get good data        (defun foo ( x / result )            (   (lambda (k)                    (repeat x                        (setq result                            (cons                                (setq k (1- k))                                result                            )                        )                    )                )                (+ 0.5 (/ x 2.0))            )        )        (apply 'append            (mapcar               '(lambda (y)                    (mapcar                       '(lambda (x) (list x y))                        (foo m)                    )                )                (foo n)            )        )    )    ;;  bozo filtering    (if        (or            (not (eq 'pickset (type ss)))            (not (< 0 (sslength ss)))            (not (listp basepoint))            (not (< 1 (length basepoint) 4))            (not (vl-every 'numberp basepoint))            (not                (vl-every                   '(lambda (x)                        (and                            (eq 'int (type x))                            (< 0 x)                        )                    )                    (list rows columns)                )            )            (not                (vl-every                   '(lambda (x)                        (and                            (numberp x)                            (< 0 x)                        )                    )                    (list xoffset yoffset)                )            )        )        (exit)    )    ;;  we're good, let's calculate     ;;  all the target points        (   (lambda (offset)            (setq matrix                (mapcar                   '(lambda (point)                        (mapcar '+                            (mapcar '* point offset)                            basepoint                        )                    )                    (makematrix                        rows                        columns                    )                )            )        )        (list xoffset yoffset)    )        ;;  shhhh ...    (setq cmdecho (getvar "cmdecho"))    (setvar "cmdecho" 0)    ;;  make all the copies    (foreach point matrix        (command            ".copy"            ss            ""            "_non"            basepoint            "_non"            point        )    )    ;;  trap a locked layers fubar    (vl-catch-all-apply       '(lambda ( )            (command                ".erase"                ss                ""            )        )    )    ;;  play nice    (setvar "cmdecho" cmdecho)    ;;  shhh ...    (princ))`
Example implementation:

Code: [Select]
`(defun c:ASAD ( / ss inibits )    (if (setq ss (ssget))        (ArraySelectionAndDelete            ss            (getpoint "\nSelect basepoint: ")            (progn                (initget (setq inibits (+ 1 2 4)))                (getint "Enter rows: ")            )            (progn                (initget inibits)                (getint "Enter columns: ")            )            (progn                (initget inibits)                (getdist "Enter xoffset: ")            )            (progn                (initget inibits)                (getdist "Enter yoffset: ")            )        )    )    (princ))`
Like I said, pretty quick and dirty but demonstrates (I hope) the general idea.
« Last Edit: October 06, 2005, 04:18:47 PM by MP »
Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client

#### CAB

• Global Moderator
• Seagull
• Posts: 10401
##### Re: Array Question
« Reply #12 on: October 06, 2005, 03:58:10 PM »
Possible pseudo code

User select objects (or entsel)
Get user pick center
...or get corner of bounding box
Copy object(s) with base point
Get number of array rows & columns
get offset amount(s) (row & col)
Get point offsets (MatrixOmatic rows columns)
Loop point offsets, adding offset to point
.. paste selection set to new point

PS too late but I'll post anyway
Let me see how close I got
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970

#### hudster

• Gator
• Posts: 2848
##### Re: Array Question
« Reply #13 on: October 07, 2005, 03:57:30 AM »
you guys are amazing, the best I could come up with was an idea to array it in four directions, but then i had duplicates and gave up.

It's timnes like this when I realise how little I know, and how far I still have to go.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

#### MP

• Seagull
• Posts: 17750
• Have thousands of dwgs to process? Contact me.
##### Re: Array Question
« Reply #14 on: October 07, 2005, 09:05:14 AM »
Hey Mr. Hudster -- please don't belittle or dismiss your talents -- everyone can learn this stuff -- it just takes genuine interest and time. It's obvious you have the interest, just not the time, 'cause like most folks programming isn't your primary vocation or interest.

So keep posting the ideas and questions, grab and digest as much as your time and interest affords and thanks for letting folks like me pitch in. I enjoy it and need to challenge what I think I know if I want to get better at this. In other words, you're doing me a great favor when you post challenges like this.

So thanks!

Engineering Technologist  CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client