VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing and modifying Rectangular, Polar and Path array objects in VBA

8 REPLIES 8
Reply
Message 1 of 9
spauliszyn
2087 Views, 8 Replies

Accessing and modifying Rectangular, Polar and Path array objects in VBA

Hi,

 

I can't seem to find how to edit properties of rectangular arrays using VBA.   Same goes for polar or path arrays.

 

For example, if I draw a circle in an empty drawing and then create a rectangular array using the command ARRAY, AutoCAD will typically creat a default array with 3 rows and 4 columns.  In VBA, ThisDrawing.ModelSpace.Count = 1 and ThisDrawing.ModelSpace(0).ObjectName = "AcDbBlockReference".  However, I can't see or modify any array properties such as row count, row spacing, row elevation increment, included angle, etc.

 

Any ideas?

 

Shawn

8 REPLIES 8
Message 2 of 9
cwilkes
in reply to: spauliszyn

vba help file says use this format:
"RetVal = object.ArrayRectangular(NumberOfRows, NumberOfColumns, NumberOfLevels, DistBetweenRows, DistBetweenColumns, DistBetweenLevels)"

 

might be a stupid question, but have you tried that?

 

also, what version of autocad are you using? I know arrays changed somewhere between 2010 and 2014. that may play in somehow too.

Message 3 of 9
spauliszyn
in reply to: cwilkes

Thanks cwilkes.

 

I have 2013.  If someone knows the answer for 2014 that would at least give me some direction.

 

The ‘ArrayRectangular’ method is for creating new unassociated arrays.  If you run the example given, you will find you have 25 new individual circles.

 

I want to start with existing associated arrays (rect, polar or path) in my drawing then manipulate them through VBA.

__________________________________________________________

 

My ultimate goal is to use the Path array to distribute an object (like floor joist) between two end points.  No problem so far for using the Path array. 

 

Now I want to add a twist:  I want my VBA to scan for Path arrays that have ‘Rows’ = 1.  If there is only one row then the ‘Row elevation increment’ property becomes rather redundant.  But I will use the ‘Row elevation increment’ as a minimum or maximum limit for the column spacing.  My macro will see that value and adjust the number of columns accordingly.  I can use zero to have the macro ignore it, a negative number for minimum spacing and a positive number for maximum spacing (or vice versa).

 

I hope that helps to clarify a bit.

Message 4 of 9
cwilkes
in reply to: spauliszyn

Ah, I see your point. Yeah, I checked just about every method/property for BlockReference (AutoCAD 2015 stores arrays as a BlockReference) and found nothing. Thought maybe they store the array variables as dynamicblockproperties or something.... but they don't.

 

I did, however find a way to do this with an array of dynamic blocks. The AutoCAD command MINSERT creates an array of a block references that they refer to as an MInsert Block. So if you can restructure your code to create the arrays out of blocks, you can definitely edit the amount of rows/columns and the distances of that particular type of array.

 

A couple lines just to show you what types and methods to use:

 

Dim insblk As AcadMInsertBlock
Dim inspt(0 To 2) As Double

Set insblk = ThisDrawing.ModelSpace.AddMInsertBlock(inspt, "dsa", 1, 1, 1, 0, 3, 3, 10, 10)

insblk.Columns = 10
insblk.Rows = 10

Inserts a 3x3 array of my block called "dsa" with 10 units between rows and columns, then immediately changes it to a 10x10 array. Works just fine. As far as editing existing object arrays, I think you're out of luck as far as vba goes.

Message 5 of 9
cwilkes
in reply to: spauliszyn

Apologies, I didn't see the end of your post before replying. The type I suggested is ONLY rectangular arrays. I don't believe they have the same type of thing for path arrays.

 

Good luck with a workaround.

Message 6 of 9
spauliszyn
in reply to: cwilkes

Hi cwilkes,

Thanks for the research!

I do however know about MInsertBlock but the object is more tedious to implement than to just use the 'ARRAY' command. At least the associated arrays can be manipulated by grips directly in model space (which is what I want).

My intent is to automate with as little user interaction as possible so I need to get at the properties of associated arrays in VBA for my idea to work.

