<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why my code won't work in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200921#M1583</link>
    <description>&lt;P&gt;Thanks you, now i can put both color in 1 solid3d object&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2024 09:43:36 GMT</pubDate>
    <dc:creator>dinhthit25</dc:creator>
    <dc:date>2024-12-09T09:43:36Z</dc:date>
    <item>
      <title>Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200406#M1572</link>
      <description>&lt;P&gt;I want to&amp;nbsp;&lt;SPAN&gt;paint 2 color alternate on every face of a solid3d object, im using&amp;nbsp;&lt;A href="https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Solid3d_SetSubentityMaterial_SubentityId_ObjectId" target="_blank" rel="noopener nofollow noreferrer"&gt;Solid3d.SetSubentityMaterial&lt;/A&gt;&amp;nbsp;method the code have no error but it won't work can anyone have me. Im using&amp;nbsp;C#.net framework 4.8 at visual studio 2022. Here the code&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public class Solid3dMaterialExample
{
    [CommandMethod("SetTwoColorsToSolid3dFaces")]
    public void SetTwoColorsToSolid3dFaces()
    {
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;
        Editor ed = doc.Editor;

        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            // Select Solid3d object
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Solid3d:");
            peo.SetRejectMessage("\nObject must be a Solid3d.");
            peo.AddAllowedClass(typeof(Solid3d), true);
            PromptEntityResult per = ed.GetEntity(peo);

            if (per.Status != PromptStatus.OK)
            {
                ed.WriteMessage("\nNo valid Solid3d selected.");
                return;
            }

            Solid3d solid3d = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
            if (solid3d == null)
            {
                ed.WriteMessage("\nFailed to access Solid3d.");
                return;
            }

            // Create two materials with different colors
            ObjectId materialId1 = CreateMaterial(tr, db, "Material1", Color.FromColorIndex(ColorMethod.ByAci, 1)); // Red
            ObjectId materialId2 = CreateMaterial(tr, db, "Material2", Color.FromColorIndex(ColorMethod.ByAci, 3)); // Blue

            // Check and apply alternating materials to the faces
            try
            {
                using (Brep brep = new Brep(solid3d))
                {
                    int faceIndex = 0;
                    foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face face in brep.Faces)
                    {
                        try
                        {
                            SubentityId faceId = face.SubentityPath.SubentId;

                            if (faceId.Type == SubentityType.Face) // Check the type of Subentity
                            {
                                // Apply alternating materials
                                ObjectId materialToApply = (faceIndex % 2 == 0) ? materialId1 : materialId2;
                                solid3d.SetSubentityMaterial(faceId, materialToApply);
                                ed.WriteMessage($"\nMaterial applied to face {faceIndex}.");
                                faceIndex++;
                            }
                        }
                        catch (System.Exception ex)
                        {
                            ed.WriteMessage($"\nError applying material to face: {ex.Message}");
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\nError processing Brep: {ex.Message}");
            }

            tr.Commit();
        }
    }

    private ObjectId CreateMaterial(Transaction tr, Database db, string materialName, Color color)
    {
        // Create a new material
        Material material = new Material
        {
            Name = materialName
        };  
        // Add the material to the MaterialDictionary
        DBDictionary materialDict = (DBDictionary)tr.GetObject(db.MaterialDictionaryId, OpenMode.ForWrite);
        ObjectId materialId = materialDict.SetAt(materialName, material);
        tr.AddNewlyCreatedDBObject(material, true);

        return materialId;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 02:29:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200406#M1572</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T02:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200429#M1573</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the code hitting this line ??&lt;/P&gt;&lt;PRE&gt;ed.WriteMessage($"\nMaterial applied to face {faceIndex}.");&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 02:55:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200429#M1573</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2024-12-09T02:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200438#M1574</link>
      <description>&lt;P&gt;i dubugging it and this line appear:&lt;BR /&gt;Autodesk.AutoCAD.BoundaryRepresentation.Exception: 'Exception of type 'Autodesk.AutoCAD.BoundaryRepresentation.Exception' was thrown.'&lt;BR /&gt;i hope i can print&amp;nbsp;&lt;SPAN&gt;2 color alternate on every face of a solid3d object but won't&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:04:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200438#M1574</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T03:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200445#M1575</link>
      <description>&lt;P&gt;On what line was the error reported ?&lt;BR /&gt;&lt;BR /&gt;What was the actual error ?&lt;BR /&gt;&lt;BR /&gt;How complex was the solid you are testing with ?&lt;BR /&gt;&lt;BR /&gt;Any other information you can think of that may help resolve the issue ?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:08:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200445#M1575</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2024-12-09T03:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200458#M1576</link>
      <description>&lt;P&gt;This looks suspect. Are you sure this block of code is correct ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        // Create a new material
        Material material = new Material
        {
            Name = materialName
        };  &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How much help did you get from an AI source ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:29:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200458#M1576</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2024-12-09T03:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200475#M1577</link>
      <description>&lt;P&gt;sorry for my deficiency,&lt;BR /&gt;I use ai on&amp;nbsp;private ObjectId CreateMaterial class&lt;/P&gt;&lt;P&gt;i do not check that code you sent thoroughly&amp;nbsp;&lt;BR /&gt;when i debug, this happen&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dinhthit25_0-1733714564456.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1443612iDBDF8A5B4B59EDD1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dinhthit25_0-1733714564456.png" alt="dinhthit25_0-1733714564456.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;this happen when i chose a solid3d object&lt;BR /&gt;and this is&amp;nbsp;&lt;SPAN&gt;the testing solid(it quite complex)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dinhthit25_1-1733714721307.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1443613i6151AA4C3CC2A83F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dinhthit25_1-1733714721307.png" alt="dinhthit25_1-1733714721307.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and&amp;nbsp;finally im changing it from using&amp;nbsp;&lt;SPAN&gt;Solid3d.SetSubentityColor method to using&amp;nbsp;&amp;nbsp;&lt;A href="https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-ManagedRefGuide-Autodesk_AutoCAD_DatabaseServices_Solid3d_SetSubentityMaterial_SubentityId_ObjectId" target="_blank" rel="noopener nofollow noreferrer"&gt;Solid3d.SetSubentityMaterial&lt;/A&gt;&amp;nbsp;method&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:28:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200475#M1577</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T03:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200487#M1578</link>
      <description>&lt;P&gt;I'd close that&amp;nbsp; drawing . . . it looks like about 30 solid components.&lt;BR /&gt;&lt;BR /&gt;Do your initial development on a simple solid ( or perhaps one of the bracing plate components )&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;You are currently catching System Exceptions.&amp;nbsp; Perhaps change that to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Autodesk.AutoCAD.BoundaryRepresentation.Exception&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 03:43:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200487#M1578</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2024-12-09T03:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200757#M1579</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I replied you in &lt;A href="https://forums.autodesk.com/t5/net/i-have-this-problem-i-need-solution/m-p/13192990" target="_blank" rel="noopener"&gt;another thread,&amp;nbsp;&lt;/A&gt;you need to use the Brep constructor which takes a FullSubentityPath as argument to be able to access to the Solid3d Subentities (Faces here).&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:13:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200757#M1579</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-12-09T08:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200799#M1580</link>
      <description>&lt;P&gt;im doing it, but i thinks my&amp;nbsp;&lt;SPAN&gt;FullSubentityPath wrong and&amp;nbsp;i&amp;nbsp;am trying to fix it,&amp;nbsp;&lt;SPAN class=""&gt;thanks&lt;/SPAN&gt;&amp;nbsp;again for your advice&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:23:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200799#M1580</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T08:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200826#M1581</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16546065"&gt;@dinhthit25&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;im doing it, but i thinks my&amp;nbsp;&lt;SPAN&gt;FullSubentityPath wrong and&amp;nbsp;i&amp;nbsp;am trying to fix it,&amp;nbsp;&lt;SPAN class=""&gt;thanks&lt;/SPAN&gt;&amp;nbsp;again for your advice&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You're not doing it in the code you posted in the thread:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;using (Brep brep = new Brep(solid3d))&lt;/LI-CODE&gt;
&lt;P&gt;I showed you how to do it &lt;A href="https://stackoverflow.com/questions/79243114/how-to-fix-exeption-type-of-in-c-net-objectarx" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:40:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200826#M1581</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-12-09T08:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200829#M1582</link>
      <description>&lt;P&gt;thanks you i will watch it agains&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:42:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200829#M1582</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T08:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why my code won't work</title>
      <link>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200921#M1583</link>
      <description>&lt;P&gt;Thanks you, now i can put both color in 1 solid3d object&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 09:43:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/why-my-code-won-t-work/m-p/13200921#M1583</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-09T09:43:36Z</dc:date>
    </item>
  </channel>
</rss>

