Author Topic: acedCmd with Civil 3D 2017  (Read 283 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 109
acedCmd with Civil 3D 2017
« on: April 11, 2017, 04:06:40 pm »
Hi,

I have this in my coding for Civil 3D 2014 and it's working fine :

Code - C#: [Select]
  1. [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl)]
  2. extern static int acedCmd(IntPtr resbuf);

With Civil 3D 2017 it's doesn't work, it says acedCmd is not found in accore.dll

I'm using VS 2010, .NET Framework 4.0 for Civil 3D 2014 and VS 2012, .NET Framework 4.5 for Civil 3D 2017. 

Jeff_M

  • King Gator
  • Posts: 3881
  • C3D user & customizer
Re: acedCmd with Civil 3D 2017
« Reply #1 on: April 11, 2017, 04:42:16 pm »
Reference the ObjectARX 2017 libraries.

gile

  • Water Moccasin
  • Posts: 2066
  • Marseille, France
Re: acedCmd with Civil 3D 2017
« Reply #2 on: April 11, 2017, 04:52:29 pm »
Hi,

Since A2015, you have to use the managed Editor.Command (or Editor.CommandAsync()) method.

You can see this topic and this one.
Speaking English as a French Frog

Jeff_M

  • King Gator
  • Posts: 3881
  • C3D user & customizer
Re: acedCmd with Civil 3D 2017
« Reply #3 on: April 11, 2017, 07:04:19 pm »
gile, I know that the acedCmd was supposed to be removed, but we still have code using it which works fine in 2015-2018 versions.

latour_g

  • Newt
  • Posts: 109
Re: acedCmd with Civil 3D 2017
« Reply #4 on: April 12, 2017, 01:20:48 pm »
Thanks for your reply.

Jeff_M : I have change for ObjectARX 2017 but it still doesn't work.  No error message but it just do nothing. 

gile : I have tried them both but I got an error message :

L'application ne prend pas en charge le dbogage
juste--temps (JIT). Consultez la fin de ce message pour plus de dtails.

************** Texte de l'exception **************
System.ArgumentException: La valeur n'est pas comprise dans la plage attendue.
    Autodesk.AutoCAD.DatabaseServices.ResultBuffer.ObjectToResbuf(Object o, resbuf** rb)
    Autodesk.AutoCAD.Runtime.Marshaler.ObjectToResbuf(Object o)
    Autodesk.AutoCAD.Runtime.Marshaler.ObjectsToResbuf(Object[] objects)
    Autodesk.AutoCAD.EditorInput.Editor.Command(Object[] parameter)
    C3DSectionPlot.SectDlg.acPlotSection() dans c:\prog\STN_R_C3DSectionPlot_2017\SectDlg.cs:ligne 1674
    C3DSectionPlot.SectDlg.btnPrint_Click(Object sender, EventArgs e) dans c:\prog\STN_R_C3DSectionPlot_2017\SectDlg.cs:ligne 1455
    System.Windows.Forms.Control.OnClick(EventArgs e)
    System.Windows.Forms.Button.OnClick(EventArgs e)
    System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    System.Windows.Forms.Control.WndProc(Message& m)
    System.Windows.Forms.ButtonBase.WndProc(Message& m)
    System.Windows.Forms.Button.WndProc(Message& m)
    System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

You wont be able to test this code but here it is, to give you an idea of what Im doing :

Code - C#: [Select]
  1.        private void acPlotSection()
  2.        {
  3.            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  4.  
  5.            using (ResultBuffer buffer = new ResultBuffer())
  6.            {
  7.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "_-Plot"));
  8.                // 1- detail plot configuration
  9.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acYES"))));
  10.                // 2- layout name
  11.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, LayoutManager.Current.CurrentLayout));
  12.                // 3- device name
  13.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, this.cboPrinter.SelectedItem.ToString()));
  14.                // 4- paper size
  15.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, this.cboMedia.SelectedItem.ToString()));
  16.                // 5- paper units
  17.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, ((pltSet.PlotPaperUnits == PlotPaperUnit.Millimeters) ? "M" : UTIL.showRscText(rm.GetString("acInches")))));
  18.                // 6- drawing orientation
  19.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, (this.rbLandscape.Checked) ? UTIL.showRscText(rm.GetString("acLandscape")) : "P"));
  20.                // 7- symetrie verticale
  21.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  22.                // 8- plot area
  23.                if (this.cboArea.SelectedIndex == 1)
  24.                {
  25.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acWindow"))));
  26.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTPOINT, pltWindow.MinPoint));
  27.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTPOINT, pltWindow.MaxPoint));
  28.                }
  29.                else if (this.cboArea.SelectedIndex == 2)
  30.                {
  31.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acLayout"))));
  32.                }
  33.                else
  34.                {
  35.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "E"));
  36.                }
  37.                // plot scale
  38.                if (this.chkFit.Checked)
  39.                {
  40.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acFit"))));
  41.                }
  42.                else
  43.                {
  44.                    if (pltSet.UseStandardScale == true)
  45.                    {
  46.                        buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTREAL, pltSet.StdScale));
  47.                    }
  48.                    else
  49.                    {
  50.                        CustomScale scale = pltSet.CustomPrintScale;
  51.                        buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTREAL, scale.Numerator / scale.Denominator));
  52.                    }
  53.                }
  54.                // plot offset
  55.                if (this.cboArea.SelectedIndex == 2)
  56.                {
  57.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTPOINT, new Point2d(0, 0)));
  58.                }
  59.                else
  60.                {
  61.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "C"));
  62.                }
  63.                // plot style
  64.                if (this.chkStyle.Checked && this.cboStyle.SelectedIndex > 0)
  65.                {
  66.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acYES"))));
  67.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, this.cboStyle.SelectedItem.ToString()));
  68.                }
  69.                else
  70.                {
  71.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  72.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "."));
  73.                }
  74.                // line weights
  75.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acYES"))));
  76.                // lineweight with plot scale
  77.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  78.                // paper space object first
  79.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  80.                // hide paper space object
  81.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  82.                // plot file
  83.                string outFile = savePath;
  84.                if (this.cboPrinter.SelectedItem.ToString().ToUpper().Contains("DWF"))
  85.                {
  86.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, outFile.Remove(outFile.Length - 4) + " " + LayoutManager.Current.CurrentLayout + ".dwf"));
  87.                }
  88.                else if (this.cboPrinter.SelectedItem.ToString().ToUpper().Contains("PDF"))
  89.                {
  90.                    if (!this.cboPrinter.SelectedItem.ToString().ToUpper().StartsWith("DWG TO PDF"))
  91.                    {
  92.                        buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  93.                    }
  94.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, outFile.Remove(outFile.Length - 4) + " " + LayoutManager.Current.CurrentLayout + ".pdf"));
  95.                }
  96.                else
  97.                {
  98.                    buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  99.                }
  100.                // save changes to page setup
  101.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, "N"));
  102.                // proceed with plot
  103.                buffer.Add(new Autodesk.AutoCAD.DatabaseServices.TypedValue(RTSTR, UTIL.showRscText(rm.GetString("acYES"))));
  104.  
  105.                // No error message but not working
  106.                //acedCmd(buffer.UnmanagedObject);
  107.  
  108.                // Both not working, error message
  109.                //doc.Editor.Command(buffer.UnmanagedObject);
  110.                doc.Editor.CommandAsync(buffer.UnmanagedObject);
  111.            }
  112.        }


Jeff_M

  • King Gator
  • Posts: 3881
  • C3D user & customizer
Re: acedCmd with Civil 3D 2017
« Reply #5 on: April 12, 2017, 02:03:46 pm »
Heh, well I learned something here.

While my app appeared to work fine and without error, I found that the one thing I was using the acedCmd() call for was not being executed. As latour_g noted, it didn't error, but it didn't do anything either. In my case, all it was doing was calling the BLOCKICON command to update old block definitions so I could show the icon on a form. It's not a command I use very often so had not noticed that no icon was being displayed. Changing it to ed.Command("_.BLOCKICON", blockname); fixed the issue.

latour_g, the new method requires the actual input as if you were typing it into the command line, not a ResultBuffer.

latour_g

  • Newt
  • Posts: 109
Re: acedCmd with Civil 3D 2017
« Reply #6 on: April 12, 2017, 02:47:14 pm »
You are right Jeff_M, thank you so much both !