Create block from SAT file

Create block from SAT file

george1985
Collaborator Collaborator
446 Views
3 Replies
Message 1 of 4

Create block from SAT file

george1985
Collaborator
Collaborator

Hello,

I would like to create a block in Autocad, by using an ACIS (.sat) file.
I would like to do this with the use of Autocad NET API.

Is there a sample code I can follow?

 

I found an older example of how .sat file can be imported.

However, I am getting an error 'eNotInDatabase' on the line:
        tran.AddNewlyCreatedDBObject(ACISEntity, true);

 

Does anyone have any suggestion, how I can create a block from a .sat file?

Any help is appreciated. Thank you in advance.

0 Likes
Accepted solutions (1)
447 Views
3 Replies
Replies (3)
Message 2 of 4

george1985
Collaborator
Collaborator

Any help how to import a SAT file with autocad NET api?
Thank you in advance.

0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

 

The following example creates a new block definition in the current drawing by importing a .sat file.

       [CommandMethod("TEST")]
        public void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var fileDialog = new OpenFileDialog();
            fileDialog.Filter = "Acis file (*.sat)|*.sat";
            if (fileDialog.ShowDialog() != DialogResult.OK)
                return;
            string fileName = fileDialog.FileName;

            var promptResult = ed.GetString("\nEnter block name: ");
            if (promptResult.Status != PromptStatus.OK || string.IsNullOrWhiteSpace(promptResult.StringResult))
                return;
            string blockName = promptResult.StringResult;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (blockTable.Has(blockName))
                    return;
                tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
                var btr = new BlockTableRecord { Name = blockName };
                blockTable.Add(btr);
                tr.AddNewlyCreatedDBObject(btr, true);

                var acisObjects = Body.AcisIn(fileName);
                foreach (DBObject dBObject in acisObjects)
                {
                    if (dBObject is Entity)
                    {
                        btr.AppendEntity((Entity)dBObject);
                        tr.AddNewlyCreatedDBObject(dBObject, true);
                    }
                }
                tr.Commit();
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

george1985
Collaborator
Collaborator

Thank you very much @_gile !

I learned a lot from your code.
Brilliant code.

0 Likes