Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Switch block
« Last post by latour_g on Today at 09:40:26 am »
Thanks so much it's working fine !
2
I've updated my last posted animated gif... Added lower 3DSOLIDs parts around cubes-objects... I think that it's now prettier and theswamp managed to upload gif in 640x512 resolution so now it little bigger (better)...

Regards, M.R.
3
Hi,

There is no built-in method for combining / concatenating two ObjectIdCollections.
For my part, I avoid using ObjectIdCollection except when the AutoCAD API requires it.
Generic collections (List <Objectid>, HashSet <ObjectId>, ...) are more powerful and more flexible.

You can create an extension method to mimic the List<T>.AddRange() method:
Code - C#: [Select]
  1.    public static class Extension
  2.    {
  3.        public static void AddRange(this ObjectIdCollection ids, ObjectIdCollection otherIds)
  4.        {
  5.            foreach (ObjectId id in otherIds) ids.Add(id);
  6.        }
  7.    }

By my side, I'd rather use Linq extension methods which return a new IEnumerable<ObjectId> so that the original collections remain unchanged.
Code - C#: [Select]
  1.    public static class Extension
  2.    {
  3.        public static IEnumerable<ObjectId> Concat(this ObjectIdCollection ids, IEnumerable<ObjectId> otherIds)
  4.        {
  5.            return ids.Cast<ObjectId>().Concat(otherIds);
  6.        }
  7.  
  8.        public static IEnumerable<ObjectId> Concat(this ObjectIdCollection ids, ObjectIdCollection otherIds)
  9.        {
  10.            return ids.Concat(otherIds.Cast<ObjectId>());
  11.        }
  12.    }

Then, if needed, you can easily convert the returned IEnumerable<objectId> into a concrete collection:

Code - C#: [Select]
  1. List<ObjectId> ids3 = ids1.Concat(ids2).ToList();

Code - C#: [Select]
  1. ObjectIdCollection ids4 = new ObjectIdCollection(ids1.Concat(ids2).ToArray());
4
Want to combine two ObjectIdCollections ... only what to iterate through each objectid and add to the second collection? Suppose I could create lists but just wondering more out of curiosity than anything. 

Thanks!
5
.NET / Re: Check if Nested or Not
« Last post by Area51Visitor on August 15, 2017, 09:37:36 pm »
Thanks!
6
.NET / Re: Switch block
« Last post by gile on August 15, 2017, 06:35:55 pm »
Hi;

The TransformBy() method works on a block and its attributes references.

Try replacing:
Code - C#: [Select]
  1.                    Point3d position1 = br1.Position;
  2.                    Point3d position2 = br2.Position;
  3.                    double rotation1 = br1.Rotation;
  4.                    double rotation2 = br2.Rotation;
  5.  
  6.                    br1.Position = position2;
  7.                    br2.Position = position1;
  8.  
  9.                    br1.Rotation = rotation2;
  10.                    br2.Rotation = rotation1;

with:
Code - C#: [Select]
  1.                    Matrix3d xform1 = br1.BlockTransform;
  2.                    Matrix3d xform2 = br2.BlockTransform;
  3.  
  4.                    br1.TransformBy(xform2 * xform1.Inverse());
  5.                    br2.TransformBy(xform1 * xform2.Inverse());
7
.NET / Switch block
« Last post by latour_g on August 15, 2017, 04:19:20 pm »
Hi,
I want to be able to switch two blocks.  The user select the first block and then the second block.  After that I switch the position and rotation of those two blocks.  It's working fine except for the attributes, they stay in place.  Is there an easy way to make them follow the new position of the block ? Or I have to find a way to calculate the displacement of the block and apply it to the attributes ?

This is what I have so far, pretty simple :

