Create aligned dimension between rebars

Create aligned dimension between rebars

Anonymous
Not applicable
2,775 Views
4 Replies
Message 1 of 5

Create aligned dimension between rebars

Anonymous
Not applicable

Hi smart guys! 

 

I am trying to create aligned dimensions between rebars but it seems to be not so easy to me.

 

The attached screenshot is what I tried to test dimension creation (just a simple line dim between endpoints of a line)... but it just returns an exception error of "invalid number of references". I have no idea what is wrong with it...

 

2 reference points are inside of the reference array if I check with referenceArray.Size but if I check each item of the array, they are all null...

 

I also checked Revit SDK sample and it shows almost same codes...

 

Does anyone know what is my stupid mistake in the code?

 

Thanks!

🙂

 

 

0 Likes
2,776 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I get this problem too.

 

Everyone else seems to be generating geometry for some reason and apparently you can't get references to geometry that isn't in the model yet but I'm trying to draw a dim from one end of an existing wall to the other and it still says that the references of both ends of the wall are null.

Source:

https://forums.autodesk.com/t5/revit-api/getendpointreference-null-from-analytical-curve/td-p/513200...

https://groups.google.com/forum/#!topic/revitpythonshell/s5AUDkYL3P8

 

 

There's the Geometry Options parameter if I was getting the wall by geometry and, through vector maths and iteration figuring out which GeometryElement I want to base the dim off of but I'm not doing that because all the examples for that method are from 2011 and use outdated API calls so I'm assuming they're outdated as a whole.

Source: 

http://thebuildingcoder.typepad.com/blog/2011/02/dimension-walls-by-iterating-faces.html

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/Revit-API/files/GUID-...

 

 

Instead I'm using HostObjectUtils which seems to be a new addition as of 2012.

var sides = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior);

which can be used to grab specifically the exterior side of a wall which I'm now trying to dim.

Source:

http://adndevblog.typepad.com/aec/2012/07/accessing-the-exterior-face-of-a-wall-programmatically.htm...

 

 

I can separate the face into edge loops and the edge loops into edges which I can then GetEndPointReference(); from. At no point in that workflow is a Geometry Options asked for. GetEndPointReference() returns null.

 

I looked up GetEndPointReference() in the API to find out what causes it to return null and it just says

    "Returns: Reference to the point or null reference (Nothing in Visual Basic) if reference cannot be obtained."

It doesn't say why a reference might not be able to be obtained or what to do if it can't be obtained. What does it mean that a reference cannot be obtained? Is it something to do with the active view? The ReadOnly properties of the Element? The presence of the Element in the project?

 

I can even AsCurve() the edge to a curve and use the variables of a curve to create a new line with Line.CreateBound(); which I can pass into the NewDimension() method without issue. The fact that that works leads me to believe that everything else about the Face object I retrieved is fine. But GetEndPointReference() still returns null.

 

 

The fact that you can create Dims along entire walls in just two clicks (three if you include clicked the button to begin with) by just hitting the "Aligned Dimension" button in the "Annotate" tab just adds insult to injury. Can't we have access to the method running behind that? It must be a method that takes some variant of Element or Reference as its first parameter and then an offset value as its second to position the dim relative to the target. I'm trying to build a car and I don't want to have start by reinventing the wheel just because no one will let me have one.

 

 

Does anyone know what's going on? I'm in Revit 2015.

 

 

Sorry if I'm coming across as rude. I've been trying to find a solution to this problem for three days now and it's wearing me down. I hate that it's so easy in the UI and that none of the examples I've seen actually align with what I'm trying to do. I keep finding "Solutions" and thinking "There has to be a better way."

I just want this: https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2016/EN...

but from the API. I want to be able to press buttons in the Revit UI from the API. You can get references to them. You can change their tool tips and names and display images but you can't press them.

 

 

0 Likes
Message 3 of 5

Anonymous
Not applicable

HA! AHAHA! I did it! It took all week but through trial and error, I did it!

 

So I wanted to dim a wall so I thought "I'll need references to both ends of the wall. I'll just Dim between them. Simple"

 

NOPE!

 

You can't get references to the end points of lines. I guess it's too far down the tree or something. You can, however, get a reference to the face of walls using:

 

HostObjectUtils.GetSideFaces(yourWall, ShellLayerType.Exterior);

 Which will give you a reference to the exterior (or interior, depending on the ShellLayerType parameter) of the wall. You can then dim any parallel walls you find (you have to confirm they're parallel or the NewDimension method will silently fail) by their faces.

 

 

From what I can tell, the reason for this is contained within what References actually are. No one actually explains it so I'm guessing here but:

 

References relate to an Element. They are an ID number that can have an optional suffix attached that refers to a specific part of the Element, separated from the rest of it by a colon ":". If you use document.GetElement(yourReference); you get the element that contains the part, not the part itself, regardless of what is after the colon.

Dimensions need to be linked into an element. The majority of their useful behaviour is tied to the elements they're dimming together. You can't just say "This point in space", regardless of how you compute it because there's no element attached to that point in space so it won't work.

 

So why does GetEndPointReference() return null for lines that you pulled from an Element? My basic understanding is that the line you pulled from the Element is no longer linked to the Element. You can change that line and the Element you pulled it from will stay the same. You need to get your Reference data directly from the Element because otherwise it doesn't have an Element to link to.

 

You can also pull a Reference from the element and manually append a suffix to it if you know what to append. You can turn References into stable strings and then parse them back into References when you're done:

 

yourRefAsString = yourRef.ConvertToStableRepresentation(doc);
yourRef = Reference.ParseFromStableRepresentation(doc, yourRefAsString);

Some trial and error should show you which suffixes mean what. It's probably not great practice but there's very little up to date information out there to help with this so I say do whatever works. Hack it if you have to.

Message 4 of 5

Anonymous
Not applicable

Oh, before I forget, that Line that you put into 

 

NewDimension(doc, line, referenceArray);

that's a direction vector, representing the direction you want to pull your dimension away from the lines you're dimming.

 

Why doesn't the API say that? It just says "The line drawn for the dimension" which is super ambiguous and not particularly useful when you're trying to figure out what to put there.

 

 

You can make it yourself from Line.CreateBound(); with whatever values you want. I'd advise just throwing in the normal of the faces you're dimming. That way it's orientated the right way.

Line.CreateBound(new XYZ(0,0,0), normalOfWalls);

 

 

Again, this is just me after poking things for a week to see what happens. I am not a very good source on these things. I'm just frustrated that there doesn't seem to be any more comprehensive information on any of the normal platforms about this.

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hello JLee,

 

Not sure whether you got the solution for what you were looking for.

The other solutions doesn't work as it is for Walls. We cannot get reference for Rebar and Rebar is not a HostObject.

 

I was also looking for something similar and has posted my solution here. Please have a look.

 

https://forums.autodesk.com/t5/revit-api-forum/create-aligned-dimension-between-rebars/m-p/7083248/h...

 

Also, if you have any better solution let me know.

Thanks

0 Likes