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: 

NewDimension between Grids - Invalid Number of references

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
maisoui
3720 Views, 6 Replies

NewDimension between Grids - Invalid Number of references

Hi,

 

I tried to create a Dimension between two Grids and I always get the same error : Invalid number of references.

 

public static Dimension createGridDimension(View view, Grid grid1, Grid grid2)
{
	Curve curve1 = grid1.Curve;
	Curve curve2 = grid2.Curve;
	if(curve1 == null || curve1.Reference == null || curve2 == null || curve2.Reference == null)
	{
		return null;
	}

	Line line = Line.CreateBound(curve1.GetEndPoint(0), curve2.GetEndPoint(0));

	ReferenceArray references = new ReferenceArray();
	references.Append(curve1.Reference);
	references.Append(curve2.Reference);

	return view.Document.Create.NewDimension(view, line, references);
}

I found this post on the forum, which seems to be a similar issue, but it dates from 2016. I use Revit API 2018 and I hope it has been fixed now.

Best regards,

Jonathan

 

--
Jonathan
6 REPLIES 6
Message 2 of 7
maisoui
in reply to: maisoui

revit_invalid_references.png

--
Jonathan
Message 3 of 7
RPTHOMAS108
in reply to: maisoui

This behaviour is still the same in 2018 but I showed a solution for it yesterday

 

https://forums.autodesk.com/t5/revit-api-forum/fail-to-get-reference-for-grid-for-dimension-in-2017/...

 

Basically you can't use the reference from the curve of the grid (since that is a surface), you have to create a new reference by using the grid element itself: New Reference(Grid). This reference you can then add to the reference array of the Create.NewDimension method. It's the same when dimensioning reference planes.

 

If you only have the curve information to start with (not as your case) then you need to get the grid element from the curve's reference and then create a new reference from that.

 

Create.NewDimension method expects the reference type of a grid or reference plane to be REFERENCE_TYPE_NONE (for element) not REFERENCE_TYPE_SURFACE.

Message 4 of 7
maisoui
in reply to: maisoui

Many thanks RPTHOMAS108. I lost severy hours yesterday trying to find a solution.

 

Please Autodesk dev team, update your samples and when you say "it will be available in a next major release" and two years (and major versions) it still the same, this is not very serious and professional.

 

Best regards

--
Jonathan
Message 5 of 7
frank.hochban
in reply to: maisoui

I have lost several hours today,  about 8 trying to filter through all the out of date posts.

I am happy that I have found this one that gives an answer, but unfortunately links back to a post where it doesnt actually show the final solution.

 

In my application, written in IronPython and using pyRevit.  I am building a simple control that allows grids to be generated and now adds the grid dimensions between them.

 

While I create the grids I store them in a python list.  I pass a 'StartGrid' to give it the first 1 or A and after that let the auto numbering take over.

 

Xgrids = []
Ygrids = []

def DrawGrid(document, PointFrom, PointTo, StartGrid ):
	# create model line
	l = DB.Line.CreateBound(PointFrom, PointTo)
	t.Start()
	G = DB.Grid.Create(document,l)
	G.ShowBubbleInView(DB.DatumEnds.End0, document.ActiveView)
	if StartGrid == 1:
		G.Name = str(StartGrid)
		Xgrids.append(G)
	elif StartGrid == 'A':
		G.Name = StartGrid
		Ygrids.append(G)
	elif StartGrid == 'auto':
		if G.Name.isdigit():
			Xgrids.append(G)
		elif not G.Name.isdigit():
			Ygrids.append(G)
	
	t.Commit()

Currently I then loop through the lists and create the grid dimensions.  At the start, I also get a filter of the document views so that I can apply the dimensions to all the plan views at the same time.  

 

I also have collected the start and end of the grid so that I can place the dimensions at each end of the grid.

 

def DimensionGrids(document):

	FEC = DB.FilteredElementCollector(document)
	RA = DB.ReferenceArray()
	dd = FEC.OfClass(DB.ViewPlan)

	dimLocPt0 = []
	dimLocPt1 = []
	
	t.Start()
	for p in dd:
		if not p.IsTemplate:
			for g in Xgrids:
				RA.Append(DB.Reference(g))
				if dimLocPt0.Count < 2:
					if dimLocPt0.Count == 0:
						dimLocPt0.append(g.Curve.GetEndPoint(0))
					else:
						g.Curve.MakeUnbound()
						dimLocPt0.append(g.Curve.Project(dimLocPt0[0]).XYZPoint)
				if dimLocPt1.Count < 2:
					if dimLocPt1.Count == 0:
						dimLocPt1.append(g.Curve.GetEndPoint(1))
					else:
						g.Curve.MakeUnbound()
						dimLocPt1.append(g.Curve.Project(dimLocPt1[0]).XYZPoint)
			# p is a plan view
			Line0 = DB.Line.CreateBound(dimLocPt0[0],dimLocPt0[1])
			Line1 = DB.Line.CreateBound(dimLocPt1[0],dimLocPt1[1])
			
			document.Create.NewDimension(p, Line0, RA)
			document.Create.NewDimension(p, Line1, RA)
			
	t.Commit()	

I hope that this helps someone else not lose a days worth of time.

 

 

Message 6 of 7

While the code needs refactoring I figured I would add that it only shows for the Xgrids horizontal.  I just copied and pasted the same for loop and modified to include for the Ygrids.  The only additional change was to clear the lists, and the ReferenceArray.Clear.  I highlighted in red to show only changes for Ygrids.  

 

Cheers

 

# now do the Y grids
			dimLocPt0 = []
			dimLocPt1 = []
			RA.Clear()
			for g in Ygrids:
				RA.Append(DB.Reference(g))
				if dimLocPt0.Count < 2:
					if dimLocPt0.Count == 0:
						dimLocPt0.append(g.Curve.GetEndPoint(0))
					else:
						g.Curve.MakeUnbound()
						dimLocPt0.append(g.Curve.Project(dimLocPt0[0]).XYZPoint)
				if dimLocPt1.Count < 2:
					if dimLocPt1.Count == 0:
						dimLocPt1.append(g.Curve.GetEndPoint(1))
					else:
						g.Curve.MakeUnbound()
						dimLocPt1.append(g.Curve.Project(dimLocPt1[0]).XYZPoint)
			# p is a plan view
			Line0 = DB.Line.CreateBound(dimLocPt0[0],dimLocPt0[1])
			Line1 = DB.Line.CreateBound(dimLocPt1[0],dimLocPt1[1])
			
			document.Create.NewDimension(p, Line0, RA)
			document.Create.NewDimension(p, Line1, RA)
Message 7 of 7
ly1057620257
in reply to: RPTHOMAS108

thanks!!! i spent lot of time to fix it

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