It is a project that will be developed in unity where a model will be taken from Revit that is in fbx format.
While creating a the model in revit, before exporting the model, some additional information are added. In the model, there are multiple parts and for each part, manually an id is assigned.
For example, there is a house model, in which every part like each walls, each windows, each door has been assigned an ID. Like, Wall_1, Wall_2, Wall_3, Window_1, Window_2, Window_3, Door_1, Door_2, Door_3, etc.
I have tried to use obj format too but the result was same.
So, is there a way in which I can the import the property data too?
Currently using:
Unity Editor - 2022.3.9f1
OS: iOS
You should be able to read custom properties from FBX files using the ModelImporter AssetPostprocessors, specifically this one: Unity - Scripting API: AssetPostprocessor.OnPostprocessGameObjectWithUserProperties(GameObject,string[],object[])
It should be called for each GameObject created that has a custom property on the corresponding FBX object. You can look for your property value and do something out of it while the import is processed.
For example, you could add a MonoBehaviour on the GameObject that would contain a string with your property value.
Let me know if that is not enough and if you are looking for something more specific.
Yes, I have seen this site and checked some videos regarding this but mostly all the software they are referring is 3dmax or Maya, so it is possible for Revit too?
And when I import the Fbx file, apart from mesh, nothing else is getting imported in the unity.
As long as it is exported in the FBX format it should work the same regardless of the software used to generate the file.
If Revit is using custom properties in FBX files to save the extra data you want to import, then it should be accessible from the method I linked in my previous post.
If the method is not being called during the import, then that’s because the data is not in custom properties, but I’m not sure how Revit would save them in the FBX file otherwise.
public void OnPostprocessGameObjectWithUserProperties(GameObject incomingGameObject, string[] incomingPropetyNames, object[] incomingValues)
{
var thisModelImporter = this.assetImporter as ModelImporter;
var meta_key = "your_attribute_name";
if (incomingPropetyNames.Contains(meta_key))
{
string raw_data = (string)incomingValues[Array.IndexOf(incomingPropetyNames, meta_key)];
// use the data here....
}
}
Last confirmation, I have to write this script file, save it in the Editor Folder and when I import the fbx model, this script will run automatically without being in playmode. Am I right?
public void OnPostprocessGameObjectWithUserProperties(GameObject go, string[] propNames, System.Object[] values)
{
Debug.Log(go.name);
for (int i = 0; i < propNames.Length; i++)
{
string propName = propNames[i];
System.Object value = (System.Object)values[i];
Debug.Log("Propname: " + propName + " value: " + values[i]);
if (value.GetType().ToString() == "System.Int32")
{
int myInt = (int)value;
Debug.Log(myInt);
}
}
And when I import the fbx file, I can see the method being mentioned in the inspector under Model, but I am not getting output as this method is not being called.
I have used other methods to check like OnPostprocessModel, OnPreprocessModel and others to check if the file is being running or not, but it worked well so, OnPostprocessGameObjectWithUserProperties method is not running.
You’re doing it right, if this method is not being called, this is because the imported model doesn’t have any custom properties.
I don’t how Revit exports its data to FBX, are you using a custom script for it, or only the default one from Revit?
If you’re using Revit’s default exporter, then I’d suggest trying to make sure this information is actually being saved somewhere in the FBX file. If it is not, then there is no way to import that in Unity unless you use a custom export script to add this data yourself.
Well, when I export the file from Revit and again import it to another system Revit, it shows the custom data. Is there any site or system where I can check if any data is passed or not?