Jump to content

Add just created objects to the "previous" selectionset


Recommended Posts

Posted

Hi there!

I wrote a code that, from a selection, generates a polyline and a hatch for every object in the selection.

 

How can I make these objects in the selection when the program is ended?

 

For example:
1. I started my program

2. select the objects I want to evaluate
3. the program creates a polyline and a hatch for every object

4. done

Now if I use the command COPY or MOVE (or whatever) I want to select these new objects with the key P (previous) and not the selection I made at point 2 above.
 

Thanks for the help :)
Dennis

 

Posted

When you make a new object you can use SSADD to add to say a second selection set so use that one for your move. Hint (ssadd (entlast) ss2)

Posted

Hello BIGAL!
Unfortunately, I need something in c# :)
I added the tag in the question, sorry for not making that more clear :(


 

[CommandMethod("vs")]
        public void VerificaSovrapposizioni()
        {
            var TargetLayer = "DEST_LAYER";

            #region Get the current document and database

            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var db = doc.Database;

            #endregion

            using (var tr = db.TransactionManager.StartTransaction())
            {
                #region Open block table record model space

                var bt = (BlockTable) tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                var btr =
                    (BlockTableRecord) tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                #endregion

                // create new layer called "_sovrapposizioni"
                var layerName = "_sovrapposizioni";
                AddLayerIfNotExists(tr, db, layerName);

                // set the filter to select only polylines with the layer "_sovrapposizioni"
                var filter = new TypedValue[2];
                filter[0] = new TypedValue(0, "LWPOLYLINE");
                filter[1] = new TypedValue(8, TargetLayer);
                var sf = new SelectionFilter(filter);


                var res = ed.GetSelection(sf);
                if (res.Status == PromptStatus.OK)
                {
                    var ss = res.Value;
                    foreach (SelectedObject sObj in ss)
                        if (sObj != null)
                        {
                            var ent = (Polyline) tr.GetObject(sObj.ObjectId, OpenMode.ForRead);
                            var acObjIdColl = new ObjectIdCollection();
                            using (var acPoly = new Polyline())
                            {
                                acPoly.ColorIndex = 2;
                                acPoly.Layer = layerName;
                                for (var i = 0; i <= ent.NumberOfVertices - 1; i++)
                                    acPoly.AddVertexAt(i, ent.GetPoint2dAt(i), 0, 0, 0);

                                if (acPoly.NumberOfVertices < 4)
                                {
                                    var pt1 = ent.GetPoint2dAt(0);
                                    var pt2 = ent.GetPoint2dAt(1);
                                    var angle = GetAngle(pt1, pt2);
                                    var distance = GetDistance(pt1, pt2);
                                    var pt3X = ent.GetPoint2dAt(2).X - distance * Math.Cos(angle);
                                    var pt3Y = ent.GetPoint2dAt(2).Y - distance * Math.Sin(angle);

                                    acPoly.AddVertexAt(3, new Point2d(pt3X, pt3Y), 0, 0, 0);
                                }

                                acPoly.Closed = true;


                                btr.AppendEntity(acPoly);
                                tr.AddNewlyCreatedDBObject(acPoly, true);
                                acObjIdColl.Add(acPoly.ObjectId);
                            }

                            // Create the hatch object and append it to the block table record
                            using (var acHatch = new Hatch())
                            {
                                btr.AppendEntity(acHatch);
                                tr.AddNewlyCreatedDBObject(acHatch, true);
                                acHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
                                acHatch.Layer = layerName;
                                var color = Color.FromColorIndex(ColorMethod.ByAci, 1);
                                acHatch.Color = color;
                                // create a new transparency color for the hatch
                                acHatch.Transparency = new Transparency(50);
                                acHatch.Associative = true;
                                acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
                                acHatch.EvaluateHatch(true);
                            }
                        }
                }

                tr.Commit();
            }
        }


 

Posted

Same idea should work in c# must be an equivalent to ssadd as a C sub function.

Posted

I was able to add elements to the current selection, which is quite ok. (once you finish the program you find them already selected, without having to start a program and press P)


Still not able to figure out how to replace previous objects with those just created ones.

 

...
ObjectIdCollection IDs = new ObjectIdCollection();
...
IDs.Add(acPoly.ObjectId);
...
IDs.Add(acHatch.ObjectId);
...
ObjectId[] idArray = IDs.Cast<ObjectId>().ToArray();
ed.SetImpliedSelection(idArray);
...

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...