<?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 How to 'Project Objects To Profile View' with C# from Modeless Dialog? in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13338791#M338</link>
    <description>&lt;P&gt;How can I use the 'Project Objects To Profile View' command using the Civil 3D API, with C#, to project a selected Solid3d to the selected Profile View &lt;STRONG&gt;from a Modeless Dialog&lt;/STRONG&gt;?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The API does not support this call, I followed this&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/how-can-i-use-project-objects-to-profile-view-with-c/td-p/12874741" target="_blank"&gt;https://forums.autodesk.com/t5/net/how-can-i-use-project-objects-to-profile-view-with-c/td-p/12874741&lt;/A&gt;&amp;nbsp;topic to use the Editor.Command();&lt;BR /&gt;&lt;BR /&gt;However, when I try to call this command from the Modeless Dialog, I get an 'Invalid input' exception.&lt;BR /&gt;&lt;BR /&gt;My command uses this flag:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("DoProjectToProfileView", CommandFlags.UsePickSet)]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;This is the relevant code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// clear the pickfirst set
_ed.SetImpliedSelection(new ObjectId[0]);

// create selection sets
ObjectId[] solidIds = { selectedSolidId };
ObjectId[] profViewIds = { _selectedProfileViewId };
var solidSelectionSet = SelectionSet.FromObjectIds(solidIds);
var profileSelectionSet = SelectionSet.FromObjectIds(profViewIds);

// project
_ed.Command("_.AECCPROJECTOBJECTSTOPROF", solidSelectionSet, "", profileSelectionSet, "");&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I tried to surround the Editor.Command with&amp;nbsp;&lt;STRONG&gt;using (_doc.LockDocument())&lt;/STRONG&gt;, same as when calling transactions from the Modeless dialog, but it does not help, same exception shows.&lt;BR /&gt;&lt;BR /&gt;If I &lt;STRONG&gt;Close();&lt;/STRONG&gt; the dialog and then try to do the above code, I again get the same exception.&lt;BR /&gt;&lt;BR /&gt;I tried to use the dynamic variable, and got half a result. I can successfully run the command, but cannot set the selection sets.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;dynamic doc = _doc.GetAcadDocument();
doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r");

// this works as well:
doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF ");

// but none of these do!
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet, "\r");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet, " ");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;What else could I try, or do not understand? Calling the C3D commands is always a heavy guesswork for me, on trying to replicate the C3D workflow.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2025 14:59:20 GMT</pubDate>
    <dc:creator>tipitasa</dc:creator>
    <dc:date>2025-02-25T14:59:20Z</dc:date>
    <item>
      <title>How to 'Project Objects To Profile View' with C# from Modeless Dialog?</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13338791#M338</link>
      <description>&lt;P&gt;How can I use the 'Project Objects To Profile View' command using the Civil 3D API, with C#, to project a selected Solid3d to the selected Profile View &lt;STRONG&gt;from a Modeless Dialog&lt;/STRONG&gt;?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The API does not support this call, I followed this&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/how-can-i-use-project-objects-to-profile-view-with-c/td-p/12874741" target="_blank"&gt;https://forums.autodesk.com/t5/net/how-can-i-use-project-objects-to-profile-view-with-c/td-p/12874741&lt;/A&gt;&amp;nbsp;topic to use the Editor.Command();&lt;BR /&gt;&lt;BR /&gt;However, when I try to call this command from the Modeless Dialog, I get an 'Invalid input' exception.&lt;BR /&gt;&lt;BR /&gt;My command uses this flag:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[CommandMethod("DoProjectToProfileView", CommandFlags.UsePickSet)]&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;This is the relevant code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// clear the pickfirst set
_ed.SetImpliedSelection(new ObjectId[0]);

// create selection sets
ObjectId[] solidIds = { selectedSolidId };
ObjectId[] profViewIds = { _selectedProfileViewId };
var solidSelectionSet = SelectionSet.FromObjectIds(solidIds);
var profileSelectionSet = SelectionSet.FromObjectIds(profViewIds);

// project
_ed.Command("_.AECCPROJECTOBJECTSTOPROF", solidSelectionSet, "", profileSelectionSet, "");&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I tried to surround the Editor.Command with&amp;nbsp;&lt;STRONG&gt;using (_doc.LockDocument())&lt;/STRONG&gt;, same as when calling transactions from the Modeless dialog, but it does not help, same exception shows.&lt;BR /&gt;&lt;BR /&gt;If I &lt;STRONG&gt;Close();&lt;/STRONG&gt; the dialog and then try to do the above code, I again get the same exception.&lt;BR /&gt;&lt;BR /&gt;I tried to use the dynamic variable, and got half a result. I can successfully run the command, but cannot set the selection sets.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;dynamic doc = _doc.GetAcadDocument();
doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r");

// this works as well:
doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF ");

