How to retrieve a Dimension's (segment) geometry ?

How to retrieve a Dimension's (segment) geometry ?

maisoui
Advocate Advocate
6,613 Views
29 Replies
Message 1 of 30

How to retrieve a Dimension's (segment) geometry ?

maisoui
Advocate
Advocate

Hello,

 

I'd like to retrieve the geometry of a Dimension : for each Dimension's segment, I'd like to have start, end points and text position and direction. I'm able to obtain the text position and the text string by looping on segments array :

 

foreach(DimensionSegment segment in dimension.Segments)
{
   //segment.TextPosition
   //segment.ValueString
}

But, I don't understand how to obtain the segment's points and direction. I tried get_geometry and looping on references array, but no success.

 

foreach(Reference reference in dimension.References)
{
    reference.GlobalPoint; // ---> always null
}

I don't find any samples.

Any suggestion is welcomed.

Best regards,

--
Jonathan
Accepted solutions (2)
6,614 Views
29 Replies
Replies (29)
Message 21 of 30

jeremytammik
Autodesk
Autodesk

Not quite... with the current code, plus an additional method DrawMarker to add model lines marking the 'start point and the three 'further points', I currently get the following result:

 

Screen Shot 2017-06-15 at 14.32.27.png

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 22 of 30

FAIR59
Advisor
Advisor
as you can see, is the first Mark positioned on the MidPoint of the first segment.
We still have to adjust the GetDimensionStartPoint() method:


XYZ p = null; double length=0; XYZ direction =(dim.Curve as Line).Direction.Normalize(); try { p = dim.Origin; length = dim.Value; } catch( Autodesk.Revit.Exceptions.ApplicationException ex ) { Debug.Assert( ex.Message.Equals( "Cannot access this method if this dimension has more than one segment." ) ); foreach( DimensionSegment seg in dim.Segments ) { p = seg.Origin; length = seg.Value; break; } } return p.Subtract(direction.Multiply(length/2));
0 Likes
Message 23 of 30

jeremytammik
Autodesk
Autodesk

Yes indeed. It works now:

 

dim_three_walls_markers_correct.png



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 24 of 30

jeremytammik
Autodesk
Autodesk

I summarised the results on The Building Coder for future reference:

 

http://thebuildingcoder.typepad.com/blog/2017/06/determining-dimension-segment-endoints.html

 

Thank you very much, Fair59, for all your advice and support!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 25 of 30

maisoui
Advocate
Advocate

Sorry for the delay. Here's my final code:

 

private List<DimensionInfo> dumpDimension(Dimension dimension)
{
	Curve curve = dimension.Curve;
	Line line = curve as Line;
	XYZ point1 = null;
	XYZ point2 = null;
	XYZ direction = null;

	IntersectionResult projection = null;
	XYZ ortho = null;

	BcGeCurve geCurve = null;
	if(line != null)
	{
		if(line.IsBound)
		{
			point1 = line.GetEndPoint(0);
			direction = line.Direction;
			geCurve = createLine(point1, direction, false, Transform.Identity);
		}
		else
		{
			point1 = line.Origin;
			direction = line.Direction;
			geCurve = createLine(point1, direction, true, Transform.Identity);
		}
	}
	else
	{
		geCurve = createCurve(curve.Tessellate(), Transform.Identity);
	}

	//dump dimension (segments) info
	List<DimensionInfo> dimensionInfos = new List<DimensionInfo>();
	if(dimension.Segments.Size == 0)
	{
		projection = line.Project(dimension.LeaderEndPosition);
		ortho = dimension.LeaderEndPosition.Subtract(projection.XYZPoint);
		//TODO: find the correct leader point

		point1 = dimension.Origin.Subtract(direction.Multiply((double)dimension.Value / 2.0));
		point2 = point1.Add(direction.Multiply((double)dimension.Value));
		DimensionInfo dimensionInfo = new DimensionInfo(point1.Add(ortho), point2.Add(ortho), point1, dimension.TextPosition, dimension.ValueString)
		dimensionInfos.Add(dimensionInfo);
	}
	else
	{
		foreach(DimensionSegment segment in dimension.Segments)
		{
			projection = line.Project(segment.LeaderEndPosition);
			ortho = segment.LeaderEndPosition.Subtract(projection.XYZPoint);
			//TODO: find the correct leader point

			point1 = segment.Origin.Subtract(direction.Multiply((double)segment.Value / 2.0));
			point2 = point1.Add(direction.Multiply((double)segment.Value));
			DimensionInfo dimensionInfo = new DimensionInfo(point1.Add(ortho), point2.Add(ortho), point1, segment.TextPosition, segment.ValueString)
		dimensionInfos.Add(dimensionInfo);
		}
	}

	return dimensionInfos;
}

The "xlinePoint1" and "xlinePoint2" is not correct yet.

I'm looking forward for a solution.

--
Jonathan
0 Likes
Message 26 of 30

Anonymous
Not applicable

Hi @jeremytammik ,

 

I'm facing the same issue as this thread's title. I'm getting an unbound line from my dimension and can't get the curve from it, do you know if the engineering team has already got a solution for this?

 

I tried the solution mentioned in this topic, but it is not completely clear to me as there are some variable definitions that are not given in the context.

 

Any tip of advice will be very well received.

 

Regards!

0 Likes
Message 27 of 30

mehdi.blanchard
Enthusiast
Enthusiast

The Origin being the middle of the dimension I had to actually substract half the length to get the correct first point Pt1:

pt1 = pt1.Add(-direction.Multiply((double)dim.Value/2));

 

0 Likes
Message 28 of 30

mehdi.blanchard
Enthusiast
Enthusiast

The Origin being the middle of the dimension, I had to substract half the length to get the correct start point Pt1:

pt1 = pt1.Add(-direction.Multiply((double)dim.Value/2));

 

0 Likes
Message 29 of 30

Simon.Pusateri
Contributor
Contributor

Cheers from 5 years later! dim.curve still gives an unbound curve, but this thread has been a bit of a lifesaver!

0 Likes
Message 30 of 30

jeremy_tammik
Alumni
Alumni

Glad to hear you found it useful. 🙂

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes