Parameter.SetValueString and Parameter.Set cannot be used to change a height and width parameter value to 4 or 2

DKollarJ8NUG
Participant
Participant

Parameter.SetValueString and Parameter.Set cannot be used to change a height and width parameter value to 4 or 2

DKollarJ8NUG
Participant
Participant

Hello everyone,

I have a problem that I can't seem to find a solution for. I am working with several Revit 2025 documents that have been split up by discipline. I have a mechanical model linked into a structural model. The mechanical model has face-based louvers that are hosted on the structural model's walls. In the structural model, we have to place another face-based family that cuts the opening for the louvers. I would like to automate the placing of the wall opening families.

 

My current code will prompt the user to select the louver from the linked mechanical model and then the face of the wall that will host the wall opening. Using parameters from the louver family I create a custom JHWallOpening object with all the parameters I need (and probably some I don't lol). I then pass the properties from the JHWallOpening to create a new instance of the wall opening family. I then try to adjust the height and width.

 

I currently have some half working code. I say half working because for some louver sizes it works, and for others it does not. I am pulling the height and width instance parameters from the louver and using that to set the height and width of the wall opening's instance parameters. It works for most of the sizes. However, it doesn't seem to work for 4'-0" or 2'-0" (and possibly others, I'm not sure). Whenever I pass these values through the two methods mentioned in the post's title, the wall opening doesn't set the parameters at all and keeps the default height and width.

 

I've tried passing in string, int (4 or 2), and double (4.0 or 2.0) hardcoded values and it doesn't work. I have tried passing in the value from Parameter.AsValueString with no luck. My code is below.

 

public static void JHWallOpening(Document doc, JHWallOpening wallOpening, Reference faceReference)
{
    FamilySymbol opening = GetFamilySymbol(doc, "JH-WALL OPENING-RECTANULAR_R23", "Square");
    Wall hostWall = doc.GetElement(faceReference) as Wall;
    Face face = hostWall.GetGeometryObjectFromReference(faceReference) as Face;
    BoundingBoxUV boundingBoxUV = face.GetBoundingBox();
    UV center = (boundingBoxUV.Max + boundingBoxUV.Min) / 2;
    XYZ normal = face.ComputeNormal(center);
    XYZ origin = new XYZ(wallOpening.OriginX, wallOpening.OriginY, wallOpening.OriginZ);
    XYZ direction = normal.CrossProduct(XYZ.BasisZ);
    FamilyInstance instance = doc.Create.NewFamilyInstance(faceReference, origin, direction, opening);
    Parameter height = instance.LookupParameter("Height");
    Parameter width = instance.LookupParameter("Width");
    Parameter thickness = instance.LookupParameter("Thickness");
    height.SetValueString(wallOpening.Height);
    width.SetValueString(wallOpening.Width);
    thickness.SetValueString(wallOpening.Thickness);
}

 

public JHWallOpening(FamilyInstance family)
{
    double Height = family.LookupParameter("Height").AsDouble();

    LocationPoint? location = family.Location as LocationPoint;
    this.OriginX = location.Point.X;
    this.OriginY = location.Point.Y;
    this.OriginZ = location.Point.Z - (Height / 2);
    this.HostElementId = family.Host.UniqueId;
    this.Height = family.LookupParameter("Height").AsValueString();
    this.Width = family.LookupParameter("Width").AsValueString();
    this.Thickness = family.LookupParameter("Wall Thickness").AsValueString();
    this.DirectionX = family.FacingOrientation.X;
    this.DirectionY = family.FacingOrientation.Y;
    this.DirectionZ = family.FacingOrientation.Z;
    this.LinkedElementId = Convert.ToInt32(family.HostFace.LinkedElementId.Value);
    this.HostingFaceId = Convert.ToInt32(family.HostFace.ElementId.Value);
}

 

DKollarJ8NUG_0-1734985914526.png

 

 

I'm at my wits end with this. Anyone have any ideas?

 

Thanks

0 Likes
Reply
Accepted solutions (1)
220 Views
5 Replies
Replies (5)

Sleepingfish_Kuo
Enthusiast
Enthusiast

Did you get any warning when setting these values?

What will happen when you set 4' and 2' for the open manually?

 

By the way, Revit default use Opening Cut (Create->Open),to create open for door and windows. So that you don't need to edit thinkness value when it put on different walls.

0 Likes

DKollarJ8NUG
Participant
Participant

The opening family works fine when manually changing the parameters. I've thought about using openings, but our company has been using the family for so long that I don't want to start changing things.

DKollarJ8NUG
Participant
Participant

I've found a workaround for this problem. However, I'm not really happy with the "solution" because it leaves the opportunity for this to happen with other dimensions that have the same problem. I just subtracted 0.0001 feet from the height or width and Revit will place the opening correctly. This uses hardcoded values for the dimensions I know will throw off Revit so it's not a good solution, but it's what I have so far.

0 Likes

jeremy_tammik
Autodesk
Autodesk
Accepted solution

I would always avoid trying to set a numerical value using SetValueString. After all, the value is a number, so why pass in a string? It requires unnecessary overhead and possibly confusion. I don't see any code samples using Set. What happens when you try that? I would always use that for numerical parameters.

   

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

DKollarJ8NUG
Participant
Participant

Ok, so this worked, but I feel like I need to explain what I think went wrong. I was pulling the height and width as a string and then trying to convert that to a double. As soon as I pulled the value as a double, and not a string, then used Parameter.Set with the double it worked as expected. Thanks, @jeremy_tammik