Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linear dimension between reference planes

6 REPLIES 6
Reply
Message 1 of 7
emlplsn
2781 Views, 6 Replies

Linear dimension between reference planes

Hi,

Does anyone know if it's possible to make a linear dimension between two reference planes in revit API? My idea is to set this to a family parameter to make the distance between the planes adjustable in the project file.

 

This simply doesn't seem to work:

 

//CREATE PLANE 1
XYZ freeend1 = new XYZ(1, 10, 0);
XYZ bubbleend1 = new XYZ(1, -10, 0);
XYZ cutvec = new XYZ(0, 0, 1);
ReferencePlane refplane1 = document.FamilyCreate.NewReferencePlane(bubbleend1, freeend1, cutvec, document.ActiveView);

 

//CREATE PLANE 1 - is parallel to plane 1
XYZ freeend2 = new XYZ(5, 10, 0);
XYZ bubbleend2 = new XYZ(5, -10, 0);
//XYZ cutvec = new XYZ(0, 0, 1);
ReferencePlane refplane2 = document.FamilyCreate.NewReferencePlane(bubbleend2, freeend2, cutvec, document.ActiveView);

 

//CREATE DIMENSION LINE - is perpendicular to both refplane1 and refplane2
XYZ dimpt1 = new XYZ(1, 10, 0);
XYZ dimpt2 = new XYZ(5, 10, 0);
Line dimline = document.Application.Create.NewLine(dimpt1, dimpt2, true);

 

// CREATING LINEAR DIMENSION
ReferenceArray ra = new ReferenceArray();
ra.Append(refplane1.Reference);
ra.Append(refplane2.Reference);
Dimension dim = document.FamilyCreate.NewLinearDimension(document.ActiveView, dimline, ra);
FamilyParameter param = document.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false);
dim.Label = param;

 

I get the message "One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument"

 

Any ideas anyone?

Many thanks,

Emil

Tags (1)
6 REPLIES 6
Message 2 of 7
saikat
in reply to: emlplsn

Please call doc.Regenerate() after calling the NewLine().

 

cheers

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 3 of 7
emlplsn
in reply to: saikat

Thanks saikat! It worked perfectly now. Now I have run into another problem,

 

Basically, what I am trying to achieve is to create a parametric box, which I can control the dimensions of by editing the values of the family parameter. This has been my approach:

 

- create 4 reference planes in shaped as a rectangle in the plan view

- make linear dimensions between these for controlling the length and width distances.

- create 4 lines in the reference planes (one in each). these lines form the base rectangle.

- align and lock the lines to their reference planes. (to make them move when I change the distance between the ref planes).

- extrude my base rectangle.

 

The problem with this is that the extrusion command only takes CurveArrArray (consisting of Lines) and the Alignment only takes References. When I try to feed in my Line as dimline.Reference in NewAlignment it doesn't work, because dimline.Reference is a null reference (but dimline itself is not a null reference). Why?

 

Cheers,

Emil

Message 4 of 7
emlplsn
in reply to: emlplsn

Here is the code:

 

public void CreateRectangle2(Document document)
{
//create boundary points
XYZ p0 = new XYZ(10, 10, 0);
XYZ p1 = new XYZ(-10, 10, 0);
XYZ p2 = new XYZ(-10, -10, 0);
XYZ p3 = new XYZ(10, -10, 0);
XYZ cutvec = new XYZ(0, 0, 1);

 

//Create refplanes
ReferencePlane refplanex1 = document.FamilyCreate.NewReferencePlane(p0, p1, cutvec, document.ActiveView);
ReferencePlane refplaney1 = document.FamilyCreate.NewReferencePlane(p1, p2, cutvec, document.ActiveView);
ReferencePlane refplanex2 = document.FamilyCreate.NewReferencePlane(p2, p3, cutvec, document.ActiveView);
ReferencePlane refplaney2 = document.FamilyCreate.NewReferencePlane(p3, p0, cutvec, document.ActiveView);

 

// Lines which defines the base rectangle
Line dimlineboundx1 = document.Application.Create.NewLineBound(p0, p1);
Line dimlineboundy1 = document.Application.Create.NewLineBound(p1, p2);
Line dimlineboundx2 = document.Application.Create.NewLineBound(p2, p3);
Line dimlineboundy2 = document.Application.Create.NewLineBound(p3, p0);
document.Regenerate();

 

// Creating the linear dimension between first pair of lines
ReferenceArray ra1 = new ReferenceArray();
ra1.Append(refplanex1.Reference);
ra1.Append(refplanex2.Reference);
Dimension dim = document.FamilyCreate.NewLinearDimension(document.ActiveView, dimlineboundy1, ra1);
FamilyParameter param = document.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false);
dim.Label = param;

 

