Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Differences .NET API between AutoCAD and BricsCAD

I wrote the list more than 60 differences between API. I use this list to forget nothing. And I found ways to solve some of these problems. I think this article can be interesting, for those who plan to port their .Net plug-ins. While I did not translate into English. I think that the code in C # is understandable without translation. But write to me if there is interest.
https://sites.google.com/site/avcprg/bricscad-net
I propose to leave in this thread a comment about the problems of porting plug-ins and your ways of solving them.

Comments

  • edited June 14

    You know the way to open and close a drawing in BRICSCAD .NET.

  • @abeltello said:
    You know the way to open and close a drawing in BRICSCAD .NET.

    Is this a question? I have not yet tried to open the document, but I load the drawing database without opening the document. This works perfectly.

  • @avc Thanks, its a question, but i need to open a drawing in BRICSCAD and I have been reading the documentation form .NET API in AUTOCAD and BRICSCAD it can not found the namespace in the same place.

  • You can use COM and a bit of reflection. Here is a sample

        /// <summary>
        /// Gets the specified property name.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="propName">Name of the property.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns>System.Object.</returns>
        public static object Get(this object obj, string propName, params object[] parameter)
        {
            return obj.GetType().InvokeMember(propName, BindingFlags.GetProperty, null, obj, parameter);
        }
    
        /// <summary>
        /// Sets the specified property name.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="propName">Name of the property.</param>
        /// <param name="parameter">The parameter.</param>
        public static void Set(this object obj, string propName, params object[] parameter)
        {
            obj.GetType().InvokeMember(propName, BindingFlags.SetProperty, null, obj, parameter);
        }
    
        /// <summary>
        /// Invokes the specified meth name.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="methName">Name of the meth.</param>
        /// <param name="parameter">The parameter.</param>
        /// <returns>System.Object.</returns>
        public static object Invoke(this object obj, string methName, params object[] parameter)
        {
            return obj.GetType().InvokeMember(methName, BindingFlags.OptionalParamBinding | BindingFlags.InvokeMethod, null, obj, parameter);
        }
    
    
        /// <summary>
        /// Opens the DWG.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="dwgPath">The DWG path.</param>
        public static void OpenDwg(this Document doc, string dwgPath)
        {
            var acad = Application.AcadApplication;
            var documents = acad.Get("Documents", null);
            if (documents != null)
            {
                var parameters = new List<object> {dwgPath, Type.Missing, Type.Missing};
                documents.Invoke("Open", parameters.ToArray());
            }
        }
    

    and the final call:

    Application.DocumentManager.MdiActiveDocument.OpenDwg(fname);

  • avcavc
    edited July 10

    @Daniele Piazza said:
    public static void OpenDwg(this Document doc, string dwgPath)
    and the final call:
    Application.DocumentManager.MdiActiveDocument.OpenDwg(fname);

    Your method OpenDwg is mistakenly primed to the helper for the document. But an existing document is not needed to open a new file. In AutoCAD there is an Open helper and it is assigned to DocumentCollection. And this is logical.
    public static Document Open(this DocumentCollection docCol, string FileName);
    and the final call:
    Document newdoc = Application.DocumentManager.Open(filename);
    In BricsCAD it is desirable to do the same, so get a new document.

    I will write down this BricsCAD API defect in my list.

    update:
    I tried this:

            #if BRICS
                public static Document Open(this DocumentCollection dc, string dwgPath) // вообще-то параметр dc не нужен, добавлен чисто для совместимости c AutoCAD
                {
                  var acad = Application.AcadApplication;
                  var documents = acad.Get("Documents", null);
                  if (documents != null)
                  {
                    var parameters = new List<object> { dwgPath, Type.Missing, Type.Missing };
                    return documents.Invoke("Open", parameters.ToArray()) as Document;
                  }
                  else return null;
                }
            #endif
    

    Document opened without problem but returned null :(

  • Yes, you are right about the poor design: just provided a code snippet.
    Extending DocumentCollection (DocumentManager) makes sense.

  • @avc said:
    I wrote the list more than 60 differences between API. I use this list to forget nothing. And I found ways to solve some of these problems. I think this article can be interesting, for those who plan to port their .Net plug-ins. While I did not translate into English. I think that the code in C # is understandable without translation. But write to me if there is interest.
    https://sites.google.com/site/avcprg/bricscad-net
    I propose to leave in this thread a comment about the problems of porting plug-ins and your ways of solving them.

    Thanks for putting this together

  • I continue to replenish my collection. There are already 75 problems with the BricsCAD API. In most cases I found and published solutions ... terrible crutches, but better than nothing.

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam