NewFamilyInstance fails on Structural Foundations

NewFamilyInstance fails on Structural Foundations

HD12310
Contributor Contributor
1,109 Views
9 Replies
Message 1 of 10

NewFamilyInstance fails on Structural Foundations

HD12310
Contributor
Contributor

Fourth overload of NewFamilyInstance seems unpredictable on Structural Foundations. (pile caps)

Problem being the Z-value (offset from Level) is not set on the new familyinstance.

And so the copied element doesnt get placed on the correct Z location. (XY gets correct)

This happens only in some Revit project files.

In new projects created from OOTB templates it works fine, but not in our project files.

 

Fourth overload looks like this:

 

public FamilyInstance NewFamilyInstance(XYZ location, FamilySymbol symbol, StructuralType structuralType);

 

 

Anyone had similar issues with this ?

 

 

0 Likes
1,110 Views
9 Replies
Replies (9)
Message 2 of 10

Aaron.Lu
Autodesk
Autodesk

Dear Håvard,

 

Would you please attach your example rvt file and some code snippet? so that we can better reproduce your problem.

 

thanks.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 10

HD12310
Contributor
Contributor

Hi Aaron

 

Tnx for reply.

Could i possibly email the template file directly to you ?

The input box expects meters, eg 10,10,10

 

Code is here:

 

 

try

 

 

{

Selection sel = uiApp.ActiveUIDocument.Selection;

Reference pickedRef = sel.PickObject(ObjectType.Element, "Select Element");

Element elem = doc.GetElement(pickedRef);

FamilyInstance famInst = elem as FamilyInstance;

FamilySymbol fam = famInst.Symbol;

double feet_to_m = 0.30480;

Transaction trans = new Transaction(doc);

trans.Start("Copy to Location");

string[] inpArr = Microsoft.VisualBasic.Interaction.InputBox("Destination XYZ[m]:", "Revit").Split(',');

NumberFormatInfo provider = new NumberFormatInfo();

provider.NumberDecimalSeparator = ".";

 

double x_inp = Convert.ToDouble(inpArr[1], provider);

double y_inp = Convert.ToDouble(inpArr[0], provider);

double z_inp = Convert.ToDouble(inpArr[2], provider);

XYZ xyzLocalImp = new XYZ(x_inp, y_inp, z_inp).Divide(feet_to_m);

FamilyInstance fi= doc.Create.NewFamilyInstance(xyzLocalImp, fam, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

trans.Commit();

}

 

 

catch (Autodesk.Revit.Exceptions.OperationCanceledException)

0 Likes
Message 4 of 10

Aaron.Lu
Autodesk
Autodesk
yes, aaron.lu@autodesk.com

you can try to send by email, but im not sure if the big sized file can be transfered successfully.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 10

Aaron.Lu
Autodesk
Autodesk

Dear Håvard,

 

I think the Z position is incorrect is because the "Structural Foundation" is level based, to meet your need, you have to set the "Offset" of the instance created.

 

below is the code snippet example:

FamilyInstance fi = doc.Create.NewFamilyInstance(xyzLocalImp, fam, Autodesk.Revit.DB.Structure.StructuralType.Footing);
Parameter pp = fi.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM);
if (pp != null)
{
    pp.Set(30);
}

 Hope it helps.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 6 of 10

ola.gunnar.skippervik
Explorer
Explorer

Hello

I think that might be an ok work around (and is quite easy to implement in the code), but it does not answer why this overload works fine with the same Structural Foundations family in some *.rvt file as it does not in other *.rvt files.

 

Best regards

Ola Gunnar

0 Likes
Message 7 of 10

Aaron.Lu
Autodesk
Autodesk

Thanks for mentioning it, dose anyone have an example rvt file containing the different situations? if yes, would you send it to me so I can do a research.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 8 of 10

Anonymous
Not applicable

Well its your call Ole Gunnar as it's your code here 😉

 

You would have to set the Level for the family as well and/or determine its relative location if not 0.

(After setting or detecting which category the user wants to insert)

 

I agree with you it doesnt explain why the behaviour is not consistent across different projects.

 

Aaron: this works in the ootb templates included with Revit.

"Default Metric.rtf" should do it.

 

 

0 Likes
Message 9 of 10

Aaron.Lu
Autodesk
Autodesk

I got comment from development team Arnošt, he said

"It is not something that can be easily explained or reasoned with. In this case (of the footing sometimes works but not all the time) we can only sat "it depends". That i because Revit always tries to manage the model even if it means that sometimes it must guess absent data. Naturally, this guessing works sometimes, if the user's lucky enough, but it cannot work all the time, understandingly"

"It is a very old, hand-written API"

 

He also suggest using a newer API method which takes a Level as argument, it is safer and more stable:

    FamilyInstance NewFamilyInstance(XYZ location, FamilySymbol symbol, Level level, StructuralType structuralType)



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 10 of 10

HD12310
Contributor
Contributor

Hi

 

Thanks for investigating this Aaron.

Truly interresting issue.

 

My tip to codeauthor Ole Gunnar is to determine the Level based on the XYZ point.

A "GetLevelFromPoint(XYZ)" subfunction should be able to handle the extra Level argument.

 

0 Likes