PropertySetElement contains structural or thermal?

PropertySetElement contains structural or thermal?

swfaust
Advocate Advocate
2,630 Views
10 Replies
Message 1 of 11

PropertySetElement contains structural or thermal?

swfaust
Advocate
Advocate

I'm working on being able to create material physical and thermal assets.  I have it pretty well working but it's painfully slow because of how I need to check for existing (or at least how I think I do).  Based on what I have found on this link and others there is no way to tell if a property set element contains structural and/or thermal assets except to try and get them and let it throw an exception if it doesn't.  That's terribly inefficient and makes things really slow...  I did create it so that it caches the assets up front and then uses that so that it doesn't have to keep going back during the process which helps a lot, but still slows it down quite a bit.  Here is my code to sort out the assets:

 

 _physicalAssets = new List<StructuralAsset>();
            _thermalAssets = new List<ThermalAsset>();
            foreach (PropertySetElement pse in new FilteredElementCollector(doc).OfClass(typeof(PropertySetElement)))
            {
                try
                {
                    var sa = pse.GetStructuralAsset();
                    if (sa != null) _physicalAssets.Add(sa);
                }
                catch
                {
                }

                try
                {
                    var ta = pse.GetThermalAsset();
                    if (ta != null) _thermalAssets.Add(ta);
                }
                catch
                {
                }
            }

Have there been any updates that I missed that allows us to determine this without the try block?  Is there any better way to do this?  If I create another asset with the same name I assume it will either throw an error or create a duplicate correct?

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

RPTHOMAS108
Mentor
Mentor

List the materials and from the materials list get two further district lists from:

Material.StructuralAssetID

Material.ThermalAssetID

 

Turns lists above into two lists of relevant property sets:

 

PropertySetElement pse = document.GetElement(strucAssetId) as PropertySetElement

and

PropertySetElement pse = document.GetElement(thermAssetId) as PropertySetElement

 

There is an example in the RevitAPI.chm, property sets relate to materials so that is the starting point in my view.

Message 3 of 11

zhong_wu
Autodesk Support
Autodesk Support

I checked the doc and there seems not a way to identify if the PropertySetElement has a StructuralAsset or ThermalAsset. 

I thin what Richard mentioned should be a way to avoid the try/catch block. And also I'd like to know what exactly you want to achieve? If you just want to get/set some value of material, how about using the parameters directly? The code logical should be something like:

 

 

IList<Element> pses = new FilteredElementCollector(doc).OfClass(typeof(PropertySetElement)).ToElements();
foreach (PropertySetElement pse in pses)
{
        // for example to get/set the density parameter directly from the pse
        Parameter pm = pse.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_STRUCTURAL_DENSITY);
        Double test = pm.AsDouble();
        pm.Set( 2.0);
}

 Does this help?

 


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 4 of 11

swfaust
Advocate
Advocate

@RPTHOMAS108 Thanks for the reply.  This is good but I think would miss some items right?  It would cover all the assets used in materials, but what about the ones that aren't used in any material?  I probably could start with this and then look for property set elements that weren't already in a list and only do the try/catch thing on those which would probably cut out a lot of the issue, but still not all of it...

0 Likes
Message 5 of 11

swfaust
Advocate
Advocate

@zhong_wu that could help a lot actually.  I didn't realize those were also accessible via normal parameters...  I assume that if it's a thermal one the structural parameters will just come back null (instead of throwing an exception) and vice versa correct?  It's a little less user friendly to try to find the BIP's, but if that makes it work correctly well worth it.  I guess I could also use this to check if it's structural or thermal (by if the parameter exists or not) and then get the correct asset type from it.  Unless the parameter exists but has a default value...  going to experiment with that a bit and will report back.

 

What I'm trying to achieve is basic management of the assets, so that we can take a material from on location and recreate it on other models/families/etc.  The physical and thermal assets are part of that, and I would like to be able to either assign an existing asset and update it's properties or create a new one but I'm trying to determine how to manage the assets to effectively determine what I need to do (create or update).

0 Likes
Message 6 of 11

zhong_wu
Autodesk Support
Autodesk Support

Yes, there is no exception if the value is not existing, only return "null" as you can see, please give a try and I'd also going to request the improvement to the API to provide the check methods as follow, that will make the whole world easy:

bool PropertySetElement.HasStructuralAsset()

