Author Topic: Keywords and dynamic block visibility  (Read 2242 times)

0 Members and 1 Guest are viewing this topic.

fixo

  • Guest
Keywords and dynamic block visibility
« on: May 10, 2009, 06:09:43 AM »
Hi, guys
I can't fix my problem entire the day, it's
driving me mad ...
What's wrong with my code snip?
At the first glance even thouh

Code: [Select]
        /// <summary>
        ///
        /// </summary>
        [CommandMethod("DBB", CommandFlags.UsePickSet)]
        public void ChangeDynBlock()
        {
            Document oDoc = AcadApp.DocumentManager.MdiActiveDocument;
           
            Editor ed = oDoc.Editor;
           
            using (DocumentLock dlock = oDoc.LockDocument(DocumentLockMode.Write, "", "DBB", false))
            {
                using (Database db = HostApplicationServices.WorkingDatabase)
                {
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
                           
                            PromptSelectionOptions pso = new PromptSelectionOptions();
                           
                            pso.SingleOnly = true;
                           
                            pso.MessageForRemoval = "\nWrong selection. Try again!";
                           
                            pso.MessageForAdding = "\nSelect block:";
                           
                            PromptSelectionResult pr = ed.GetSelection(pso);

                            if (pr == null)
                                return;

                            SelectionSet ss = pr.Value;
                           
                            ObjectId[] oids = ss.GetObjectIds();
                           
                            ObjectId id = oids[0];
                           
                            BlockReference bref = (BlockReference)trans.GetObject(id, OpenMode.ForRead);

                            DynamicBlockReferencePropertyCollection dpcoll = bref.DynamicBlockReferencePropertyCollection;

                            for (int n = 0; n < dpcoll.Count; n++)//iteration is just for the future programm
                            {
                                DynamicBlockReferenceProperty vizz = dpcoll[n];

                                switch (vizz.PropertyName.ToUpper())
                                {
                                    case "VISIBILITY":
                                       
                                        Object[] props = vizz.GetAllowedValues();

                                        PromptKeywordOptions pko = new PromptKeywordOptions("");

                                        for (int m = 0; m < props.Length; m++)
                                            pko.Keywords.Add(props[m].ToString());

                                        pko.Keywords.Default = props[0].ToString();
                                       
                                        pko.AllowArbitraryInput = true;
                                       
                                        pko.AllowNone = true;
                                       
                                        pko.Message = "\nChoose a visibility color ";// setup your message to suit
                                       
                                        pko.AppendKeywordsToMessage = true;
                                       
                                        PromptResult prr = ed.GetKeywords(pko);
                                       
                                        string typ = prr.StringResult.ToString();
                                       
                                        vizz.Value = typ;

                                        break;

                                }

                            }

                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            MessageBox.Show(ex.Message +
                                           "------------------------------------------" +
                                           ex.StackTrace);
                        }
                        trans.Commit();
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="tr"></param>
        /// <param name="blkref"></param>
        /// <returns></returns>
        public string EffectiveName(Transaction tr, BlockReference blkref)
        {
            if (blkref.IsDynamicBlock)
            {
                using (BlockTableRecord obj = (BlockTableRecord)
                   
                    tr.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead))
                   
                    return obj.Name;
            }
            return blkref.Name;
        }

~'J'~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Keywords and dynamic block visibility
« Reply #1 on: May 11, 2009, 11:17:46 AM »
I noticed that you didn't filter for just blocks.  I'm assuming that is just because this is in the early phase of development.

You might want to say what it is/isn't doing that you think it should/shouldn't be.  This way people will know which parts to look at more closely.  I don't use dynamic blocks, and haven't coded for them, so I'm not much help, so I'm just a spectator this time.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

fixo

  • Guest
Re: Keywords and dynamic block visibility
« Reply #2 on: May 11, 2009, 11:40:53 AM »
I noticed that you didn't filter for just blocks.  I'm assuming that is just because this is in the early phase of development.

You might want to say what it is/isn't doing that you think it should/shouldn't be.  This way people will know which parts to look at more closely.  I don't use dynamic blocks, and haven't coded for them, so I'm not much help, so I'm just a spectator this time.

Thanks Tim, that you have paid attention to mine post.
Pardon me, that you have spent the time for my problem.
I have just found out that a problem is in the AutoCAD, I have
reinstalled it and now all works just fine

Regards,

Oleg

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Keywords and dynamic block visibility
« Reply #3 on: May 11, 2009, 11:54:37 AM »
I noticed that you didn't filter for just blocks.  I'm assuming that is just because this is in the early phase of development.

You might want to say what it is/isn't doing that you think it should/shouldn't be.  This way people will know which parts to look at more closely.  I don't use dynamic blocks, and haven't coded for them, so I'm not much help, so I'm just a spectator this time.

Thanks Tim, that you have paid attention to mine post.
Pardon me, that you have spent the time for my problem.
I have just found out that a problem is in the AutoCAD, I have
reinstalled it and now all works just fine

Regards,

Oleg

Good to hear Oleg.  It wasn't a waste of time for me, as I get to see how someone works with dy blocks.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

fixo

  • Guest
Re: Keywords and dynamic block visibility
« Reply #4 on: May 11, 2009, 12:07:44 PM »
Glad you are always ready to help  :-)

Best regards

~'J'~