Announcement

Collapse
No announcement yet.

Replacing Static Mesh Component with other Unreal mesh from REVIT RPC to Unreal Trees

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Replacing Static Mesh Component with other Unreal mesh from REVIT RPC to Unreal Trees

    So the title kind of describes what I am looking for.
    I have this scene that is coming from REVIT. This REVIT file was using RPC for trees, plants, and people when imported into Unreal using DataSmith, none of the RPC elements came (that's good) but I get a Static Mesh Component instead on the location of this element.
    I would like to replace all those 'Dots" with Unreal trees and plants. I have been looking at the Docs but I can't find a solution that works. Most of the replacement method points for geometry in the scene not these dots from Data Smith.
    Any help is appreciated.
    Fco.
    Francisco Penaloza.
    Sr. Visualization Artist
    HMC Architects

    #2
    Here's a quick script I wrote up some time ago:

    Code:
    import unreal
    
    ##### Replace RPC assets
    
    rpc_replacement_asset = '/Game/MultiUserViewer/Meshes/Tree/HillTree_02.HillTree_02'
    rpcs_to_replace = [
    'Hawthorn',
    'Honey_Locust',
    'Largetooth_Aspen',
    'Lombardy_Poplar',
    'Red_Ash',
    'Red_Maple',
    'Scarlet_Oak'
    ]
    
    all_actor_components = unreal.EditorLevelLibrary.get_all_level_actors_components()
    loaded_asset = unreal.EditorAssetLibrary.load_asset(rpc_replacement_asset)
    for component in all_actor_components:
        if component.component_has_tag("Revit.RPC"):
            actor_name = component.get_owner().get_name()
            print("Found an RPC component: " + actor_name)
            for replacement_key in rpcs_to_replace:
                if (actor_name.startswith(replacement_key)):
                    print("Replacing...")
                    spawn_location = component.get_owner().get_actor_location()
                    spawn_rotation = component.get_owner().get_actor_rotation()
                    # randomize the rotation
                    spawn_rotation.yaw = unreal.MathLibrary.random_float_in_range(0,360)
                    # spawn the actor
                    new_actor = unreal.EditorLevelLibrary.spawn_actor_from_object(loaded_asset, spawn_location, spawn_rotation)
                    # randomize its scale factor
                    scale_factor = unreal.MathLibrary.random_float_in_range(0.75,1.25)
                    world_scale = new_actor.get_actor_scale3d()
                    world_scale.z = world_scale.z * scale_factor
                    new_actor.set_actor_scale3d( world_scale )
                    # make the new actor a child of the RPC actor
                    new_actor.attach_to_actor( component.get_owner(), "", unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, unreal.AttachmentRule.KEEP_WORLD, False )
                    break
    Basically it looks through all the Static Mesh components in the level, looking for ones that have the "Revit.RPC" tag. For each of those, it checks the name of the asset against a list of trees and foliage types (I didn't want to replace people or cars, for example). Then, for each one that matches, it spawns a new instance of an existing tree Static Mesh at the same location, with a random rotation and scale. Finally, it attaches that newly spawned actor to the RPC object so that it shows up as a child in the World Outliner hierarchy.

    hope that helps!

    Comment


      #3
      This looks really cool, I am out of the office now, but as soon I go back I give it a try, thank you very much.
      Francisco Penaloza.
      Sr. Visualization Artist
      HMC Architects

      Comment


        #4
        Thank you so much for your great information, It is too useful for me MyBKExperience
        Last edited by Waderan666; 02-28-2019, 06:24 AM.

        Comment


          #5
          Well I am back to this project, and this is not working for me, I am sure that I am doing something wrong.
          First where I can put this code? in the cmd??

          Second I attached manually new trees to the Data Smith actor icons, but when the data Smith file update, the attached geometry doesn't move or update.
          your help is appreciated.
          Francisco Penaloza.
          Sr. Visualization Artist
          HMC Architects

          Comment


            #6
            Sorry to nag guys, but I really need help with this.
            For our workflow, RPC is a big thing ( I don't know why for Architects) I really need a better way to replace these objects with Native Unreal geometry or something that render better.
            As it is, for now, I have to go one by one replacing, but if I update the DATA smith file all those links are lost.

            Francisco Penaloza.
            Sr. Visualization Artist
            HMC Architects

            Comment


              #7
              Hey fco3d, you can save that script in a .py file on your computer. Then you'll need to activate the Python Scripting Plugin and the Editor Scripting Utilities Plugin in your Project. Once you've done that, you can run your script by going to File > Execute Python Script in the Unreal Editor.

              See the docs on Python at https://docs.unrealengine.com/en-us/...omation/Python

              Comment


                #8
                Thank you Ro-Su- this works great!
                NOw the sad part if when you re-import the Datasmith file it loses the connection between the nodes and the replaced trees. So I need to run the scrip every time.
                Not sure why it would do that since the Data smith nodes a the named the same just the location change.
                Anyways this script works great.
                Thanks.
                Francisco Penaloza.
                Sr. Visualization Artist
                HMC Architects

                Comment

                Working...
                X