Family with parametric array

Family with parametric array

Anonymous
Not applicable
1,779 Views
12 Replies
Message 1 of 13

Family with parametric array

Anonymous
Not applicable

Hi, 

 

I am trying to create programmatically a family similar to the RFA file that I have attached. It is a parametric array of extrusions. As you can see, the reference Group contains an extrusion constrained by width, height and position (X, Y). Also I added a parameter for the number of elements that contains the array and the offset between the elements.

 

Manually, I can add the width and height dimensions when it is being created the sketch of the extrusion. This way, I don't get any constraint issue when I start changing the parameters via Family type table. Is it possible to create programmatically an array using this way? Do you know how could I constraint the width and height of the extrusion to not get the exception "Constraints are not satisfied"?

 

Thanks in advance,

 

 

0 Likes
1,780 Views
12 Replies
Replies (12)
Message 2 of 13

eason.kangEDLV4
Autodesk Support
Autodesk Support

Please accept our sincere apologies for the late, we have a backlog in the queue.

 

Here are two API classes for creating arrays of Revit elements, LinearArray and RadialArray. In this case, you can use the LinearArray.create to create the same thing in the RFA you provided. Here is a example for you:

 

 

var eRef = this.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
			
if( eRef == null ) return;

// The first element you want to copy var element = this.Document.GetElement( eRef ); using(var trans = new Transaction( this.Document, "Create Linear Array of a element" ) ) { try { if( trans.Start() == TransactionStatus.Started ) {
// Offset first element every 500 mm in X direction
var offset = new XYZ( UnitUtils.ConvertToInternalUnits( 500, DisplayUnitType.DUT_MILLIMETERS ), 0 , 0 );
// Element count of this array
var n = 5;
var result = LinearArray.Create( this.Document, this.ActiveView, element.Id, n, offset, ArrayAnchorMember.Second ); trans.Commit(); } } catch( Exception ex ) { trans.RollBack(); TaskDialog.Show( "Revit", ex.Message ); } }

 

The ArrayAnchorMemeber has two types:

  1. Second: The translation or rotation value specifies the location of the second member of the array.
  2. Last: The translation or rotation value specifies the location of the last member of the array.

They are the same as you seen in the Revit UI:

ArrayAnchorMember.jpg

 

 

For more detail, you can refer:

  1. http://www.revitapidocs.com/2016/33520964-cb76-56b5-a303-bd2bad01adfe.htm
  2. https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/Revit-API/files/GUID-...

 

Hope this helps.

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 3 of 13

Anonymous
Not applicable

Thanks Eason,

 

the main problem that I have with that RFA file is, to constraint the array programmatically. I know how to control the number of elements of the array, but I don't how to control parametrically the offset value between element array. Also, if I constraint the element that I want to use in the array, I get the message error: "Constraints are not satisfied".

 

So, the idea would be to create programmatically a similar RFA file as the file that attached in my last post. 

 

Thanks in advance,

0 Likes
Message 4 of 13

eason.kangEDLV4
Autodesk Support
Autodesk Support

Hi,

 

You can use the doc.FamilyCreate.NewLinearDimension() to create a offset annotation, doc.FamilyManager.AddParameter() to add a parameter called offset and assign it to the offset annotation, just like what you do on the Revit UI. Here is a reference for you:

 

http://thebuildingcoder.typepad.com/blog/2010/02/creating-a-dimension-label.html

 

If this didn't match what you want, I'd like to suggest you provide a none-confidential reproducible case to us, so that we can help you figure out what happened. A none-confidential reproducible case contains:

  1. A short exact description of what you are trying to achieve.
  2. The behavior you observe versus what you expect, and why this is a problem.
  3. A complete yet minimal Revit sample model to run a test in.
  4. A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyze its behavior live in the sample model.
  5. Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.

Hope it helps.

 

Cheers,

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 5 of 13

Anonymous
Not applicable

Hi Eason, 

 

Find below the first problem that we faced when we add a constrained box (dimensions, reference lines and a extrusion ) to the array. 

 

1. A short exact description of what you are trying to achieve.

