public PlineJig(Matrix3d ucs) : base(new Polyline()) { // Create a point collection to store our vertices m_pts = new Point3dCollection(); // Create a temporary plane, to help with calcs Point3d origin = new Point3d(0, 0, 0); Vector3d normal = new Vector3d(0, 0, 1); normal = normal.TransformBy(ucs); m_plane = new Plane(origin, normal); // Create polyline, set defaults, add dummy vertex Polyline pline = Entity as Polyline; pline.SetDatabaseDefaults(); pline.Normal = normal; //makes sure the layer exists then switches over to the layer GeneralMenu.CreateLayer("Match", 134, "ByLayer", false); pline.Layer = "Match"; //makes sure the linetype exists then assigns the linetype GeneralMenu.LoadLinetype("PHANTOM"); pline.Linetype = "PHANTOM"; pline.AddVertexAt(0, new Point2d(0, 0), 0, .0625, .0625); //Application.DocumentManager.MdiActiveDocument.Database.Orthomode = true; }
public static void InsertLayer() { Document acDoc = Application.DocumentManager.MdiActiveDocument; PromptStringOptions pStrOpts = new PromptStringOptions(""); //from the menu macro command gets the filename of the text file to use PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts); //concatenates the full file path string FileName = MyPlugin.GetRoot() + @"CSV\" + pStrRes.StringResult; //gets each line in the text file and adds each line to an element in a string array string[] fileLines = SplitFileByLine(FileName); //parses each element in individual line to get the variables we need for (int index = 0; index < fileLines.Length; index++) { string[] items = fileLines[index].Trim().Split(','); if (items.Length > 1) { string Name = items[0]; short Color = short.Parse(items[1]); string LineType = items[2]; //makes sure the linetype exists GeneralMenu.LoadLinetype(LineType); //creates the layer GeneralMenu.CreateLayer(Name, Color, LineType, false); acDoc.Editor.WriteMessage("\n " + Name + " Layer created"); } } }
public static void RevisionCloudCommand() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; //ensures the REV layer exists in the drawing, if not adds it GeneralMenu.CreateLayer("REV", 91, "Continuous", true); using (Transaction acTrans = db.TransactionManager.StartTransaction()) { //finds and makes the REV layer the current layer for the drawing LayerTable acLyrTbl = acTrans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable; db.Clayer = acLyrTbl["REV"]; acTrans.Commit(); } //user inserts the triangle thingy Commands.BlockJigCmd(revtri, true); //get the current revision number from the title block string value = GetRevLetter(); //updates the attribute for ALL triangle block references in the drawing if (value != null) { UpdateAttributesInRevBlock("REVTRI.DWG", "LEVEL", value); } //user inserts the revision cloud doc.SendStringToExecute("REVCLOUD ", true, false, true); }
public void VALVEBREAK() { Document acDoc = Application.DocumentManager.MdiActiveDocument; PromptStringOptions pStrOpts = new PromptStringOptions(""); //getting string result from menu macro //this gets the relative file name and path from the root // replaced @ with \ for folder structure because you can't put a \ in an AutoCAD menu macro string PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts); string filepath = MyPlugin.GetRoot() + @"blocks\" + pStrRes.StringResult.Replace('@', '\\'); //another string result from the menu macro //this one will determine what layer the block will be inserted on pStrRes = acDoc.Editor.GetString(pStrOpts); string LayerName = pStrRes.StringResult; //checks to ensure the layer that the block is to be inserted on exists GeneralMenu.CreateLayer(LayerName, 7, "Continuous", false); InsertValveBlock.dostuff(filepath); }
public void MyPolyJig() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; // Get the current UCS, to pass to the Jig Matrix3d ucs = ed.CurrentUserCoordinateSystem; //ensures that the layer the object will be created on exists, if it doesn't creates it GeneralMenu.CreateLayer("DIM", 1, "Continuous", true); // Create our Jig object PlineJig jig = new PlineJig(ucs); // Loop to set the vertices directly on the polyline bool bSuccess = true; for (int i = 0; i < 2; i++) { PromptResult res = ed.Drag(jig); bSuccess = (res.Status == PromptStatus.OK); // A new point was added if (bSuccess) { jig.AddLatestVertex(); } } jig.RemoveLastVertex(); Ellipse el = InsertElipse(); //formula for calculating a polar point based on a base point, an angle, and the distance Point3d newpoint = new Point3d(el.Center.X + 0.04492187 * Math.Cos(angleA + 4.71238898), el.Center.Y + 0.04492187 * Math.Sin(angleA + 4.71238898), 0); jig.ReplaceOrigin(newpoint); MText tx = addText(); // If the jig completed successfully, add the polyline // Append entity Database db = doc.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = ((BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); btr.AppendEntity(jig.GetEntity()); btr.AppendEntity(el); btr.AppendEntity(tx); tr.AddNewlyCreatedDBObject(jig.GetEntity(), true); tr.AddNewlyCreatedDBObject(el, true); tr.AddNewlyCreatedDBObject(tx, true); tr.Commit(); } }
static public void BlockJigCmd(string strSourceBlockPath, string LayerName, bool displayAttEdit) { //same stuff Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; BlockTableRecord btr; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { string strSourceBlockName = Path.GetFileName(strSourceBlockPath); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); //if block already exists in drawing retrieve it, if not create if from external drawing if (bt.Has(strSourceBlockName)) { ObjectId id = bt[strSourceBlockName]; btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead, true, true); } else { BlockTableRecord btrSource = GeneralMenu.GetBlock(strSourceBlockName, strSourceBlockPath); if (btrSource == null) { return; } btr = (BlockTableRecord)tr.GetObject(btrSource.ObjectId, OpenMode.ForRead, true, true); } BlockTableRecord space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); // Block needs to be inserted to current space before // being able to append attribute to it BlockReference br = new BlockReference(new Point3d(), btr.ObjectId); GeneralMenu.CreateLayer(LayerName, false); br.Layer = LayerName; space.AppendEntity(br); tr.AddNewlyCreatedDBObject(br, true); Dictionary <ObjectId, AttInfo> attInfo = new Dictionary <ObjectId, AttInfo>(); if (btr.HasAttributeDefinitions) { foreach (ObjectId id in btr) { DBObject obj = tr.GetObject(id, OpenMode.ForRead); AttributeDefinition ad = obj as AttributeDefinition; if (ad != null && !ad.Constant) { AttributeReference ar = new AttributeReference(); ar.SetAttributeFromBlock(ad, br.BlockTransform); ar.Position = ad.Position.TransformBy(br.BlockTransform); if (ad.Justify != AttachmentPoint.BaseLeft) { ar.AlignmentPoint = ad.AlignmentPoint.TransformBy(br.BlockTransform); } if (ar.IsMTextAttribute) { ar.UpdateMTextAttribute(); } ar.TextString = ad.TextString; ObjectId arId = br.AttributeCollection.AppendAttribute(ar); tr.AddNewlyCreatedDBObject(ar, true); // Initialize our dictionary with the ObjectId of // the attribute reference + attribute definition info attInfo.Add(arId, new AttInfo(ad.Position, ad.AlignmentPoint, ad.Justify != AttachmentPoint.BaseLeft)); } } } // Run the jig BlockJig myJig = new BlockJig(tr, br, attInfo); if (myJig.Run() != PromptStatus.OK) { return; } if (btr.HasAttributeDefinitions && displayAttEdit) { doc.SendStringToExecute("_.EATTEDIT l ", true, false, true); //CommandLine.Command("_.EATTEDIT", br.ObjectId); } // Commit changes if user accepted, otherwise discard tr.Commit(); } }