assign material to directshape via paint

assign material to directshape via paint

Ning_Zhou
Advocate Advocate
3,136 Views
14 Replies
Message 1 of 15

assign material to directshape via paint

Ning_Zhou
Advocate
Advocate

seems it's not working.

 

I tried 2017 new ShapeImporter to create DirectShape element, works fine, but doesn't work when using Document.Paint, is it because I have to use it before or during creating DirectShape? if so then how to get Element Id, I mean e.Id of doc.Paint(e.Id, face, mat.Id) in which e is newly created DirectShape element.

 

besides, still no way to directly assign material to DirectShape element?

0 Likes
Accepted solutions (1)
3,137 Views
14 Replies
Replies (14)
Message 2 of 15

Mustafa.Salaheldin
Collaborator
Collaborator

Can you please provide a sample of your Revit project and the VS solution, so I may can help.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

0 Likes
Message 3 of 15

Ning_Zhou
Advocate
Advocate

thanks Mustafa for your reply.

 

I noticed that I cannot paint directshape element in the GUI so I assume it's not doable via API

http://forums.autodesk.com/t5/revit-api-forum/applying-material-to-solid/m-p/5836373/highlight/false...

 

per Jeremy's post, seems the only way is via TessellatedFace.MaterialId, it will add material at the time of creating directshape element, not afterward

0 Likes
Message 4 of 15

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Ning,

 

Thank you for your query.

 

As far as I know, you can assign a category to a direct shape.

 

You can use that to control the material.

 

You can also assign sub-categories, over which you can have total control, afaik.

 

Does that possibly provide all you need?

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 15

Ning_Zhou
Advocate
Advocate

thanks Jeremy for your time looking into this issue and the workarounds you provided, works fine in most cases especially for VG Overrides per view even though it's not a real material.

 

just a thought, i assume ShapImporter is created from TessellatedFaces, if so then material option will be great just like

shapeImporter.InputFormat = ShapeImporterSourceFormat.SAT;

0 Likes
Message 6 of 15

jeremytammik
Autodesk
Autodesk

Dear Ning,

 

Thank you for your update and appreciation.

 

I am very glad it helps.

 

Can you provide a minimal non-confidential sample demonstrating how you use it for me to share on the blog?

 

I do not quite understand the second part describing your wish. Can you clarify that, please?

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 15

Ning_Zhou
Advocate
Advocate

thanks Jeremy,

 

the following code is from RevitAPI.chm

ShapeImporter shapeImporter = new ShapeImporter();
shapeImporter.InputFormat = ShapeImporterSourceFormat.SAT;
IList<GeometryObject> shapes = shapeImporter.Convert(revitDoc, ofd.FileName);

if (shapes.Count != 0)
{
  using (Transaction tr = new Transaction(revitDoc, "Create a DirectShape"))
  {
   tr.Start();

  DirectShape dsImportedSat = DirectShape.CreateElement(revitDoc, new ElementId(BuiltInCategory.OST_Walls));
   dsImportedSat.SetShape(shapes);

  tr.Commit();
  }
}

 

my wish is something like below

shapeImporter.MaterialId = whatever;

 

is ShapeImporter class developed based on TessellatedShapeBuilder class?

the following code is also from RevitAPI.chm

TessellatedShapeBuilder builder = new TessellatedShapeBuilder();

// omitted

builder.AddFace(new TessellatedFace(loopVertices, materialId));

// omitted

 

hope it helps.

0 Likes
Message 8 of 15

jeremytammik
Autodesk
Autodesk

Dear Ning,

 

There may be a good reason why the TessellatedFace provides that option and the ShapeImporter does not.

 

Please provide a detailed description of exactly what you wish to achieve and why, so I can ask the development team what approach they would suggest.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 15

Ning_Zhou
Advocate
Advocate

thanks Jeremy, this issue is not that critical so i'll take your suggestion as solution

0 Likes
Message 10 of 15

BOb_Zhu
Contributor
Contributor

How can I assign sub-categories for DirectShape?I know that,When creating a DirectShape,I only set a Top-Level categoy.

 

0 Likes
Message 11 of 15

jeremytammik
Autodesk
Autodesk

Here, it says that the old version only supported top-level categories, before Revit 2017:

 

https://thebuildingcoder.typepad.com/blog/2016/04/whats-new-in-the-revit-2017-api.html#2.18

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 12 of 15

BOb_Zhu
Contributor
Contributor

Thanks Jeremy!

0 Likes
Message 13 of 15

BOb_Zhu
Contributor
Contributor
DirectShape ds = DirectShape.CreateElement(doc, subCategory.Id);

 After being tested on revit2018, this is not yet possible,Can you point out the right way?

0 Likes
Message 14 of 15

jeremytammik
Autodesk
Autodesk

The correct way is always to RTFM; in this case, the developer guide section on DirectShape:

 

http://help.autodesk.com/view/RVT/2020/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Revit_Geometri...

 

I'm sorry to say it is still impossible, presumably intentionally:

 

A DirectShape object may be assigned a top-level Model category, such as the Wall category. Sub-categories cannot be assigned to DirectShape elements. The IsValidCategoryId() method can test a category id to make sure it is a top-level built-in category approved for use with DirectShape and the Category.CategoryType enumerated value will indicated if the category type is Model.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 15 of 15

zhongding_cui
Contributor
Contributor

The "accepted solution" is very misleading. Please take it down and make the latest reply "intentionally impossible" as the "solution".

0 Likes