Replace objects script?

Started by willchocks7, May 27, 2016, 02:50:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

willchocks7

Hi Everyone!

I have been using Keyshot for a while and have always had one problem. I have placeholder models which need to be swapped out with new models that have updated UV coordinates but are otherwise identical (pivots and geometry are the same).

I would love if Luxion would make substitution of objects a feature of Keyshot!

Anyway, is there a simple python script I can use to replace models in my scene?

I'm afraid I have only a very basic understanding of Python. Can anyone help me out?

Thanks so much!


Will Gibbons

Hi,

Quick question, does the live linking feature not work for you in this case? What program is your geometry coming from?

guest84672

Or use update geometry, as long as the name is the same.

willchocks7

#3
Hi Guys,

Thanks for the quick reply!

My exact problem is:

I'm using Solid Edge to set up a kind of architectural scene, then sending it to Keyshot for rendering.

The models I need to replace are 3D people which are placed in the scene. I had to convert the 3D people to .stl in order to get them into Solid edge. Now that these 3D people are in .stl format, they don't have UV maps. So when I send the scene to Keyshot for rendering, my 3D people look shocking.

I need to replace these 3D people with their original source models (which are .obj.) using Keyshot but there is no simple way to do this besides placing them by hand.

I was just hoping that I may be able to find someone here to help me with a script that could place the imported models quickly, saving a heap of time as I have usually around 30 people in my scenes.

Is anyone out there amazing enough to help me out?

willchocks7

I was thinking of a script that would behave in this way:

You import your models with working UVs into the scene and just have them floating in the scene.

1. Click the object that you want to replace (Get it's transforms)

2. Click the object that you want to take it's place. (Apply the transforms to the second model)

3. Delete the old placeholder model.

I know I'm probably asking way too much but does anyone who knows Python know how to write a simple script such as this?

TpwUK

It's very possible if thought through, but not as an animation it would be more a case of now ya see me now ya don't. My way of thinking is that you would duplicate the first selected object and place it hidden where the swap part is, then hide or delete the swapped parts.

Martin

willchocks7

I wasn't thinking of doing an animation. I just really need a script that can swap out one object for another.

Just swapping transforms.

TpwUK

Your problem sounds to be more one of ambiguity more than anything else. Break it down into blocks and how to solve, such as:

Import Architectural model and apply materials, set camera views etc.

The tricky part starts here:

Import stock people (stl) using Add To Scene scale and place where needed, apply materials etc

Depending on the camera view, manually hide the people you don't need active in that frame shot.

There is no need for a script, because the script could only offer a repeat of the scene tree structure for you to select which people are on or off, so you may as well just use what KS has already provided.

As a thing for the future, when you get the time is to go through your UV ready people and save them out as ready textured bip files, this way you could then use a script that could import them into the scene and swap as needed since the KS scene tree uses the filename of the geometry as a parent  object. Using this method you can then have some future proofing and can re-use them as needed.

Martin

willchocks7

Hi Martin,

Thank you kindly for your reply.

The reason I made this post was because I have many, many people in my scene in very particular positions. And multiple scenes to render every day.

For example: One person might be using a workout machine and so they require very careful placement so that they are holding the right parts of the machine.

I just thought it would be ideal to have a script that could automate the placement of my 3D people for me.

My situation and how I think this could work: (Forget everything I said before)

I have some 3D people already placed in my scene. These people came in with my scene which was built in Solid Edge (Which doesn't support UVs, and so the 3D people have lost their UV coordinates)

I just need to swap these already placed models with the UV ready models (which I would import into Keyshot separately.)

Could a script simple script not do this?

Get the transforms of the existing 3D person.

Apply those transforms to the UV ready person.

All this in a few clicks rather than a few minutes of careful manual placement.

Thanks again for your reply Martin. I just really need this because my boss (who isn't tech savvy at all) is going to think I'm a blundering fool if i can't get these 3D people to have working textures!  ::)

TpwUK

If the figures in your scene have sensible names then it should be do able as long as the stl figures have been exported ready in position and pose etc, then you should be able to do an import in with location set to keep original and not alter camera settings. Do this for every figure that needs to be replaced, but you will still need to go through them all and set materials and textures etc to be UV mapped.

So yes it's scriptable for removing the non UV figure with the STL version as long as naming conventions of some sort are followed and as long as the figures were exported from your master model already in place and scaled.

Scripting would have a flow like this ...

search sceneTree for "NameOfModelFigure-???" (where ? would equal number) and would be of type Group
add models that are found to a list
Using that list, iterate through the results and import NameOfModelFigure-??? with the same name STL file with no camera adjustments, and set to add to scene and keep original location, then delete the non STL figure from the sceneTree

From this point you would then need to apply textures and materials of the STL figures. Unless of course the figures are ready mapped and textured.

Martin

willchocks7

What would that look like in code? :-\

TpwUK

I have a bit of a busy schedule this week, if you have the time to wait I will see if i can get time at the week end to try and drum up a script that should do what you want,  I can't guarantee it though as my disabled wife is having complications to her condition and i might need more time depending on hospital results and checks etc. You will also need to customise the script to suit your needs though but I shall try and comment it so you know what's happening where.

Martin

willchocks7

You are an absolute life saver Martin, thank you so much.

Take all the time you need and of course put your life first.

I look forward to your response.

-Will

willchocks7

Never mind, Martin!

I've found a workaround by taking my scene to 3DS Max and placing the 3D people there, then sending them back over to key shot and merging them with my scene.

I won't be needing a script right now, but if you've already written it then definitely post it as others may have a need for it and maybe I'll use it for other purposes as it would still be extremely useful.

Thank you so much for your time regardless, Martin.

-Will

TpwUK

Thanks for letting me know Will, I had not started it yet so all good there.

Martin