<?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: Run MESHSMOOTH through Editor.Command in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850171#M18049</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You should not call EditorCommand from within a transaction.&lt;/P&gt;
&lt;P&gt;Try like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("VCY_CreateMesh")]
public static void CreateMesh()
{
    var ed = Application.DocumentManager.MdiActiveDocument.Editor;

    var filter = new SelectionFilter(new[] { 
        new TypedValue(0, "3DSOLID"), 
        new TypedValue(8, "Roads,Terrain") });

    var psr = ed.SelectAll(filter);

    if (psr.Status == PromptStatus.OK)
        ed.Command("_.MESHSMOOTH", psr.Value, "");
}&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 06 Nov 2020 12:11:21 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-11-06T12:11:21Z</dc:date>
    <item>
      <title>Run MESHSMOOTH through Editor.Command</title>
      <link>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850093#M18048</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to create a command that converts 3DSolid entities to Mesh (not PolyFaceMesh).&amp;nbsp; (Part of a bigger command).&lt;/P&gt;&lt;P&gt;I couldn't find a direct way of converting using the .Net API so have looked at calling MESHSMOOTH through Editor.Command().&amp;nbsp; The code below runs with no errors but no changes are made to the solids.&amp;nbsp; The same solids convert successfully if I manually call the command on the AutoCAD command line.&amp;nbsp; If I change the code and switch the passed in command to ERASE then the process works.&amp;nbsp; So are there certain AutoCAD commands that do not support being called from Editor.Command()?&lt;/P&gt;&lt;P&gt;Also, if anyone knows how to convert 3DSolid to Mesh using .NET API I would be grateful to know!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[Autodesk.AutoCAD.Runtime.CommandMethod("VCY_CreateMesh", CommandFlags.UsePickSet)]
public void CreateMesh()
{
	Document doc = Application.DocumentManager.MdiActiveDocument;
	Database db = doc.Database;
	Editor ed = doc.Editor;

	PromptSelectionResult psr = null;

	TypedValue[] filterlist = new TypedValue[2];

	//select only 3DSOLIDs
	filterlist[0] = new TypedValue(0, "3DSOLID");

	//8 = DxfCode.LayerName
	filterlist[1] = new TypedValue(8, "Roads,Terrain");

	SelectionFilter filter = new SelectionFilter(filterlist);

	psr = ed.SelectAll(filter);

	Transaction tr = db.TransactionManager.StartTransaction();

	using (tr)
	{
		ed.Command("_.MESHSMOOTH", psr.Value, ""); // doesn't work
		//ed.Command("_.ERASE", psr.Value, ""); // does work

		// Do i need a transaction when calling ed.Command?
		tr.Commit();
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 11:25:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850093#M18048</guid>
      <dc:creator>grahamcook</dc:creator>
      <dc:date>2020-11-06T11:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Run MESHSMOOTH through Editor.Command</title>
      <link>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850171#M18049</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You should not call EditorCommand from within a transaction.&lt;/P&gt;
&lt;P&gt;Try like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[CommandMethod("VCY_CreateMesh")]
public static void CreateMesh()
{
    var ed = Application.DocumentManager.MdiActiveDocument.Editor;

    var filter = new SelectionFilter(new[] { 
        new TypedValue(0, "3DSOLID"), 
        new TypedValue(8, "Roads,Terrain") });

    var psr = ed.SelectAll(filter);

    if (psr.Status == PromptStatus.OK)
        ed.Command("_.MESHSMOOTH", psr.Value, "");
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 06 Nov 2020 12:11:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850171#M18049</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-11-06T12:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Run MESHSMOOTH through Editor.Command</title>
      <link>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850936#M18050</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks for responding.&amp;nbsp; Removing the transaction made no difference.&amp;nbsp; But it turns out if I test this on two very simple primitive solids (a box) then it works.&amp;nbsp; If the solids are non-primitive solids and I run the MESHSMOOTH manually in the command prompt I get the attached dialog prompt.&amp;nbsp; I tick the box and click Create Mesh and my solid gets converted.&amp;nbsp; Now, you would think that because I have ticked the box that any subsequent conversions will just convert without the prompt being shown but that's not the case if I call the MESHSMOOTH command from Editor.Command().&lt;BR /&gt;The Revit API has an option to deal with Failures or popup warnings of this nature (FailuresAccessor class) so I wonder if there is anything similar in the AutoCAD API?&amp;nbsp; Anyway, I suspect that the popup (which doesn't actually show when automating through Editor.Command()) is influencing the result here.&amp;nbsp; Popup dialog is attached.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 17:29:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9850936#M18050</guid>
      <dc:creator>grahamcook</dc:creator>
      <dc:date>2020-11-06T17:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Run MESHSMOOTH through Editor.Command</title>
      <link>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9863837#M18051</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the end I found out how to do this by creating a SubDMesh:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[CommandMethod("VCY_CreateMesh")]
public static void CreateMesh()
{
    var ed = Application.DocumentManager.MdiActiveDocument.Editor;

    var filter = new SelectionFilter(new[] { 
        new TypedValue(0, "3DSOLID"), 
        new TypedValue(8, "Roads,Terrain") });

    var psr = ed.SelectAll(filter);

    if (psr.Status != PromptStatus.OK)
        return;

    Transaction tr = db.TransactionManager.StartTransaction();
    using (tr)
    {
        for (int i = 0; i &amp;lt; psr.Value.Count; i++)
        {
            Solid3d mySolid = 
             (Solid3d)psr.Value[i].ObjectId.GetObject(OpenMode.ForWrite);

            MeshFaceterData mfd = new MeshFaceterData();
            mfd.FaceterMeshType = 0;
            mfd.FaceterMaxEdgeLength = 0;
              
            // Create new mesh from solid (smoothing level 0)
            MeshDataCollection meshData = 
                          SubDMesh.GetObjectMesh(mySolid, mfd);
            SubDMesh myMesh = new SubDMesh();
            myMesh.SetSubDMesh(meshData.VertexArray, 
                            meshData.FaceArray, 0); // smoothing 0

            // Add mesh to database.
            myMesh.SetDatabaseDefaults();
            BlockTableRecord btr = 
                 (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, 
                          OpenMode.ForWrite);
            btr.AppendEntity(myMesh);
            tr.AddNewlyCreatedDBObject(myMesh, true);

            mySolid.Erase();
        }
                
        tr.Commit();
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 12 Nov 2020 07:48:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/run-meshsmooth-through-editor-command/m-p/9863837#M18051</guid>
      <dc:creator>grahamcook</dc:creator>
      <dc:date>2020-11-12T07:48:34Z</dc:date>
    </item>
  </channel>
</rss>

