<?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: Texture mapping on a surface using c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13188404#M1699</link>
    <description>&lt;P&gt;getting these errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;'Mapper' does not contain a definition for 'MaterialTransform' and no accessible extension method 'MaterialTransform'&lt;BR /&gt;CS1061:&lt;/LI&gt;&lt;LI&gt;accepting a first argument of type 'Mapper' could be found (are you missing a using directive or an assembly reference?)&lt;BR /&gt;'Material' does not contain a definition for 'DiffuseMap'&lt;/LI&gt;&lt;LI&gt;Source MaterialMap.Source { get; }&lt;BR /&gt;Gets the data source of the material map; one of the MaterialMap.Source&amp;gt; enumerators.&lt;BR /&gt;CS0200: Property or indexer 'MaterialMap.Source• cannot be assigned to it is read only&lt;/LI&gt;&lt;LI&gt;CSOI 03: The name 'FileMaterialSource' does not exist in the current context&lt;/LI&gt;&lt;LI&gt;: 'MaterialMap' does not contain a definition for 'Filename'&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Tue, 03 Dec 2024 04:21:30 GMT</pubDate>
    <dc:creator>mayur_kapadnis</dc:creator>
    <dc:date>2024-12-03T04:21:30Z</dc:date>
    <item>
      <title>Texture mapping on a surface using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13186841#M1697</link>
      <description>&lt;P&gt;I have a surface in autocad, i have an image, i want to map that image on that surface, like we do it using RMAT command, how can I do it using c#?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 13:03:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13186841#M1697</guid>
      <dc:creator>mayur_kapadnis</dc:creator>
      <dc:date>2024-12-02T13:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Texture mapping on a surface using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13187134#M1698</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/16134452"&gt;@mayur_kapadnis&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;try it with the following code&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(TextureMappingExample))]

public class TextureMappingExample
{
    [CommandMethod("MapTexture")]
    public void MapTexture()
    {
        // Get the active document and database
        Document doc = Application.DocumentManager.MdiActiveDocument;
        Database db = doc.Database;

        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            // Select a surface
            PromptEntityOptions peo = new PromptEntityOptions("\nSelect a surface: ");
            peo.SetRejectMessage("\nOnly surfaces are allowed.");
            peo.AddAllowedClass(typeof(Surface), true);

            PromptEntityResult per = doc.Editor.GetEntity(peo);

            if (per.Status != PromptStatus.OK)
                return;

            // Open the surface for write
            ObjectId surfaceId = per.ObjectId;
            Surface surface = tr.GetObject(surfaceId, OpenMode.ForWrite) as Surface;

            if (surface == null)
            {
                doc.Editor.WriteMessage("\nSelected entity is not a surface.");
                return;
            }

            // Add a material with texture
            ObjectId materialId = AddMaterialWithTexture(db, tr, "MyTextureMaterial", "path_to_your_image.jpg");

            // Apply the material to the surface
            if (!materialId.IsNull)
            {
                surface.MaterialId = materialId;
                surface.MaterialMapper.MaterialTransform = Matrix3d.Identity;
            }

            tr.Commit();
        }
    }

    private ObjectId AddMaterialWithTexture(Database db, Transaction tr, string materialName, string imagePath)
    {
        // Get the material dictionary
        ObjectId materialDictId = db.MaterialDictionaryId;
        DBDictionary materialDict = tr.GetObject(materialDictId, OpenMode.ForWrite) as DBDictionary;

        // Check if material already exists
        if (materialDict.Contains(materialName))
        {
            return materialDict.GetAt(materialName);
        }

        // Create a new material
        Material material = new Material
        {
            Name = materialName,
            DiffuseMap = new MaterialMap
            {
                Source = FileMaterialSource.File,
                Filename = imagePath
            }
        };

        // Add the material to the dictionary
        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;BR /&gt;Furthermore, there is an extensive code from Pavliukas, which was made available in 2007. Many thanks for that.&lt;BR /&gt;&lt;A title="Ressource " href="https://forum.dwg.ru/showthread.php?t=15000&amp;amp;highlight=%EC%E0%F2%E5%F0%E8%E0%EB&amp;amp;pp=10000" target="_blank" rel="noopener"&gt;https://forum.dwg.ru/showthread.php?t=15000&amp;amp;highlight=%EC%E0%F2%E5%F0%E8%E0%EB&amp;amp;pp=10000&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 15:15:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13187134#M1698</guid>
      <dc:creator>M_Kocyigit</dc:creator>
      <dc:date>2024-12-02T15:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Texture mapping on a surface using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13188404#M1699</link>
      <description>&lt;P&gt;getting these errors:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;'Mapper' does not contain a definition for 'MaterialTransform' and no accessible extension method 'MaterialTransform'&lt;BR /&gt;CS1061:&lt;/LI&gt;&lt;LI&gt;accepting a first argument of type 'Mapper' could be found (are you missing a using directive or an assembly reference?)&lt;BR /&gt;'Material' does not contain a definition for 'DiffuseMap'&lt;/LI&gt;&lt;LI&gt;Source MaterialMap.Source { get; }&lt;BR /&gt;Gets the data source of the material map; one of the MaterialMap.Source&amp;gt; enumerators.&lt;BR /&gt;CS0200: Property or indexer 'MaterialMap.Source• cannot be assigned to it is read only&lt;/LI&gt;&lt;LI&gt;CSOI 03: The name 'FileMaterialSource' does not exist in the current context&lt;/LI&gt;&lt;LI&gt;: 'MaterialMap' does not contain a definition for 'Filename'&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 03 Dec 2024 04:21:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13188404#M1699</guid>
      <dc:creator>mayur_kapadnis</dc:creator>
      <dc:date>2024-12-03T04:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Texture mapping on a surface using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13188610#M1700</link>
      <description>Have you already tried testing and experimenting with the provided resources? If I have time, I will take a closer look.</description>
      <pubDate>Tue, 03 Dec 2024 07:00:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/texture-mapping-on-a-surface-using-c/m-p/13188610#M1700</guid>
      <dc:creator>M_Kocyigit</dc:creator>
      <dc:date>2024-12-03T07:00:38Z</dc:date>
    </item>
  </channel>
</rss>