It may be an XData entry in the block but I don't know how to get at it because I don't know the 'AppName' in order to use 'GetXData'. Is there a way to get the entire set of XData from an object? This would be the simplest method. Or maybe there is a simple LISP program that can act as a go-between for those and other useful bits of information (but I don't know anything about LISPSmiley Sad)

The less desirable method is to re-create my own associative array app and blocks, complete with simple ways to access the properties and grips. I hase tried to group a set of identical items and my macros automatically distributed them from the first to last item (in the ModelSpace.Item order). Then I could include max/mins in the group name itself. However, there are many difficulties and slowdowns that I have found when I make this automated.

I have exhausted all the help files like you did and googled it quite a bit over a few days. I am hoping that someone out there might know where the parameters of associated arrays are kept.

I know I am asking for a miracle and that there may be absolutely no way to get at it, but I am too stuborn and haven't resigned to giving up...

Message 7 of 9
spauliszyn
in reply to: spauliszyn

I found the 'List XData' in the Express Tools.  When I make a path array I found that there is no XData attached to either the path or the array object.

 

So much for that idea...Smiley Sad

Message 8 of 9
cwilkes
in reply to: spauliszyn

yeah I think for an object to have XData, you have to assign it XData. not 100% sure about that though.

 

Ok so let me ask this question. Are you opening some sort of template file and running analysis/editing it? Or are these human-generated drawings that you have to write a program to analyze/edit? If it's a template file.....

 

I have an idea, but I've actually got a question on this forum now that hasn't been answered that pertains to this. If the array rows and columns are set to "User Parameter" values, you can simply change those two parameters and it should reflect that in the array. In other words, in the parameters manager, you would add a rowcount variable and a colcount variable, then in the array editor ribbon, you simply type rowcount and colcount into the Rows and Columns boxes. My question.... how do you edit those user parameters with vba? haha it's kind of the same issue, but I'm more confident that the method to change User Parameters actually exists than the method to change dynamic array parameters. I know you can change dimensional parameters (constraints), not sure how to access the USER parameters. Which brings me to what may be a solution you can use. If you simply draw two lines (or even 2 points) and create a dimensional constraint on your object(s), you can drive the column and row counts based on that dimensional value. So if you are using some sort of template file, the steps would be:

 

1. open template

2. draw two lines.

3. add two dimensional constraints to those lines (parameters tab)

4. select array

5. insert those two dimensional constraint names (defaults will be d1, d2) into the rows/column boxes of your dynamic array.

6. use vba to edit those two dimensional constraint values (remember, integers only). I'm pretty sure you know this method to change dimensions, but if you don't i'll be glad to help.

7. regenerate and you array should update to the new values assigned to your two dimensions.

 

I've included a sample template with a bit of code. Hope this helps.

Message 9 of 9
spauliszyn
in reply to: cwilkes

We are getting there, at least by process of eliminationSmiley Wink

 

May or may not be a template.  I am the human creating or editing the drawing.

 

As a simple example for discussion purposes, I want an array of lines (or narrow rectangles) to show floor joists in a home/building.  Typically these are evenly spaced at a maximum spacing (say 16" which is pretty common for timber floor beams or framing studs).  I would like to position one at each end of the array and have the rest be filled in automatically.  I like the 'Path Array' idea because I can also supply a 'Start offset' and 'End offset'.  Now there may be dozens of these arrangements, all different, that I want to be able alter just by pulling on the grips of the array.

 

Constraints seem to be an interesting idea. But if try to alter the array by pulling on a grip, the constraint parameter will not automatically update.  In other words, if I can access restraint parameters though VBA, I can modify the array but not get feedback -- its only one way.  Not only that, I need to do allot of setup in order to get it to work whereas changing only one redundant parameter value in the path array itself is still very attractive (also easy for programing logic).

 

Here is another idea:  Lets say I have a non-printing layer for making useful reference lines, notes, etc.  And lets say i make a POLYLINE (or could be a LINE) on this layer and give it a thickness (pos number means min spacing and neg number means max spacing).  Then I make an un-named group out of it and the object I want duplicated.  I can have my macro scan for that combination and have it manually array the object along the non-printed polyline, using it's thickness as a spacing criteria.  Even better, I can have the macro listen for a GRIP_STRETCH on either object as a trigger so that it doesn't have to scan everything after every command and bog down the system.  This would look a bit awkward if I was using 3D.

 

I already have something similar implemented.  If I group a number of items with a group name starting with 'S', my macro will automatically distribute them between the first and last items.  If all the items are the same type, the macro will even morph the objects as it distributes them (see attached picture).  

 

But still, I think if I can just get at the ARRAYPATH parameters through VBA, it would be a cleaner, simpler implementation with all the added benefits than come with the path array.

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost