FabricationPart SetDimensionValue inconsistency

FabricationPart SetDimensionValue inconsistency

steven.williams.as
Advocate Advocate
1,114 Views
10 Replies
Message 1 of 11

FabricationPart SetDimensionValue inconsistency

steven.williams.as
Advocate
Advocate

I am trying to change a FabricationPart straight Length dimension from Auto to Value. Here is approximately what I do:

 

// part is my FabricationPart with Length dimension set to Auto
FabricationDimensionDefinition lengthDefinition = part.GetDimensions().Cast<FabricationDimensionDefinition>().SingleOrDefault(i => i.Name == "Length");
double partLength = part.GetDimensionValue(lengthDefinition);
part.SetDimensionValue(lengthDefinition, partLength); // does not set Length to Value

 

I think this must be a bug, because if I change the part length value by even a small amount, it works.

 

part.SetDimensionValue(lengthDefinition, partLength - 0.01); // sets Length to Value

 

Can someone confirm this is a bug? How do I get around this so I can set the part length to its exact length, but fixed instead of Auto?

0 Likes
1,115 Views
10 Replies
Replies (10)
Message 2 of 11

steven.williams.as
Advocate
Advocate

To partially answer my own question, it does seem to work if I set the part length twice:

 

part.SetDimensionValue(lengthDefinition, partLength - 0.01);
part.SetDimensionValue(lengthDefinition, partLength);

 

I do not feel like that is a good enough answer though.

0 Likes
Message 3 of 11

jeremy_tammik
Alumni
Alumni

Would you like to provide a minimal reproducible case?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

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

steven.williams.as
Advocate
Advocate

Sorry, I thought the code I posted was enough. Here's a more complete example, and attached MWE document with it as a macro. Note I hard-coded the element ID, in case you paste the code into your own document.

 

 

public void MakeValue()
{
	ElementId id = new ElementId(281094);
	Element element = Document.GetElement(id);
	FabricationPart part = element as FabricationPart;
	FabricationDimensionDefinition lengthDefinition = part.GetDimensions().Cast<FabricationDimensionDefinition>().SingleOrDefault(i => i.Name == "Length");
	double partLength = part.GetDimensionValue(lengthDefinition);
	using (Transaction transaction = new Transaction(Document))
	{
		transaction.Start("Set Length");
		part.SetDimensionValue(lengthDefinition, partLength); // does not set Length to Value
		transaction.Commit();
	}
}

public void MakeValueWorks()
{
	ElementId id = new ElementId(281094);
	Element element = Document.GetElement(id);
	FabricationPart part = element as FabricationPart;
	FabricationDimensionDefinition lengthDefinition = part.GetDimensions().Cast<FabricationDimensionDefinition>().SingleOrDefault(i => i.Name == "Length");
	double partLength = part.GetDimensionValue(lengthDefinition);
	using (Transaction transaction = new Transaction(Document))
	{
		transaction.Start("Set Length");
		part.SetDimensionValue(lengthDefinition, partLength+0.01);
		part.SetDimensionValue(lengthDefinition, partLength); // does set Length to Value
		transaction.Commit();
	}
}

 

  

0 Likes
Message 5 of 11

jeremy_tammik
Alumni
Alumni

Thank you for the sample model with macro. That looks better. Yes; without a model, a specific problematic element, the macro, and detailed steps to execute, how is the development team or anyone else supposed to be able observe and analyse the problem?

  

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

snajjar
Contributor
Contributor

Every straight FabricationPart has a default length set in the database, you can tell if the part is at it's default length by examining the "Length Option" parameter.

snajjar_0-1644633954488.png

 

This parameter is of type string but can have only 2 values "Auto" & "Value"

If it is set to Auto, then the part is at it's default length in the database, but if you change the part's length (by dragging one end for example) the parameter switches to "Value" and the "Length" parameter get's unlocked.

I think what is happening in your case, is that you are setting the length to the default length and the part is smart enough not to change it's "Length Option" parameter state. When you try again by changing the length slightly, the "Length Option" parameter is switching to "Value" and unlocking the Length parameter.

If the intent is just to change the parameter state from "Auto" to "Value", you do so by simply setting the parameter value:

 

 

 

public void MakeValueWorksToo()
		{
			ElementId id = new ElementId(281094);
			Element element = Document.GetElement(id);
			FabricationPart part = element as FabricationPart;
			
			var parameter = part.LookupParameter("Length Option");
			
			
			using (Transaction transaction = new Transaction(Document))
			{
				transaction.Start("Set Length");
				parameter.Set("Value");
				transaction.Commit();
			}
		}

 

 

 



0 Likes
Message 7 of 11

jeremy_tammik
Alumni
Alumni

Thank you very much for the explanation! I suppose this required approach is obvious once you have gathered some experience with the user interface for manipulating these objects? If so, it just goes to show once again how hard you can make life for yourself trying to force the square peg through the round hole...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 11

snajjar
Contributor
Contributor

The Autocad CADMEP Fabrication database is a bit of a vague monster, it takes a lot of hair pulling to get to conclusions like this 🙂

0 Likes
Message 9 of 11

steven.williams.as
Advocate
Advocate

Weird thing about the Auto / Value issue is that Revit will allow you to have a part that is not the standard length as Auto, as long as it is close. One can also use the Edit Part tool in Modify | MEP Fabrication Ductwork to change Auto to Value, though that does not always work. I posted a question about this on the MEP forum but nobody helped before it got lost in all the other questions. In short, you can change a straight length from Auto to Value and the length displayed will stick, unless it is attached to certain other services, such as a transition. See the link above for more detail.

 

Here's an example of Revit allowing multiple lengths while still calling the length Auto:

 

2022-02-14 09.21.08 Revit_ICcpQXasVp.png2022-02-14 09.20.23 Revit_7BP2GRebL7.png

2022-02-14 09.21.02 Revit_fJxzrtFHFu.png2022-02-14 09.20.47 Revit_xIJSayw6q6.png

 

Regarding setting the Length Option, I am unable to make that work when I use

part.get_Parameter(BuiltInParameter.FABRICATION_PART_LENGTH_OPTION).Set("Value");

which I thought would be the more portable way.

0 Likes
Message 10 of 11

snajjar
Contributor
Contributor

Keep in mind that when the straight is bound (connected) from both ends, both the "Length" and the "Length Option" parameters become locked and what you set the "Length Type" to is totally irrelevant, as the length of the straight is being determined by the bounding elements. Somehow the "Length Option" parameter is being set loose in the Part Edit dialog (I think this is a bug) , but changing it there will have no effect what so ever on the length behavior, and it will still be determined by the bounding elements.

Here is what I get when I try to change the Length Option parameter on a straight that is connected on both ends

snajjar_0-1645257253941.png

 

0 Likes
Message 11 of 11

steven.williams.as
Advocate
Advocate

I think that the Length Option parameter is not irrelevant, or at least it does not give me the error you show in your screenshot. Here's an example:

Duct Length Option.gif

 

I don't know what good it does to have the length option set one way or another, but one of my colleagues recently had a reason for wanting things to all be Value, or as many as possible to be Auto.

0 Likes