.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB.Net support for AutoCAD Electrical

3 REPLIES 3
Reply
Message 1 of 4
pvvss
1323 Views, 3 Replies

VB.Net support for AutoCAD Electrical

Please confirm whether AutoCAD Electrical 2013  & AutoCAD Electrical 2011 supports the VB.NET applications.

We want to create an application on VB.NET to automate the electrical wiring diagrams.

 

Please forward the supporting documents for the above for reference.Regards,

Prasanth

3 REPLIES 3
Message 2 of 4
Keith.Brown
in reply to: pvvss

Yes you can customize AutoCAD Electrical using any .net language.  AutoCAD has a full featured API that can be used for AutoCAD Electrical.  You can find more information here.  http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=19118898

Message 3 of 4
ajfehr
in reply to: Keith.Brown

I'd like to know where on that page you linked to that you found information about autocad electrical because I found exactly nothing explicitly for autocad electrical.
Message 4 of 4
Keith.Brown
in reply to: ajfehr

The link provided was to the General AutoDesk API page.

 

For specific help about Electrical i believe that you can click the help drop down menu in AutoCAD Electrical , choose additional resources and then API help.  Make sure you have a drawing open to see this option.

 

After looking at the help itself it looks like that in using the vb.net and c# you are really just invoking LISP functions.  Here is the c# example from the help file.  It is the only c# example available.

 

You can also open the help file directly at this location.  C:\Program Files\Autodesk\AutoCAD 2016\Acade\Help\en-US\Help.  The link will change depending on your release version.

 

namespace SampleCodes
{
  public class LispUtil
  {
    public const Int32 RTREAL = 5001;
    public const Int32 RTSHORT = 5003;
    public const Int32 RTSTR = 5005;
    public const Int32 RTLONG = 5010;
    public const Int32 RTENAME = 5006;

    // Import the acedInvoke function definition
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
    extern static private int acedInvoke(IntPtr args, out IntPtr result);

    /////////////////////////////////////////////////////////////////////
    // Function: InvokeLispFunc
    // Description: This function calls the acedInvoke function.
    // Parameters: args - Data structure containing the Lisp function name and arguments to be passed into the function
    //             stat - An int to store function execution status code
    // Return Value: returns from lisp if successful, otherwise, return null
    /////////////////////////////////////////////////////////////////////
    public static ResultBuffer InvokeLispFunc(ResultBuffer args, ref int stat)
    {
      IntPtr rb = IntPtr.Zero;
      stat = acedInvoke(args.UnmanagedObject, out rb);
      if (stat == (int)PromptStatus.OK)
        return (ResultBuffer)Autodesk.AutoCAD.Runtime.DisposableWrapper.Create(typeof(ResultBuffer), rb, true);
      return null;
    }
  }

  public class SampleMainClass
  {

    /////////////////////////////////////////////////////////////////////
    // Function: ARXWNByColorCMD
    // Description: This function is the starting point for the
    //              ARXWnByColor command.
    // Parameters: None
    // Return Value: void
    /////////////////////////////////////////////////////////////////////
    void ARXWNByColorCMD()
    {
      // Select an entity
      Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
      ObjectId objId;
      try
      {
        PromptEntityResult prEntityRes = ed.GetEntity("Select a wire. \n");
        if (prEntityRes.Status != PromptStatus.OK)
        {
          ed.WriteMessage("Error in getting an entity\n");
          return;
        }
        objId = prEntityRes.ObjectId;
        if (objId == null)
          return;

        { // Obtained entity, let's process it
          String entHdl = objId.Handle.ToString(); // get the handle of the object
          String WNum = "", Suffix = "";

          // Get the text and wire number block for this wire
          // (Hopefully it is a wire entity that has a wire number on it)
          if (LispGetWireNumTextAndBlock(entHdl, ref WNum))
          {
            // Now get the layer of the line/wire
            String strWireLayer = String.Empty;
            {
              Document doc = Application.DocumentManager.MdiActiveDocument;
              Transaction tr = doc.TransactionManager.StartTransaction();
              using (tr)
              {
                Entity wireEnt = (Entity)tr.GetObject(objId, OpenMode.ForRead);
                strWireLayer = wireEnt.Layer; // try to get layer name the wire is on
              }
            }

            if (strWireLayer.Length > 0)
            {
              // Compare the layer name to determine the correct
              // wire number suffix
              if (strWireLayer.Contains("RED"))
                Suffix = "RD";
              else if (strWireLayer.Contains("GRN"))
                Suffix = "GN";
              else if (strWireLayer.Contains("WHT"))
                Suffix = "WT";
              else if (strWireLayer.Contains("BLK"))
                Suffix = "BK";
              else if (strWireLayer.Contains("YEL"))
                Suffix = "YL";
            }
            // If we have a suffix, then decide if we need to add it to the wire.
            if (Suffix.Length > 0)
            {
              // If the suffix is not on the wire number then add it.
              if (!WNum.EndsWith(Suffix))
              {
                // Not found, so add the suffix
                WNum += "-";
                WNum += Suffix;
                // Now place it on the wire text block
                LispPutWireNumText(objId, WNum);
              }
              else // Suffix is on the wire already, so don't add
                ed.WriteMessage(" color suffix is already on the wire number.\n");
            }
            else
              ed.WriteMessage("No known color in layer name.\n");
          }
          else
            ed.WriteMessage("This is either not a wire entity or there is no wire number found.\n");
        }
      }
      catch(System.Exception ex)
      {
        ed.WriteMessage("Error : " + ex.Message);
      }
    }

    /////////////////////////////////////////////////////////////////////
    // Function: LispGetWireNumTextAndBlock
    // Description: This function calls the c:ace_get_wnum lisp function
    //              using the acedInvoke function.
    // Parameters: EntHdl - Wire entity handle to pass to LISP
    //             String - Wire num text pulled from wire entity in LISP
    //                      and filled in here.
    // Return Value: bool - true if passed, false if failed
    /////////////////////////////////////////////////////////////////////
    bool LispGetWireNumTextAndBlock(String EntHdl, ref String WNumText)
    {
      int stat = 0;
      ResultBuffer resBuf = new ResultBuffer();
      resBuf.Add(new TypedValue(LispUtil.RTSTR, /*MSG0*/"c:ace_get_wnum")); //Lisp function to call
      resBuf.Add(new TypedValue(LispUtil.RTSTR, EntHdl)); // Handle of wire
      ResultBuffer ret = LispUtil.InvokeLispFunc(resBuf, ref stat);
      if (ret == null) return false;

      TypedValue[] rbChain = ret.AsArray();
      if (rbChain.Length >= 2)
      {
        if (rbChain[0].TypeCode == LispUtil.RTSTR)
          WNumText = (String) rbChain[0].Value;
      }

      return (WNumText.Length > 0);
    }

    /////////////////////////////////////////////////////////////////////
    // Function: LispPutWireNumText
    // Description: This function calls the c:wd_putwn LISP function
    //              using the acedInvoke function.
    // Parameters: ObjectId - Wire entity name to pass to LISP
    //             String - Wire num text to pass to LISP.  This will be
    //                        the value that the wirenumber is set to.
    // Return Value: bool - true if passed, false if failed
    /////////////////////////////////////////////////////////////////////
    bool LispPutWireNumText(ObjectId ObjId, String WNum)
    {
      int stat = 0;
      bool bOK = true;
      ResultBuffer resBuf = new ResultBuffer();
      resBuf.Add(new TypedValue(LispUtil.RTSTR, /*MSG0*/"c:wd_putwn")); // Lisp function to call
      resBuf.Add(new TypedValue(LispUtil.RTENAME, ObjId)); // object id
      resBuf.Add(new TypedValue(LispUtil.RTSTR, WNum));    // new wire number
      ResultBuffer ret = LispUtil.InvokeLispFunc(resBuf, ref stat);
      if (ret == null) return false;

      TypedValue[] rbChain = ret.AsArray();
      if (rbChain.Length == 0)
      {
        bOK = false;
      }
      return bOK;
    }
  }
}

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost