<?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: Argument 2: cannot convert from 'void' in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191255#M1680</link>
    <description>&lt;P&gt;thanks you point it out for me&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2024 04:16:10 GMT</pubDate>
    <dc:creator>dinhthit25</dc:creator>
    <dc:date>2024-12-04T04:16:10Z</dc:date>
    <item>
      <title>Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13190820#M1678</link>
      <description>&lt;P&gt;i stuck at this problem&amp;nbsp;Argument 2: cannot convert from 'void' to 'Autodesk.AutoCAD.Colors.Color'&lt;BR /&gt;does anyone know how to fix this or give me an advise how to fix this&lt;BR /&gt;im using C#.net framework 4.8&lt;/P&gt;&lt;LI-CODE lang="general"&gt;private void ApplyColorsTo3DObject()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    if (_color1 == null || _color2 == null)
    {
        ed.WriteMessage("\nPlease choose two colors.");
        return;
    }

    using (var docLock = doc.LockDocument())
    {
        PromptEntityOptions peo = new PromptEntityOptions("\nSelect a 3D solid:");
        peo.SetRejectMessage("\nOnly 3D solids are allowed.");
        peo.AddAllowedClass(typeof(Solid3d), true);
        var per = ed.GetEntity(peo);

        if (per.Status != PromptStatus.OK)
        {
            ed.WriteMessage("\nNo valid 3D solid selected.");
            return;
        }

       

        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            Solid3d solid3d = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
            if (solid3d == null)
            {
                ed.WriteMessage("\nSelected object is not a valid Solid3d.");
                return;
            }

            try
            {
                // Tạo FullSubentityPath để truy cập BREP
                var fullSubentityPath = new FullSubentityPath(new[] { per.ObjectId }, new SubentityId(SubentityType.Null, IntPtr.Zero));

                using (var brep = new Brep(fullSubentityPath))

                {
                    int faceIndex = 0;
                    foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face face in brep.Faces)
                    {
                        try
                        {
                            // Lấy SubentityId của mặt
                            var subEntityId = face.SubentityPath.SubentId;

                            // Chọn màu xen kẽ dựa trên chỉ số mặt
                            var colorToApply = (faceIndex % 2 == 0) ? _color1 : _color2;

                            solid3d.SetSubentityColor(subEntityId, ApplyColorToFace(solid3d, face, colorToApply));
                          
                            faceIndex++;
                        }
                        catch (System.Exception ex)
                        {
                            ed.WriteMessage($"\nError applying color to face: {ex.Message}");
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\nError processing solid: {ex.Message}");
            }

            tr.Commit();
        }
    }
}

private void ApplyColorToFace(Solid3d solid, Autodesk.AutoCAD.BoundaryRepresentation.Face face, Autodesk.AutoCAD.Colors.Color color)
{
    try
    {
        var subentityId = face.SubentityPath.SubentId;
        solid.SetSubentityColor(subentityId, color);
    }
    catch (System.Exception ex)
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\nError applying color: {ex.Message}");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 03:36:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13190820#M1678</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-04T03:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191247#M1679</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;wrote:&lt;BR /&gt;&lt;P&gt;i stuck at this problem&amp;nbsp;Argument 2: cannot convert from 'void' to 'Autodesk.AutoCAD.Colors.Color'&lt;BR /&gt;does anyone know how to fix this or give me an advise how to fix this&lt;BR /&gt;im using C#.net framework 4.8&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;solid3d.SetSubentityColor(subEntityId, ApplyColorToFace(solid3d, face, colorToApply));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;Your code is calling SetSubEntityColor() and passing it an argument that is the result of a method that returns void.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 04:09:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191247#M1679</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-12-04T04:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191255#M1680</link>
      <description>&lt;P&gt;thanks you point it out for me&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 04:16:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191255#M1680</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-04T04:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191351#M1681</link>
      <description>&lt;P&gt;I don't understand why you use the ApplyColorToFace function when you could simply add one more parameter for the color in solid3d.SetSubentityColor(subEntityId, colorToApply).&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 04:26:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191351#M1681</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2024-12-04T04:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191353#M1682</link>
      <description>&lt;P&gt;may i ask do you know how to fix that line&lt;/P&gt;&lt;PRE&gt;solid3d.SetSubentityColor(subEntityId, ApplyColorToFace(solid3d, face, colorToApply));&lt;/PRE&gt;&lt;P&gt;i try changes&lt;/P&gt;&lt;PRE&gt;ApplyColorToFace&lt;/PRE&gt;&lt;P&gt;and it wont paint the color anymore&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 04:29:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191353#M1682</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-04T04:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Argument 2: cannot convert from 'void'</title>
      <link>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191381#M1683</link>
      <description>&lt;P&gt;now you mention it,&amp;nbsp;&lt;SPAN&gt;ApplyColorToFace not&amp;nbsp;necessary&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 04:37:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/argument-2-cannot-convert-from-void/m-p/13191381#M1683</guid>
      <dc:creator>dinhthit25</dc:creator>
      <dc:date>2024-12-04T04:37:45Z</dc:date>
    </item>
  </channel>
</rss>

