using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
namespace ITAT_Autocad
{
struct Formats
{
public string format;
public int height;
public int width;
public string orientation;
public string baseFormat;
public int multiplier;
};
public class yyy
{
public static void number()
{
Formats a1;
Formats a3;
Formats a4;
a1.format = "A1";
a1.height = 891;
a1.width = 1143;
a1.orientation = "h";
a1.multiplier = 1;
}
}
public class FormatsHandler
{
protected void DrawFormat()
{
throw new System.NotImplementedException();
}
protected void MakeBlock()
{
throw new System.NotImplementedException();
}
[CommandMethod("2title")]
public void DrawMainTitle()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
ObjectId blkRecId = ObjectId.Null;
if (!acBlkTbl.Has("MainTitle"))
{
BlockTableRecord acBlkTblRec = new BlockTableRecord();
acBlkTblRec.Name = "MainTitle";
// Set the insertion point for the block
acBlkTblRec.Origin = new Point3d(5, 5, 0);
acBlkTbl.UpgradeOpen();
acBlkTbl.Add(acBlkTblRec);
acTrans.AddNewlyCreatedDBObject(acBlkTblRec, true);
Polyline acPoly = new Polyline();
acPoly.SetDatabaseDefaults();
acPoly.AddVertexAt(0, new Point2d(0, 55), 0, 0, 0);
acPoly.AddVertexAt(1, new Point2d(-185, 55), 0, 0, 0);
acPoly.AddVertexAt(2, new Point2d(-185, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
Polyline acPoly1 = new Polyline();
acPoly1.SetDatabaseDefaults();
acPoly1.AddVertexAt(0, new Point2d(-178, 55), 0, 0, 0);
acPoly1.AddVertexAt(1, new Point2d(-178, 30), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly1);
acTrans.AddNewlyCreatedDBObject(acPoly1, true);
Polyline acPoly2 = new Polyline();
acPoly2.SetDatabaseDefaults();
acPoly2.AddVertexAt(0, new Point2d(-168, 55), 0, 0, 0);
acPoly2.AddVertexAt(1, new Point2d(-168, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly2);
acTrans.AddNewlyCreatedDBObject(acPoly2, true);
Polyline acPoly3 = new Polyline();
acPoly3.SetDatabaseDefaults();
acPoly3.AddVertexAt(0, new Point2d(-145, 55), 0, 0, 0);
acPoly3.AddVertexAt(1, new Point2d(-145, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly3);
acTrans.AddNewlyCreatedDBObject(acPoly3, true);
Polyline acPoly4 = new Polyline();
acPoly4.SetDatabaseDefaults();
acPoly4.AddVertexAt(0, new Point2d(-130, 55), 0, 0, 0);
acPoly4.AddVertexAt(1, new Point2d(-130, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly4);
acTrans.AddNewlyCreatedDBObject(acPoly4, true);
Polyline acPoly5 = new Polyline();
acPoly5.SetDatabaseDefaults();
acPoly5.AddVertexAt(0, new Point2d(-120, 55), 0, 0, 0);
acPoly5.AddVertexAt(1, new Point2d(-120, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly5);
acTrans.AddNewlyCreatedDBObject(acPoly5, true);
Polyline acPoly6 = new Polyline();
acPoly6.SetDatabaseDefaults();
acPoly6.AddVertexAt(0, new Point2d(-50, 40), 0, 0, 0);
acPoly6.AddVertexAt(1, new Point2d(-50, 0), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly6);
acTrans.AddNewlyCreatedDBObject(acPoly6, true);
Polyline acPoly7 = new Polyline();
acPoly7.SetDatabaseDefaults();
acPoly7.AddVertexAt(0, new Point2d(-35, 40), 0, 0, 0);
acPoly7.AddVertexAt(1, new Point2d(-35, 20), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly7);
acTrans.AddNewlyCreatedDBObject(acPoly7, true);
Polyline acPoly8 = new Polyline();
acPoly8.SetDatabaseDefaults();
acPoly8.AddVertexAt(0, new Point2d(-18, 40), 0, 0, 0);
acPoly8.AddVertexAt(1, new Point2d(-18, 20), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly8);
acTrans.AddNewlyCreatedDBObject(acPoly8, true);
Polyline acPoly9 = new Polyline();
acPoly9.SetDatabaseDefaults();
acPoly9.AddVertexAt(0, new Point2d(-30, 20), 0, 0, 0);
acPoly9.AddVertexAt(1, new Point2d(-30, 15), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly9);
acTrans.AddNewlyCreatedDBObject(acPoly9, true);
Polyline acPoly10 = new Polyline();
acPoly10.SetDatabaseDefaults();
acPoly10.AddVertexAt(0, new Point2d(-120, 40), 0, 0, 0);
acPoly10.AddVertexAt(1, new Point2d(-0, 40), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly10);
acTrans.AddNewlyCreatedDBObject(acPoly10, true);
Polyline acPoly11 = new Polyline();
acPoly11.SetDatabaseDefaults();
acPoly11.AddVertexAt(0, new Point2d(-120, 15), 0, 0, 0);
acPoly11.AddVertexAt(1, new Point2d(-0, 15), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly11);
acTrans.AddNewlyCreatedDBObject(acPoly11, true);
Polyline acPoly12 = new Polyline();
acPoly12.SetDatabaseDefaults();
acPoly12.AddVertexAt(0, new Point2d(-50, 35), 0, 0, 0);
acPoly12.AddVertexAt(1, new Point2d(-0, 35), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly12);
acTrans.AddNewlyCreatedDBObject(acPoly12, true);
Polyline acPoly13 = new Polyline();
acPoly13.SetDatabaseDefaults();
acPoly13.AddVertexAt(0, new Point2d(-50, 20), 0, 0, 0);
acPoly13.AddVertexAt(1, new Point2d(-0, 20), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly13);
acTrans.AddNewlyCreatedDBObject(acPoly13, true);
Polyline acPoly14 = new Polyline();
acPoly14.SetDatabaseDefaults();
acPoly14.AddVertexAt(0, new Point2d(-185, 50), 0, 0, 0);
acPoly14.AddVertexAt(1, new Point2d(-120, 50), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly14);
acTrans.AddNewlyCreatedDBObject(acPoly14, true);
Polyline acPoly15 = new Polyline();
acPoly15.SetDatabaseDefaults();
acPoly15.AddVertexAt(0, new Point2d(-185, 45), 0, 0, 0);
acPoly15.AddVertexAt(1, new Point2d(-120, 45), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly15);
acTrans.AddNewlyCreatedDBObject(acPoly15, true);
Polyline acPoly16 = new Polyline();
acPoly16.SetDatabaseDefaults();
acPoly16.AddVertexAt(0, new Point2d(-185, 40), 0, 0, 0);
acPoly16.AddVertexAt(1, new Point2d(-120, 40), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly16);
acTrans.AddNewlyCreatedDBObject(acPoly16, true);
Polyline acPoly17 = new Polyline();
acPoly17.SetDatabaseDefaults();
acPoly17.AddVertexAt(0, new Point2d(-185, 35), 0, 0, 0);
acPoly17.AddVertexAt(1, new Point2d(-120, 35), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly17);
acTrans.AddNewlyCreatedDBObject(acPoly17, true);
Polyline acPoly18 = new Polyline();
acPoly18.SetDatabaseDefaults();
acPoly18.AddVertexAt(0, new Point2d(-185, 30), 0, 0, 0);
acPoly18.AddVertexAt(1, new Point2d(-120, 30), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly18);
acTrans.AddNewlyCreatedDBObject(acPoly18, true);
Polyline acPoly19 = new Polyline();
acPoly19.SetDatabaseDefaults();
acPoly19.AddVertexAt(0, new Point2d(-185, 25), 0, 0, 0);
acPoly19.AddVertexAt(1, new Point2d(-120, 25), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly19);
acTrans.AddNewlyCreatedDBObject(acPoly19, true);
Polyline acPoly20 = new Polyline();
acPoly20.SetDatabaseDefaults();
acPoly20.AddVertexAt(0, new Point2d(-185, 20), 0, 0, 0);
acPoly20.AddVertexAt(1, new Point2d(-120, 20), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly20);
acTrans.AddNewlyCreatedDBObject(acPoly20, true);
Polyline acPoly21 = new Polyline();
acPoly21.SetDatabaseDefaults();
acPoly21.AddVertexAt(0, new Point2d(-185, 15), 0, 0, 0);
acPoly21.AddVertexAt(1, new Point2d(-120, 15), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly21);
acTrans.AddNewlyCreatedDBObject(acPoly21, true);
Polyline acPoly22 = new Polyline();
acPoly22.SetDatabaseDefaults();
acPoly22.AddVertexAt(0, new Point2d(-185, 10), 0, 0, 0);
acPoly22.AddVertexAt(1, new Point2d(-120, 10), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly22);
acTrans.AddNewlyCreatedDBObject(acPoly22, true);
Polyline acPoly23 = new Polyline();
acPoly23.SetDatabaseDefaults();
acPoly23.AddVertexAt(0, new Point2d(-185, 5), 0, 0, 0);
acPoly23.AddVertexAt(1, new Point2d(-120, 5), 0, 0, 0);
acBlkTblRec.AppendEntity(acPoly23);
acTrans.AddNewlyCreatedDBObject(acPoly23, true);
AttributeDefinition developer = new AttributeDefinition
{
Position = new Point3d(-170, 0, 0),
AlignmentPoint = new Point3d(-170, 0, 0),
AdjustAlignment(acBlkTbl.Database),
Prompt = "Developer",
Tag = "Developer",
TextString = "Гусаров",
WidthFactor = 0.7,
Height = 3.5,
Justify = AttachmentPoint.BottomLeft
};
acBlkTblRec.AppendEntity(developer);
acTrans.AddNewlyCreatedDBObject(developer, true);
blkRecId = acBlkTblRec.Id;
AttributeDefinition сhecker = new AttributeDefinition
{
Position = new Point3d(-162, 0, 0),
//AlignmentPoint=new Point3d(-167,45,0),
LockPositionInBlock=true,
Prompt = "Checker",
Tag = "Checker",
TextString = "Магненков",
WidthFactor = 0.7,
Height = 3.5,
Justify = AttachmentPoint.BottomLeft
};
acBlkTblRec.AppendEntity(сhecker);
acTrans.AddNewlyCreatedDBObject(сhecker, true);
blkRecId = acBlkTblRec.Id;
AttributeDefinition issuer = new AttributeDefinition
{
Position = new Point3d(-162, 0, 0),
//AlignmentPoint = new Point3d(-167, 40, 0),
Prompt = "Issuer",
Tag = "Issuer",
TextString = "Самоленков",
WidthFactor=0.7,
Height = 3.5,
Justify = AttachmentPoint.BottomLeft
};
acBlkTblRec.AppendEntity(issuer);
acTrans.AddNewlyCreatedDBObject(issuer, true);
blkRecId = acBlkTblRec.Id;
}
else
{
blkRecId = acBlkTbl["MainTitle"];
}
// Insert the block into the current space
if (blkRecId != ObjectId.Null)
{
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(blkRecId, OpenMode.ForRead) as BlockTableRecord;
// Create and insert the new block reference
BlockReference acBlkRef = new BlockReference(acBlkTblRec.Origin, blkRecId);
acBlkRef.SetDatabaseDefaults();
BlockTableRecord acCurSpaceBlkTblRec;
acCurSpaceBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
acCurSpaceBlkTblRec.AppendEntity(acBlkRef);
acTrans.AddNewlyCreatedDBObject(acBlkRef, true);
// Verify block table record has attribute definitions associated with it
if (acBlkTblRec.HasAttributeDefinitions)
{
// Add attributes from the block table record
foreach (ObjectId objID in acBlkTblRec)
{
DBObject dbObj = acTrans.GetObject(objID, OpenMode.ForRead) as DBObject;
if (dbObj is AttributeDefinition)
{
AttributeDefinition acAtt = dbObj as AttributeDefinition;
if (!acAtt.Constant)
{
AttributeReference acAttRef = new AttributeReference();
acAttRef.SetAttributeFromBlock(acAtt, acBlkRef.BlockTransform);
//acAttRef.Position = acAtt.Position.TransformBy(acBlkRef.BlockTransform);
acAttRef.TextString = acAtt.TextString;
acBlkRef.AttributeCollection.AppendAttribute(acAttRef);
acTrans.AddNewlyCreatedDBObject(acAttRef, true);
}
}
}
}
}
// Save the new object to the database
acTrans.Commit();
}
}
}
}