Author Topic: Create associative rectangular array  (Read 2125 times)

0 Members and 1 Guest are viewing this topic.

scottcd

  • Newt
  • Posts: 52
Create associative rectangular array
« on: March 21, 2016, 10:28:33 AM »
I have the following code which I use to create a rectangular array of a rectangle which is 50x50

But it is not associative - is there a variable I need to set as well?

Thanks

Scott


Code: [Select]
(defun c:ag ()
  (vl-load-com)
  (setq util (vla-get-utility
       (vla-get-activedocument
(vlax-get-acad-object)
       )
     )
  )
  (vla-getentity util 'obj 'ip "\nSelect Object: ")
  (setq numrows   4
numcols   4
drows   50
dcols   50
numlevels 1
dlevels   0
arrayobj  (vla-ArrayRectangular
    obj numrows numcols numlevels drows dcols dlevels)
  )
  (princ)
)
AutoCAD Dos R9 - 2018 and BricCAD 18.2

scottcd

  • Newt
  • Posts: 52
Re: Create associative rectangular array
« Reply #1 on: March 22, 2016, 10:32:32 AM »
https://forums.autodesk.com/t5/autocad-2013-2014-2015-2016-2017/how-to-use-new-array-command-with-lisp/td-p/6040598

After looking at the above link I have resorted to the use of the command

Code: [Select]
(defun c:gaa ()
  (vl-load-com)
  (setq ss (ssget "_:L"))
  (setq therows 4
thecols 4
drows 50
dcols 50
  )
  (if ss
    (vla-sendcommand
      (vla-get-activedocument (vlax-get-acad-object))
      (strcat "array\rp\r\rR\rROW\r"
      (itoa therows)
      "\n"
      (rtos drows 2 10)
      "\n\nCOL\r"
      (itoa thecols)
      "\r"
      (rtos dcols 2 10)
      "\r\r"
      )
    )
  )
)

Must admit I don't understand how the vla-sendcommand bit works?
AutoCAD Dos R9 - 2018 and BricCAD 18.2

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create associative rectangular array
« Reply #2 on: March 22, 2016, 11:17:20 AM »
I don't see any reason for using (vla-sendcommand ...) instead of (command ...) here.

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Create associative rectangular array
« Reply #3 on: March 22, 2016, 11:19:22 AM »
why not do this with a dynamic block?  then the grid could be any size, and possibly more useful
Be your Best


Michael Farrell
http://primeservicesglobal.com/

ChrisCarlson

  • Guest
Re: Create associative rectangular array
« Reply #4 on: March 22, 2016, 12:21:19 PM »
Dynamic block would have static pieces with dynamic actions, using array any object (dynamic) would be arrayed associative (dynamic).

scottcd

  • Newt
  • Posts: 52
Re: Create associative rectangular array
« Reply #5 on: March 24, 2016, 04:03:39 AM »
Hi Roy

I just couldn't work out the syntax for using command and the only example I could find was send command.

Hi ChrisCarlson  and  mjfarrell

Thanks for the responses.

As regards dynamic block, you are probably right but I was just trying to reproduce what I was doing manually and was just interested in trying to resolve why the array wasn't associative.

I am really just trying to draw a coordinate grid so I only draw it once in the job so there is no advantage in either method really.

Thanks again for your suggestions.

Scott
AutoCAD Dos R9 - 2018 and BricCAD 18.2

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Create associative rectangular array
« Reply #6 on: March 24, 2016, 07:54:43 AM »
This works in BricsCAD:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:gaa ( / ss dcols drows thecols therows)
  2.   (setq ss (ssget "_:L"))
  3.   (setq
  4.     therows 4
  5.     thecols 4
  6.     drows 50
  7.     dcols 50
  8.   )
  9.   (if ss (command "_.arrayrect" ss "" "_row" therows drows "_col" thecols dcols "_exit"))
  10. )