// Creating the linear dimension between second pair of lines
ReferenceArray ra2 = new ReferenceArray();
ra2.Append(refplaney1.Reference);
ra2.Append(refplaney2.Reference);
Dimension dim2 = document.FamilyCreate.NewLinearDimension(document.ActiveView, dimlineboundx1, ra2);
FamilyParameter param2 = document.FamilyManager.AddParameter("length", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false);
dim2.Label = param2;

 

// lock the base lines to the reference planes. THIS DOESN'T WORK.
document.FamilyCreate.NewAlignment(document.ActiveView, dimlineboundx1.Reference, refplanex1.Reference);
document.FamilyCreate.NewAlignment(document.ActiveView, dimlineboundx2.Reference, refplanex2.Reference);
document.FamilyCreate.NewAlignment(document.ActiveView, dimlineboundy1.Reference, refplaney1.Reference);
document.FamilyCreate.NewAlignment(document.ActiveView, dimlineboundy2.Reference, refplaney2.Reference);

 

//create Extrusion
XYZ freeend1b = new XYZ(1, 0, 0);
XYZ bubbleend1b = new XYZ(0, 1, 0);
Plane plane1b = document.Application.Create.NewPlane(freeend1b.CrossProduct(bubbleend1b), bubbleend1b);
SketchPlane sketchPlane = document.FamilyCreate.NewSketchPlane(plane1b);
CurveArrArray curveArrArray = new CurveArrArray();
CurveArray curveArray1 = new CurveArray();
Extrusion rectExtrusion = null;

curveArray1.Append(dimlineboundx1);
curveArray1.Append(dimlineboundy1);
curveArray1.Append(dimlineboundx2);
curveArray1.Append(dimlineboundy2);
curveArrArray.Append(curveArray1);

rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 10);
}

 

cheers

Message 5 of 7
saikat
in reply to: emlplsn

Glad to know that the previous suggestion helped.

 

The new requirement seems to be very similar to what we have in the Family API labs. Please refer to the following blogpost to see how a rectangular extrusion is created using the API and then alignments, dimensions added, etc.

 

http://thebuildingcoder.typepad.com/blog/2009/08/the-revit-family-api.html

 

Cheers



Saikat Bhattacharya
Senior Manager - Technology Consulting
Message 6 of 7

I ran into the same problem today. The Line objects that you create for the extrusion have Reference equal to null, so you can't use those lines to lock the extrusion to reference planes with NewAlignment(...)

 

The solution seems to be that you first create the extrusion

 

rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 10);

 

and then you can use rectExtrusion.Sketch.Profile to get the "internal" CurveArrArray object of the extrusion. In this array you will find the lines again, and those you can use in NewAlignment(...)

 

The order of the lines may have changed so it's a bit of a pain to reestablish which lines belong to which reference plane.

 

I hope this helps the next poor sod who attempts to do this 🙂

 

Michael

 

 

 

 

Message 7 of 7
strsuraj
in reply to: emlplsn

Hi,

I am very much new to Revit API and found your code useful for 1 of my task i.e to create dimension between Reference Planes.

I am facing problem-

It says "Document.FamilyManager can only be used in the Revit Family Editor"

So I try not to include this line of code "FamilyParameter param = document.FamilyManager.AddParameter("width", BuiltInParameterGroup.PG_CONSTRAINTS, ParameterType.Length, false);" and run rest of it. It works without any error, creates 2 Reference planes but there's no dimension between them.

 

What is it I am doing wrong ?

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community