I'm trying to copy a constrained box in an array. This way, anytime that I change the width or height of the box, the duplicated boxes will also change their dimensions.

 

2. The behavior you observe versus what you expect, and why this is a problem.

I get the following message when the function Commit() is called:

arrayparametric.png

I expect that the array is created correctly and I can modify the number of copies of the initial box using the parameter table.

 

3. A complete yet minimal Revit sample model to run a test in.

4. A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyze its behavior live in the sample model.

Find attached a simple Revit plugin which reproduces the issue.

 

5. Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.

- Run Revit
- Go to "Add-Ins" tab
- Expand "External Tools" button and select "Command ArrayParametric"
- Error - Cannot be ignored: "Changes to groups are allowed only in group edit mode. Use the Edit Group command to change to all instances of a group type. You may use the "Ungroup" option to proceed with this change by ungrouping the changed group instances."

 

Another question would be if it is possible to constraint the translation vector of that array programmatically? 

 

Thanks in advance,

0 Likes
Message 6 of 13

eason.kangEDLV4
Autodesk Support
Autodesk Support

The error caused by line 38-39, you shouldn't array the annotation elements.

 

And line 48 should be changed to

LinearArray linearArray = LinearArray.Create(doc, pView, extrusion.Id, 6, offset, ArrayAnchorMember.Second);

Hope it helps.


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 7 of 13

Anonymous
Not applicable

Hi Eason, 

 

ok, error message dissapears, but after opening the resulting RFA file in Revit, I try to change manually (using parameters table) the width and height parameters, none of the generated boxes changes their dimensions. Only the reference Lines change their dimensions. Then, I tried to align manually the reference lines to the original box, in edit group mode. The dimensions of array elements have changed but, if I modify again the width and height parameters (using parameter table), I get the message "Constraints are not satisfied". Is it a problem of the order in which I create the elements? could be also how I associate them?

 

My final goal is to develop programmatically a similar RFA file as I sent in the first post message (ArrayFamilywithParameters.rfa): I want the possibility of creating an array of boxes, where using the parameters table, I can modify the number of elements of the array, the offset between elements in the array, and the size (width, height, depth) of the elements.

 

Thanks Eason,

0 Likes
Message 8 of 13

Anonymous
Not applicable

Hi, 

 

could anyone help me with this issue? anyone knows how to create a parametric array with an element that is also parameterized?

0 Likes
Message 9 of 13

FAIR59
Advisor
Advisor

manually I would use labelled dimensions on the profile lines of the Extrusion, but I don't think that can be accomplished through the API. The only option I see, is using a nested family containing the extrusion.

0 Likes
Message 10 of 13

eason.kangEDLV4
Autodesk Support
Autodesk Support

Please accept our sincere apologies for the late response. Due to the Chinese New Year, I'm online for a while.

 

As I know, there is no APIs to open profile sketch like we do with the Revit UI, so it might not be possible to add dimensions to the extrusion's sketch.

 

I'm checking with our Revit experts, and will get you back A.S.A.P.

 

Cheers,


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 11 of 13

Anonymous
Not applicable

Thanks Eason for your reply,

 

I'm looking forward to hearing from you.

 

Cheers,

0 Likes
Message 12 of 13

eason.kangEDLV4
Autodesk Support
Autodesk Support

Hi,

 

Sorry for letting you wait.

 

According to our Revit Experts, Revit doesn't have a Sketch API for doing such things you wanted in the Extrusion Profile now unfortunately. Apologies for any inconvenience caused to you.

 

We already added your request to existing and similar wish list item CF-2030 [Sketch API: No way to create dimension in edit mode of sweep profile using API] on your behalf for the functionality you suggest, as this issue requires exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

At the meantime, I would suggest you to archive this with the nested RFA instead. Besides, you can vote the request from official page below:

https://forums.autodesk.com/t5/revit-ideas/autodesk-answer-day-edit-sketch-in-api/idi-p/6334613

 

Cheers,

 

 

 

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes
Message 13 of 13

kisliplugins
Explorer
Explorer
But you can found Sketch model line via [GetDependedElements], and create dimension for that lines.
0 Likes