Applying a material to a DirectShape

Applying a material to a DirectShape

Anonymous
Not applicable
4,908 Views
4 Replies
Message 1 of 5

Applying a material to a DirectShape

Anonymous
Not applicable

Using the suggested TessellatedFace.MaterialId in Jeremy's post, I am able to set the material of faces when I'm building the geometry of a DirectShape.  However, if I wish to change the material later (because the user changed the value in the shared parameter), I'm stumped.  I can iterate through the faces of the DirectShape, but the MaterialId for those faces is read-only.  

 

The same post refers to SolidOptions.MaterialId... how does one use that to set the material?  Is it also only at time of creation?

 

If I want to change the material, do I need to reconstruct the DirectShape geometry from scratch, or is there a way to use the existing structure and just set some parameter?

 

Thanks,
Andrea

0 Likes
4,909 Views
4 Replies
Replies (4)
Message 2 of 5

Revitalizer
Advisor
Advisor

Hi Andrea,

 

you cannot assign a Material FamilyParameter to a DirectShape object.

If you cannot do it in the GUI, you cannot do it via API.

 

But since you are in Family context, you could use FreeFormElements, based on your Solids.

No need to use DirectShape at all, this way.

 

Once created such a FreeFormElement, you can assign a subcategory, add FamilyParameters and so on.

 

 

Best regards,

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 5

Anonymous
Not applicable

"No need to use DirectShape at all"

 

Actually, I'm writing a plugin that reads various types of meshes from files, and uses TessellatedShapeBuilder to create DirectShapes from the meshes.  I don't think there's a way to get the generated GeometryObjects into something visible in Revit besides using DirectShape?

 

Thanks,

Andrea

0 Likes
Message 4 of 5

Revitalizer
Advisor
Advisor

Dear Andrea,

 

you are absolutely right.

 

The FreeFormElements approach would need Solids, but you are working with Meshes.

 

But what about this:

Use the TessellatedShapeBuilder to create your DirectShape Element.

In its Build method, you can set TessellatedShapeBuilderTarget.Solid to try to create a Solid body from the Mesh input.

 

If this would function as desired, your resulting DirectShape Element's geometry should contain at least one Solid.

If that is the case, just get that Solid, create your FreeFormElement using it, and after all, you could delete the original DirectShape Element.

In this approach, you would use DirectShape just as a temporary item, to generate Solid from a Mesh geometry.

 

I must admit that I didn't try this myself, it's just an idea.

 

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 5

Revitalizer
Advisor
Advisor

Dear Andrea,

 

I've tested my suggestion now (FreeFormElements instead of DirectShape).

I thought it could be an intermediate step to use TesselatedShapeBuilder to convert Meshes to Solids,

but this is not the case.

So the problem is definitely not solved yet.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes