.NET

.NET

Reply
Contributor
dreamwtx
Posts: 12
Registered: ‎03-07-2012
Message 1 of 9 (617 Views)

How to pass parameter in interface to the programe of .dll file using c#?

617 Views, 8 Replies
03-14-2012 11:51 PM

I  have developped  the  interface using c#,i want to turn off or on the layer according to the parameter in interface.

now i have carried out turn off or on a specified layer using a .dll file. but how i can connect the parameter in interface to the program in .dll file .thanks

Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 2 of 9 (596 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-15-2012 07:33 AM in reply to: dreamwtx

What interface did you develop?  Is it a ribbon? tool palette? Is it an external program?

 

-Mark

Contributor
dreamwtx
Posts: 12
Registered: ‎03-07-2012
Message 3 of 9 (578 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-15-2012 06:06 PM in reply to: MarkPendergraft

MarkPendergraft wrote:

What interface did you develop?  Is it a ribbon? tool palette? Is it an external program?

 

-Mark

 

 

yes ,it is anexternal program. the interface is developped using c#.


 

Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 4 of 9 (574 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-15-2012 08:00 PM in reply to: dreamwtx

If it's an external program, then you need to use the COM API to access functionality inside autocad from your external program.

 

Take a look here for someone with the same idea:

 

http://forums.autodesk.com/t5/NET/Stand-alone-applications/m-p/2513610/highlight/true#M15108

 

You can also search for stand alone applications.  There has been a lot of discussion on this type of thing, but it's not something I've ever explored.

 

-Mark

 

Contributor
dreamwtx
Posts: 12
Registered: ‎03-07-2012
Message 5 of 9 (568 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-15-2012 10:07 PM in reply to: MarkPendergraft

Thank you

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 9 (563 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-15-2012 10:21 PM in reply to: dreamwtx

Show us your code you get started with

maybe it will be more effective

 

~"J"~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
dreamwtx
Posts: 12
Registered: ‎03-07-2012
Message 7 of 9 (555 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-16-2012 12:48 AM in reply to: Hallex
  1. 未命名.jpg

  2. using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using Autodesk.AutoCAD.Interop;
    using Autodesk.AutoCAD.Interop.Common;
    using Autodesk.AutoCAD;
    using System.IO;
    //using Autodesk.AutoCAD.ApplicationServices;
    //using Autodesk.AutoCAD.DatabaseServices;
    //using Autodesk.AutoCAD.Runtime;
    //using TurnLayerOff;

     

     

     

    namespace Demo
    {  
        public partial class Form1 : Form
        {
            private AcadApplication a;//声明AutoCAD对象
          
            public Form1()
            {
                InitializeComponent();
               
            }

            private void button1_Click(object sender, EventArgs e)
            {
                a = new AcadApplicationClass();
                a.Visible = true;
                string strFileName = "C:\\G4P4-S01.dwg";
                a.Application.Update();//更新显示
                a.Application.Documents.Open(strFileName, false, 1);
                //Autodesk.AutoCAD.Interop.AcadDocument aDocument;
                //Autodesk.AutoCAD.Interop.Common.AcadLayers acDoc;
                
          
                    
                //a.ActiveDocument.Layers.Item("IN_SWGEAR_CAB_USED").LayerOn=false;

                //AcadDocument acDocComObj;
                //acDocComObj = acAppComObj.ActiveDocument;

                // Optionally, load your assembly and start your command or if your assembly
                // is demandloaded, simply start the command of your in-process assembly.
               
                a.ActiveDocument.SendCommand("(command " + (char)34 + "NETLOAD" + (char)34 + " " +
                                        (char)34 + "c:/myapps/mycommands.dll" + (char)34 + ") ");
                TurnLayerOff.Class1.TurnLayerOff(textBox2.Text);
                a.ActiveDocument.SendCommand("TurnLayerOff");

  3.           

        TurnLayyerOff  is .dll file.but i can't pass textBox2.text to the ,dll file.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 8 of 9 (548 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-16-2012 02:49 AM in reply to: dreamwtx

You may want to use direct access to all

AutoCAD objects this way instead:

       {

            a = new AcadApplicationClass();
            a.Visible = true;
            string strFileName = @"C:\G4P4-S01.dwg";
            a.Application.Documents.Open(strFileName, false, 1);
            AcadApplication acad = (AcadApplication)a as AcadApplication;
            acad.WindowState = AcWindowState.acMax;
            AcadDocument adoc = (AcadDocument)acad.ActiveDocument as AcadDocument;
            AcadUtility acutil = (AcadUtility)adoc.Utility as AcadUtility;
            string layername = textBox2.Text;
            acutil.Prompt(string.Format("\nLAYER SELECTED\t{0}",layername));
            AcadLayers aclayers = (AcadLayers)adoc.Layers;
            AcadLayer aclayer = aclayers.Item(layername) as AcadLayer;
            if (aclayer == null)
            {
                MessageBox.Show("Layer \"{0}\" does not exist, try another layer name");
                this.textBox2.Select();
                this.textBox2.Text = string.Empty;
                return;
            }
            if (aclayer.ObjectID == adoc.ActiveLayer.ObjectID)
            {
                MessageBox.Show("This is active layer, program exiting...");
                return;
            }
            if (aclayer.LayerOn)
                aclayer.LayerOn = false;
            acutil.Prompt(string.Format("\n\tLAYER \"{0}\" IS OFF", layername));

        }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
dreamwtx
Posts: 12
Registered: ‎03-07-2012
Message 9 of 9 (495 Views)

Re: How to pass parameter in interface to the programe of .dll file using c#?

03-19-2012 08:59 PM in reply to: dreamwtx

there is an error  "HRESULT:0x80010001 (RPC_E_CALL_REJECTED"

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.