editableAsset.FindByName("generic_diffuse") Showing Null whilst using PBR Assett

editableAsset.FindByName("generic_diffuse") Showing Null whilst using PBR Assett

sam.robertsRQ4X8
Participant Participant
625 Views
5 Replies
Message 1 of 6

editableAsset.FindByName("generic_diffuse") Showing Null whilst using PBR Assett

sam.robertsRQ4X8
Participant
Participant

I can get the Assett Property using the older Asset Types but not with the updated Assets.

 

ElementId appearanceAssetId = material.AppearanceAssetId;
AppearanceAssetElement assetElem = material.Document.GetElement(appearanceAssetId) as AppearanceAssetElement;

using (Transaction t = new Transaction(material.Document, "Change material bumpmap bitmap"))
{
t.Start();

using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(assetElem.Document))
{
Asset editableAsset = editScope.Start(assetElem.Id); // returns an editable copy of the appearance asset

AssetProperty bumpMapProperty = editableAsset.FindByName("generic_diffuse"); 
string propname1 = bumpMapProperty.Name;

0 Likes
Accepted solutions (1)
626 Views
5 Replies
Replies (5)
Message 2 of 6

GaryOrrMBI
Collaborator
Collaborator

1) Not all material Appearance Assets have the Generic Diffuse property.
2) Not all Generic Diffuse properties have an embedded UnifiedBitmap (which is the container for the BitMap properties)
3) the path is stored within the unifiedbitmap_Bitmap string property of the embedded Asset

 

Here is a clip from a utility that I just finished that creates a new material, then adds an embedded asset to the appearance Asset if it doesn't already have one, then assigns an image path to the embedded asset...

 

*Please note that I use text strings for all of the "findByName" calls but this doesn't translate to other languages and will be replaced with calls such as : FindByName(RDV.Generic.GenericDiffuse)

 

 

			Using editScope As New RDV.AppearanceAssetEditScope(thisDoc)
				' returns an editable copy of the new appearance asset
				Dim editableAsset As RDV.Asset = editScope.Start(thisAsset.Id)

				Dim descriptionProperty As RDV.AssetPropertyString = TryCast(editableAsset.FindByName("description"), RDV.AssetPropertyString)
				descriptionProperty.Value = "My First Generic Appearance Asset"

				'let's attach some images
				'create a reusable string for the images
				Dim imagePath As String

				'** add a generic Diffuse image to the Appearance Asset
				Dim diffuseMapProperty As RDV.AssetProperty = editableAsset.FindByName("generic_diffuse")
				Dim connectedDiffAsset As RDV.Asset = diffuseMapProperty.GetSingleConnectedAsset()
				' Add a new connected asset if it doesn't already have one
				If connectedDiffAsset Is Nothing Then
					diffuseMapProperty.AddConnectedAsset("UnifiedBitmap")
					connectedDiffAsset = diffuseMapProperty.GetSingleConnectedAsset()
				End If
				If connectedDiffAsset IsNot Nothing Then
					' Find the target asset path property
					Dim diffuseBitmapProperty As RDV.AssetPropertyString = TryCast(connectedDiffAsset.FindByName("unifiedbitmap_Bitmap"), RDV.AssetPropertyString)
					'build a path to an image
					imagePath = My.Computer.FileSystem.CombinePath(thisPath, "Concrete.Cast-In-Place.Exposed Aggregate.Medium.jpg")
					If diffuseBitmapProperty.IsValidValue(imagePath) Then
						diffuseBitmapProperty.Value = imagePath
					End If
				End If

 

 

Sorry for the VB but it's the only language that I can speak fluently at this time 🙂

 

-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 3 of 6

sam.robertsRQ4X8
Participant
Participant

Cheers for explaining this Gary, i was hoping it would be the case that the PBR assett didnt have a diffuse map but i have checked it on multiple assets and still not working. I have tried a few different ways to make sure its not an error in retrieving the diffusemap

//ATTEMPT  ONE
AssetPropertyDoubleArray4d genericDiffuseProperty = editableAsset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;

 

//ATTEMPT TWO

AssetProperty diffusemap = editableAsset2.FindByName("generic_diffuse");

 

//ATTEMPT THREE
AssetProperty genericDiffuseProperty = editableAsset.FindByName(Generic.GenericDiffuse);

 

All return null, i have tried it on Assets which definitely have a diffuse map not sure if it is accessed differently for PBR materials

 

0 Likes
Message 4 of 6

GaryOrrMBI
Collaborator
Collaborator

I may need to back up here and read a bit closer. I'm seeing two different aspects to this question:

 

1) a "PBR" asset... What exactly do you mean by that? Different material assets (as defined by the schema) store their bitmaps in different properties.

 

2) how to get the bitmap, if there is one associated, from a "Generic" asset (which is the only type of asset schema that stores the bitmap in the "Generic Diffuse" property).

 

I am attaching an xml file that I just produced using my material asset collector routine on a test file that I created specifically for the purpose of investigating materials and material assets and which has all of the asset types within it.

 

Perhaps this will help a bit with the relationships in different asset types.

 

{ I'm editing this to attach another xml file that has one material in it that is specifically a Generic asset and has embedded bitmaps for both the gereric_diffuse and generic_bump_map properties }

 

-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 5 of 6

sam.robertsRQ4X8
Participant
Participant

Thanks for Sendin gthese Gary,,

 

1) might not be using the right terminology but essentially the updated images PBR, hoopefully the screen grab helps clear this up

 

2) ive attached the code snippet to show how im getting and using the Diffuse Map

 

Thanks

0 Likes
Message 6 of 6

GaryOrrMBI
Collaborator
Collaborator
Accepted solution

That highlighted material is not a "Generic" asset.

 

Here is a generic Asset (like your upper group of materials that are working properly):

GaryOrrMBI_0-1688649012555.png

this is one of the advanced materials (like the ones that are posting as failures):

GaryOrrMBI_1-1688649119525.png

 

Here is the difference in code:

GaryOrrMBI_2-1688649317760.png

here is the location of one of the bitmaps that the PrismOpaqueSchema uses:

GaryOrrMBI_3-1688649559733.png

Notice that the property holding the bitmap is not "generic_diffuse", it is stored in the "opaque_albedo" property instead.

 

here are a couple new xml files that have those two materials in them for comparison.

 

-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