NewDimension ReferenceArray

NewDimension ReferenceArray

yuvdal
Enthusiast Enthusiast
2,480 Views
3 Replies
Message 1 of 4

NewDimension ReferenceArray

yuvdal
Enthusiast
Enthusiast

Hello,

 

I'm using ReferenceArray Class for dimensioning wall with the NewDimension Method.

For the ReferenceArray I want to add only the Start and the End off the wall without the openings.

Please see the relevant part of the code below.

How can I filter only the Start and the End references of the wall? 

2020-06-30_10-40-36.png

 

def isParallel(v1,v2):
	return v1.CrossProduct(v2).IsAlmostEqualTo(XYZ(0,0,0))

with rpw.db.Transaction("Wall"):
    logger.debug([reference for reference in reference_array])
    for wall in wall_selection:
        param = wall.LookupParameter('Wall Type').AsString()
        if param:
            refArray = ReferenceArray()
            line = LineElement(wall)
            lineDir = line.GetEndPoint(1) - line.GetEndPoint(0)
            geoElement = wall.get_Geometry(options)
            #get side references
            for obj in geoElement:
                if isinstance(obj,Solid):
                    for f in obj.Faces:
                        try:
                            faceNormal = f.FaceNormal
                            if isParallel(faceNormal,lineDir):
                                refArray.Append(f.Reference)
                        except Exception, ex:
                            continue
            try:
                if dimtype:
                    dim = doc.Create.NewDimension(doc.ActiveView, line, refArray, dimtype)
                else:
                    dim = doc.Create.NewDimension(doc.ActiveView, line, refArray)
                dim.ValueOverride = param;
            except Exception, ex:
                continue

 

Thanks,

Yuval

0 Likes
Accepted solutions (1)
2,481 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @yuvdal ,

I created a simple code to draw a wall dimension.

In the ReferenceArray, you have to give the endpoints of the wall as references.

The line l1 represents the dimension line, not the wall line.

Wall w;
LocationCurve LC = w.Location as LocationCurve;              
Line l1;
DetailCurve dcurve = doc.Create.NewDetailCurve(doc.ActiveView, LC.Curve);

ReferenceArray RA = new ReferenceArray();         
RA.Append(dcurve.GeometryCurve.GetEndPointReference(0));
RA.Append(dcurve.GeometryCurve.GetEndPointReference(1));

doc.Create.NewDimension(doc.ActiveView,l1,RA);

You can create Line l1 using 

 Line l1=Line.CreateBound(startPt,endPt);

here startPt and endPt represent the start point and endpoint of the dimension line but not the start point and endpoint of the wall location line.

 

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

yuvdal
Enthusiast
Enthusiast

Thank you but I want the wall faces to be the references and not the Detail Curve that you have created.

2020-06-30_16-22-06.png

0 Likes
Message 4 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @yuvdal ,

I tried using your code.

It works as expected.(i.e)I am able to create a dimension between two endpoints of the wall.

Maybe the problem lies with this line of code

line = LineElement(wall)

Could you tell me what this part of the code does?

 

Here is the code  in c# I used to create a dimension by referencing faces

 Wall w;

                LocationCurve LC = w.Location as LocationCurve;
                XYZ Normal = findNormal(LC.Curve);
                XYZ lineDir = LC.Curve.GetEndPoint(1) - LC.Curve.GetEndPoint(0);

                Options op = app.Create.NewGeometryOptions();
                op.ComputeReferences = true;
                op.IncludeNonVisibleObjects = true;

                ReferenceArray RA = new ReferenceArray();

                GeometryElement GE = w.get_Geometry(op) as GeometryElement;
                foreach(GeometryObject GO in GE)
                {
                    Solid solid = GO as Solid;
                    FaceArray FA = solid.Faces;
                    foreach(Face f in FA)
                    {
                        PlanarFace pf = f as PlanarFace;
                        if(pf!=null && isParallel(lineDir,pf.FaceNormal))
                        {
                            RA.Append(pf.Reference);
                        }
                    }
                }

                Line l1 = Line.CreateBound(LC.Curve.GetEndPoint(0), LC.Curve.GetEndPoint(1));
                doc.Create.NewDimension(doc.ActiveView,l1, RA);
private bool isParallel(XYZ lineDir, XYZ faceNormal)
        {
            return faceNormal.CrossProduct(lineDir).IsAlmostEqualTo(new XYZ(0, 0, 0));
        }   
        private XYZ findNormal(Curve curve)
        {
            XYZ p = curve.GetEndPoint(0);
            XYZ q = curve.GetEndPoint(1);
            XYZ v = q - p;

            return v.CrossProduct(XYZ.BasisZ).Normalize();
        }

 

Here the line l1 represents the start point and endpoint of the dimension line. 

My code will draw a dimension on the wall.

For the Horizontal wall, If you want the dimension above the wall, then you have to change the value of the (l1) dimension line's start and end point's Y value.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network