// but none of these do!
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet);
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet, "");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, "\r", profileSelectionSet, "\r");
            doc.SendCommand("_.AECCPROJECTOBJECTSTOPROF\r", solidSelectionSet, " ", profileSelectionSet, " ");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;What else could I try, or do not understand? Calling the C3D commands is always a heavy guesswork for me, on trying to replicate the C3D workflow.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 14:59:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13338791#M338</guid>
      <dc:creator>tipitasa</dc:creator>
      <dc:date>2025-02-25T14:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to 'Project Objects To Profile View' with C# from Modeless Dialog?</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13339004#M339</link>
      <description>&lt;P&gt;I find that sometimes going over to LISP might help in understanding what arguments a particular method requires.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="lisp"&gt;(princ "\nSelect Solids: ")
(setq ss (ssget '(( 0 . "3DSOLID"))))
(setq ent (car (entsel "\nSelect Profile View: ")))
(command "_.AECCPROJECTOBJECTSTOPROF" ss "" ent "")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above LISP code will run and then display the dialog for choosing the projection style.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the command is being passed a selection set for the solid's argument, but a single objectID for the profile view argument.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using VB.NET (sorry, not sorry), I was successful with the following code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Dim selOpt As New PromptSelectionOptions
selOpt.MessageForAdding = vbCrLf &amp;amp; "Select Solids:"

Dim tvs(0) As TypedValue
tvs.SetValue(New TypedValue(DxfCode.Start, "3DSOLID"), 0)

Dim selFilter As New SelectionFilter(tvs)

Dim selRes As PromptSelectionResult = ed.GetSelection(selOpt, selFilter)

If selRes.Status &amp;lt;&amp;gt; PromptStatus.OK Then Exit Sub

Dim opt As New PromptEntityOptions(vbCrLf &amp;amp; "Select Profile View: ")
opt.SetRejectMessage(vbCrLf &amp;amp; "Selected entity must be a Profile View. Try again.")
opt.AddAllowedClass(GetType(ProfileView), True)

Dim res As PromptEntityResult = ed.GetEntity(opt)

If res.Status &amp;lt;&amp;gt; PromptStatus.OK Then Exit Sub

ed.Command("_.AECCPROJECTOBJECTSTOPROF", selRes.Value, "", res.ObjectId, "")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dialog box then displays prompting the user to select the projection style.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT - Being that you are invoking your command from a Modeless UI you will want to consider the coding required by a Modeless dialog, some of which you are already aware of, such as Locking the Document. Though, I am not sure if you also need to call the StartUserInteraction method or not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 16:33:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13339004#M339</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2025-02-25T16:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to 'Project Objects To Profile View' with C# from Modeless Dialog?</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13339279#M340</link>
      <description>&lt;P&gt;The issue is that editor.Command() cannot be used in Application context, which is the context when you start the code execution from an modeless UI. A recent discussion in the .NET forum provides the exact solution yo are looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/run-a-sample-command-with-parameters-using-c-net/td-p/13334844" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/net/run-a-sample-command-with-parameters-using-c-net/td-p/13334844&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 19:37:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13339279#M340</guid>
      <dc:creator>Norman_Yuan</dc:creator>
      <dc:date>2025-02-25T19:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to 'Project Objects To Profile View' with C# from Modeless Dialog?</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13341205#M341</link>
      <description>&lt;P&gt;Thank you both! I was not truly aware of the changed context in the Modeless Dialog.&lt;BR /&gt;&lt;BR /&gt;I now call the command using the extension method from&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&amp;nbsp; from the above linked topic&lt;BR /&gt;&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/run-a-sample-command-with-parameters-using-c-net/m-p/13335435/highlight/true#M85759" target="_blank"&gt;https://forums.autodesk.com/t5/net/run-a-sample-command-with-parameters-using-c-net/m-p/13335435/highlight/true#M85759&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// clear the pickfirst set
_ed.SetImpliedSelection(new ObjectId[0]);

ObjectId[] solidIds = { selectedSolidId };
ObjectId[] profViewIds = { _selectedProfileViewId };
var solidSelectionSet = SelectionSet.FromObjectIds(solidIds);
var profileSelectionSet = SelectionSet.FromObjectIds(profViewIds);

DocumentCollection docs = Application.DocumentManager;
try
{
     await docs.CommandAsync("_.AECCPROJECTOBJECTSTOPROF", solidSelectionSet, "", profileSelectionSet, "");
}
catch (System.Exception ex)
{
     docs.MdiActiveDocument.Editor.WriteMessage($"Operation failed: {ex.Message}");
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:11:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/how-to-project-objects-to-profile-view-with-c-from-modeless/m-p/13341205#M341</guid>
      <dc:creator>tipitasa</dc:creator>
      <dc:date>2025-02-26T15:11:24Z</dc:date>
    </item>
  </channel>
</rss>

