MastroLube Posted February 23 Share Posted February 23 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 2023-02-23-13-07-15.mp4 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 23 Share Posted February 23 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) Quote Link to comment Share on other sites More sharing options...
MastroLube Posted February 24 Author Share Posted February 24 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(); } } Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 25 Share Posted February 25 Same idea should work in c# must be an equivalent to ssadd as a C sub function. Quote Link to comment Share on other sites More sharing options...
MastroLube Posted March 1 Author Share Posted March 1 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); ... 2023-03-01-19-27-28.mp4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.