Getting a DModelPanel's Model

Is there a way?

[lua]
iconmodel:GetModel()
[/lua]

doesen’t work

Look below.

Look below.

DModelPanel.Entity:GetModel() I believe.

Cheers Chewgum.

Assuming of course that .Entity is valid. In certain situations the panel’s entity will not be valid.

I thought all models had to be an entity?

Yes, all model panels use entities (ClientsideModel() to be precise), but what I’m saying is the entity may be nil or invalid if something hasn’t been done or there are errors.

The entity may not exist yet, such as before setting the model or after setting the entity’s model to an invalid model. The DModelPanel has safeguards built in to check this and so should any code grabbing the entity from the DModel.

See lines 26, 70, 89:
http://luabin.foszor.com/code/addons/derma/lua/vgui/DModelPanel.lua

If it’s done right that wouldn’t be a problem?

If everything was reasonably within your control then yeah it wouldn’t be much of a problem. If you were doing something like listing all the models in a directory though and it failed to load a corrupted model, then that could generate errors when you try to grab it’s model.