bool PropertySetElement.HasThermalAsset()

 

 


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 7 of 11

zhong_wu
Autodesk Support
Autodesk Support

How does that work? Is the issue solved? I would be very happy if it solves your issue;)


John Wu
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 8 of 11

kinjal
Enthusiast
Enthusiast

Hi @swfaust,

Were you able to find out a way to determine if a given PropertySetElement is "Structural", "Thermal" (or other) type?

 

We need to assign PropertySetElement instances to Materials (.StructuralAssetId, .ThermalAssetId). We want to make sure a Thermal asset is never assigned to Material.StructuralAssetId and vice versa. Couldn't really find a way establish if a given PropertySetElement is good for, say Material.StructuralAssetId.

 

I hope there is a way to tell those apart.

 

Best regards, Kinjal

Kinjal Desai
Fullstack developer @ Dwaravati
Delivering high quality programmatic boosts for your already beautiful Revit


0 Likes
Message 9 of 11

swfaust
Advocate
Advocate

Sorry just saw this.  Not other than the try catch shown above unfortunately.

0 Likes
Message 10 of 11

GaryOrrMBI
Advisor
Advisor

@zhong_wu wrote:

Yes, there is no exception if the value is not existing, only return "null" as you can see, please give a try and I'd also going to request the improvement to the API to provide the check methods as follow, that will make the whole world easy:

bool PropertySetElement.HasStructuralAsset()

bool PropertySetElement.HasThermalAsset()

 

 


I'm giving this old thing a bump.

@zhong_wu has there been any progress on getting something built in to the property set that would allow a quick and simple check? Or, perhaps, simply separate the two entities since you are looking for one or the other at any given time.

 

I have been struggling with this for a while now.

In my tests:

If I call thisAssetElem.GetStructuralAsset it has always returned the asset, even when they are Thermal Assets without an error.

If I call thisAssetElem.GetThermalAsset it will often succeed even on Structural Assets (some will error but not all).

 

I even tried counting the number of parameters that were attached to the PropertySetElement because most cases in my test file were showing that Structural Assets were returning above 40 Parameters while Thermal Assets were returning fewer than 30... That worked until I got into a file with older materials and ran into a structural Asset with only 27 Parameters.

 

There simply is no method of collecting and sorting the PropertySetElements within a document to reuse them (or duplicate them) for new materials with the same properties, and, without being able to search for them independently, you can't be sure that a name is already in use for a given PSE type (IE: a physical (structural) PSE can have the same name as a Thermal PSE so you can't simply check the collection of property set elements to check for a name already in use)

 

This has been out here for a very long time...

A couple of other threads:

https://forums.autodesk.com/t5/revit-api-forum/identify-the-associated-building-structural-elements-... 

 

https://forums.autodesk.com/t5/revit-api-forum/material-assets-collector-appearance-structural-physi... 

 

-G

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 11 of 11

GaryOrrMBI
Advisor
Advisor

Here's a little graphic to help illustrate the issue.

 

I used Snoop to look up a material that has a thermal property set that returns both a structural and a thermal asset.

The material and it's assets were specifically created and named for this purpose.

The material is "Air", the Physical (Structural) Pset is "Air - P", the Thermal Asset is "Air - T"

 

If you use <document>GetElement(<material>.ThermalAssetId) you know that the returned element is the attached Thermal Pset. Because you came at it from a given material you can use this to determine which is which. However, even when you have the PropertySetElement, and know that it is a Thermal Pset, it will still return both a Thermal Asset <Pset>.GetThermalAsset, and a Structural Asset <Pset>.GetThermalAsset.

GaryOrrMBI_0-1687434253447.png

 

GaryOrrMBI_0-1687433078049.png

and this is all when you KNOW that the Pset is a thermal asset.

 

When you are simply collecting PropertySetElements via a filtered element collector to reuse and/or verify their existence and/or to ensure that you don't try to create something with a name that is already in use... well, you're simply out of luck in trying to determine what type of property set you actually have.

 

and here is the same thing from a material that has Thermal and Structural assets that have the same name, which makes trying to ensure that you have a unique name within a given category impossible.

 

GaryOrrMBI_1-1687433928656.png

 

We really need an upgrade to the property sets, probably best case scenario would be to have structural psets and thermal psets as separate element types that do not have any crossover.

 

Well, that two cents turned into a dollar and a half but, there it is.

 

-G

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes