How to properly paste code?

James Maeding
edited August 2020 in Other

Here is what I get when pasting a c# function, its a nightmere.
What am I doing wrong?
I use the "code" button which adds the ''and lets me paste between the 's.
Brace yourself (with curly's if needed...):

`public static bool ImportBlkFromDwg(string fullpath) {
bool ret = false;
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
if (File.Exists(fullpath)) {
//was Database tmpDb = new Database(true, true);
Database tmpDb = new Database(false, true);
try {
tmpDb.ReadDwgFile(fullpath, FileShare.Read, true, ""); //bcad catches here

                using (var docLoc = doc.LockDocument()) {
                    string bName = Path.GetFileNameWithoutExtension(fullpath);

if ACAD

                    db.Insert(bName, tmpDb, true);

endif

if BCAD

                    db.Insert(bName, bName, tmpDb, true); //this is critical bName, bName, for bcad

endif

                }
                ret = true;
            }
            catch (System.Exception ex){
                Debug.Print(ex.Message);
            }
            finally {
                tmpDb.Dispose();
            }
        }
        return ret;
    }`

Comments

  • It's the Forum, it strips out some special characters , or treats them as MarkDown formatting options. In your case, it is treating # at the start of a line as a heading.

    Not ideal, but for code it is best to attach it to your post as a text file.

    Regards,
    Jason Bourhill
    BricsCAD V20 Ultimate
    CAD Concepts

  • hmm, notice how it treated the first half of code as just text, down to "tmpDb.ReadDwgFile(fullpath, FileShare.Read, true, ""); //bcad catches here"?
    Its not just the character switch, but other things that butcher the code.
    This really needs to be improved, code is fundamental to BCAD health and momentum.

  • It would be could if they adopted a form of Markdown suited to coding, such as GitHub Flavored Markdown.
    https://github.github.com/gfm/

    Regards,
    Jason Bourhill
    BricsCAD V20 Ultimate
    CAD Concepts

  • Roy Klein Gebbinck
    edited August 2020

    There is another way that works better:

    1. Paste the code in your post. In case of a code block make sure to leave blank line(s) above and below the code.
    2. Select the pasted code.
    3. Choose: Format > Code.
    4. If the code does not contain line ends, the code will be formatted as inline code: `abc`, else the code will be formatted as a code block: 4 spaces will be added to the start of each line.
  • James Maeding
    edited August 2020

    ok

    public static bool ImportBlkFromDwg(string fullpath) {
                bool ret = false;
                Document doc = AcAp.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                if (File.Exists(fullpath)) {
                    //was Database tmpDb = new Database(true, true);
                    Database tmpDb = new Database(false, true);
                    try {
                        tmpDb.ReadDwgFile(fullpath, FileShare.Read, true, "");
    
                        using (var docLoc = doc.LockDocument()) {
                            string bName = Path.GetFileNameWithoutExtension(fullpath);
    #if ACAD
                            db.Insert(bName, tmpDb, true);
    #endif
    #if BCAD
                            db.Insert(bName, bName, tmpDb, true); //this is critical bName, bName, for bcad
    #endif
                        }
                        ret = true;
                    }
                    catch (System.Exception ex){
                        Debug.Print(ex.Message);
                    }
                    finally {
                        tmpDb.Dispose();
                    }
                }
                return ret;
            }
    

    lets see. ahh, success!
    I think linux makes you smarter @Roy Klein Gebbinck , that is not fair.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Click one of the buttons on the top bar to get involved!