Author Topic: Reset document  (Read 2437 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Reset document
« on: August 25, 2011, 08:55:30 PM »
I wrote a small function to get blocks from our library.
1) browse to the blocks library and open the file to see if it's the right on.
2) Close the drawing and a messagebox comes up asking if you want to insert the dwg.

I could insert the drawing to the database  but  never get the insert/drag to work. I messed with CommandFlags.Session and lock but nothing worked. If not a crash I would get a Cancel from the drag.
Finally I tried a getpoint to see if that would cancel too and it did but the insert/drag suddenly works fine. There must be something that needs resetting, any ideas??
Code: [Select]
        [CommandMethod("Library")]//,CommandFlags.Session )]
        public static void Library()
        {
            string sPath = Util.Get.LibraryPath();
            OpenFileDialog openFileDia = new OpenFileDialog();
            string sFile = "";
            openFileDia.InitialDirectory = sPath + "Hardware\\";
            openFileDia.Filter = "Drawing (*.dwg)|*.dwg|All files (*.*)|*.*";

            openFileDia.Multiselect = false;
            openFileDia.RestoreDirectory = true;
            if (openFileDia.ShowDialog() == DialogResult.OK)
            {
                sFile = @openFileDia.FileName;
            }
            openFileDia.Dispose();
            if (string.IsNullOrEmpty(sFile)) return;
            string sBlock=Path.GetFileName(sFile);;
            DocumentCollection docs = acadApp.DocumentManager;
            Document docBlock = docs.Open(sFile);
            docs.MdiActiveDocument = docBlock;
            sBlock = Path.GetFileName(sFile);
            sBlock = sBlock.Replace(".dwg", "");
           
            string msg = "Would you like to insert the drawing " + sBlock + " as a block?";
            DialogResult res = MessageBox.Show(msg,"Find block", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (res != DialogResult.Yes) return;
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            PromptPointResult per = doc.Editor.GetPoint("");/////////////what the hayseed???????
//////without this the insert block jig cancels
            ObjectId BlockId = InsertDrawing(sBlock, sFile);
            if(BlockId!=ObjectId.Null) JigNew.InsertBlockJiggy.Insert(BlockId, false, "", 1);

        }//end Library
This code cant be run as I haven't included all the stuff but you can see what's happening.

kaefer

  • Guest
Re: Reset document
« Reply #1 on: August 26, 2011, 07:59:03 AM »
My favourite pastime: reverse error engineering. Didn't work here, that is, my code works as intended, so where did I go wrong?
Except by using the wrong language and skipping the jig part...

Code: [Select]
[<CommandMethod("DIATEST", CommandFlags.Session)>]
let diatest() =

    let fstDoc = acadApp.DocumentManager.MdiActiveDocument
   
    use openFileDia =
        new OpenFileDialog(
            Filter = "Drawing (*.dwg)|*.dwg|All files (*.*)|*.*",
            Multiselect = false,
            RestoreDirectory = true )

    if  openFileDia.ShowDialog() = DialogResult.OK &&
        not(System.String.IsNullOrEmpty openFileDia.FileName) then
       
        let docs = acadApp.DocumentManager
        let sndDoc = docs.Open(openFileDia.FileName, true)
        docs.MdiActiveDocument <- sndDoc

        let sBlock = System.IO.Path.GetFileNameWithoutExtension openFileDia.FileName
        let msg = "Would you like to insert the drawing " + sBlock + " as a block?"
       
        let res =
            MessageBox.Show(
                msg, "Find block", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 )
        if res = DialogResult.Yes then

            docs.MdiActiveDocument <- fstDoc
            use doclock = fstDoc.LockDocument()
           
            let oid =
                fstDoc.Database.Insert(
                    SymbolUtilityServices.BlockModelSpaceName,
                    sBlock,
                    sndDoc.Database,
                    true )
            if not oid.IsNull then
                let pt0 = ref Point3d.Origin

                use tr = fstDoc.Database.TransactionManager.StartTransaction()
                let cspace =
                    tr.GetObject(fstDoc.Database.CurrentSpaceId, OpenMode.ForWrite)
                        :?> BlockTableRecord
                let insert = new BlockReference(Point3d.Origin, oid)
                cspace.AppendEntity insert |> ignore
                tr.AddNewlyCreatedDBObject(insert, true)
                let sset = SelectionSet.FromObjectIds[| insert.ObjectId |]
                let ppr =
                    fstDoc.Editor.Drag(
                        sset, "Drag me",
                        fun pt (mat: Matrix3d byref) ->
                            if !pt0 = pt then SamplerStatus.NoChange
                            else
                                mat <- Matrix3d.Displacement(pt - !pt0)
                                SamplerStatus.OK )
                if ppr.Status = PromptStatus.OK then
                    insert.Position <- ppr.Value
                else
                    insert.Erase()
                tr.Commit()


Bryco

  • Water Moccasin
  • Posts: 1883
Re: Reset document
« Reply #2 on: August 26, 2011, 02:00:52 PM »
Thanks Kaefer.  I had tried that way ( CommandFlags.Session)  but I didn't like the way you can't zoom or pan in the open block dwg as the messagebox is modal. However it is probably a better way and works fine if I save all the dwgs w/ zoom extents.

Below gives the same Cancel after get point. But it's probably not worth persuing this kind of method anyway.
Code: [Select]
        public static void Library(string sFile)
        {           
            sFile = @"I:\0001 DesignPro\Library\Hardware\01NewHardware\bocaSection.dwg";
            string sBlock = Path.GetFileNameWithoutExtension(sFile);
            DocumentCollection docs = acadApp.DocumentManager;
            Document docBlock = docs.Open(sFile);
            docs.MdiActiveDocument = docBlock;
 
            string msg = "Would you like to insert the drawing " + sBlock + " as a block?";
            DialogResult res = MessageBox.Show(msg, "Find block", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            if (res != DialogResult.Yes) return;

            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            PromptPointResult per = doc.Editor.GetPoint("p");
        }//end Library