Code - C++: [Select]
  1. private void btnCopyBlk_Click(object sender, EventArgs e)
  2.        {
  3.            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
  4.            Editor ed = doc.Editor;
  5.            Database db = doc.Database;
  6.  
  7.            PromptEntityOptions peo1 = new PromptEntityOptions("Select first block: \n");
  8.            peo1.SetRejectMessage(MB.rmM.GetString("SelNoBlock"));
  9.            peo1.AllowNone = false;
  10.            peo1.AddAllowedClass(typeof(BlockReference), false);
  11.            PromptEntityResult per1 = ed.GetEntity(peo1);
  12.            if (per1.Status != PromptStatus.OK) return;
  13.            if (per1.ObjectId == ObjectId.Null) return;
  14.  
  15.            PromptEntityOptions peo2 = new PromptEntityOptions("Select second block: \n");
  16.            peo2.SetRejectMessage(MB.rmM.GetString("SelNoBlock"));
  17.            peo2.AllowNone = false;
  18.            peo2.AddAllowedClass(typeof(BlockReference), false);
  19.            PromptEntityResult per2 = ed.GetEntity(peo2);
  20.            if (per2.Status != PromptStatus.OK) return;
  21.            if (per2.ObjectId == ObjectId.Null) return;
  22.  
  23.            using (doc.LockDocument())
  24.            {
  25.                using (Transaction tr = db.TransactionManager.StartTransaction())
  26.                {
  27.                    BlockReference br1 = (BlockReference)tr.GetObject(per1.ObjectId, OpenMode.ForWrite);
  28.                    BlockReference br2 = (BlockReference)tr.GetObject(per2.ObjectId, OpenMode.ForWrite);
  29.  
  30.                    Point3d position1 = br1.Position;
  31.                    Point3d position2 = br2.Position;
  32.                    double rotation1 = br1.Rotation;
  33.                    double rotation2 = br2.Rotation;
  34.  
  35.                    br1.Position = position2;
  36.                    br2.Position = position1;
  37.  
  38.                    br1.Rotation = rotation2;
  39.                    br2.Rotation = rotation1;
  40.  
  41.                    tr.Commit();
  42.                }
  43.            }
  44.        }
8
AutoLISP (Vanilla / Visual) / Re: Please Help!!! on this Lisp
« Last post by cmwade77 on August 15, 2017, 12:54:01 pm »
To my knowledge this can't be done purely in LISP, you will basically need your routine to create a SCRIPT file, run it, then the SCRIPT file will need to run another LISP routine to delete the script file.

I could be wrong, but this is my understanding on how this all works.
9
AutoLISP (Vanilla / Visual) / Please Help!!! on this Lisp
« Last post by Hrishikesh on August 15, 2017, 03:35:40 am »
Hello community...
I am facing problem to use "REVERT (Express Tool)" command in my Autocad.
So I wrote a lisp which works like Revert. It works good till open same drawing & close previous copy of drawing but I stuck at this point "How to activate newly opened copy?
Can you please help me on this?
Thanks in advance...
Code - Auto/Visual Lisp: [Select]
  1. (defun c:REOPEN (/ Dwgname Readonly)
  2. (command "QSAVE")
  3. (setq Dwgname (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))
  4.           Dwgname
  5.           (if Readonly
  6.            :vlax-true
  7.            :vlax-false
  8.           )
  9. )
  10. (command "close" "Y")
  11. )
  12.  
10
.NET / Re: Check if Nested or Not
« Last post by Jeff H on August 15, 2017, 01:42:43 am »
Not sure I follow exactly what your asking and why you need to prompt for a point near it but here is an example where command prompts for selecting an object in an xref then opens the xrefs and zooms to it.

It checks the ObjectId.Database.UnmangedObject matches the current Database.UnmanagedObject.
Code - C#: [Select]
  1.        private static Handle? hnd = null;
  2.        [CommandMethod("zoomxref")]
  3.        public void zoomxref()
  4.        {
  5.            hnd = null;
  6.            var pneo = new PromptNestedEntityOptions("\nSelect xref object");
  7.            var pner = Ed.GetNestedEntity(pneo);
  8.            if (pner.Status != PromptStatus.OK)
  9.            {
  10.                return;
  11.            }
  12.  
  13.            var id = pner.ObjectId;
  14.            if (id.Database.UnmanagedObject == Db.UnmanagedObject)
  15.            {
  16.                Ed.WriteLine("Select xref object");
  17.                return;
  18.            }
  19.  
  20.            foreach (ObjectId conId in pner.GetContainers())
  21.            {
  22.                if (conId.Database.UnmanagedObject == pner.ObjectId.Database.UnmanagedObject)
  23.                {
  24.                    id = conId;
  25.                }
  26.  
  27.            }
  28.  
  29.            using (Transaction trx = Doc.TransactionManager.StartTransaction())
  30.            {
  31.                var ent = id.GetEntity();
  32.                hnd = ent.Handle;
  33.                trx.Commit();
  34.            }
  35.  
  36.            var doc = Application.DocumentManager.Open(pner.ObjectId.Database.Filename, false);
  37.            doc.SendStringToExecute("zoomxrefobject ", true, false, false);
  38.  
  39.        }
  40.  
  41.  
  42.        [CommandMethod("zoomxrefobject", CommandFlags.NoHistory)]
  43.        public void zoomxrefobject()
  44.        {
  45.            if (!hnd.HasValue) return;
  46.            var id = Db.GetObjectId(false, (Handle)hnd, 0);
  47.            var ss = SelectionSet.FromObjectIds(new ObjectId[] { id });
  48.            Ed.Command("_Zoom", "_Object", ss, "");
  49.        }
  50.  
  51.  
  52.  
Pages: [1] 2 3 ... 10