using Autodesk.AdvanceSteel.CADAccess; using Autodesk.AdvanceSteel.DocumentManagement; using Autodesk.AdvanceSteel.Runtime; using Autodesk.AdvanceSteel.Geometry; using Autodesk.AdvanceSteel.Modelling; using Autodesk.AdvanceSteel.Profiles; using Autodesk.AdvanceSteel.Runtime; using Autodesk.Windows; using System.Windows.Input; using System; using Autodesk.AdvanceSteel.CADLink.Database; using System.Collections.Generic; //using AstSTEELAUTOMATIONLib; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using System.Windows.Forms; using ASTransactionManager = Autodesk.AdvanceSteel.CADAccess.TransactionManager; using ASObjectId = Autodesk.AdvanceSteel.CADLink.Database.ObjectId; using ACDocument = Autodesk.AutoCAD.ApplicationServices.Document; using ACObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId; using ACDatabase = Autodesk.AutoCAD.DatabaseServices.Database; using ACPoint3d = Autodesk.AutoCAD.Geometry.Point3d; using ACTransaction = Autodesk.AutoCAD.DatabaseServices.Transaction; using ACMatrix3d = Autodesk.AutoCAD.Geometry.Matrix3d; using ASTransaction = Autodesk.AdvanceSteel.CADAccess.Transaction; namespace HelloWorld { public class MyRibbonCommandHandler : ICommand { public bool CanExecute(object parameter) { return true; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { RibbonCommandItem btn = parameter as RibbonCommandItem; if (btn != null) { if (btn.Id == "Create1") { Create(); } } } void LoadAndTranformDWGFile(ref string templateFilePath, ACPoint3d tranformPoint) { ACDocument doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; ACDatabase db = doc.Database; Editor ed = doc.Editor; try { db.ReadDwgFile( templateFilePath, System.IO.FileShare.Read, false, "" ); } catch (System.Exception) { ed.WriteMessage( "\nUnable to read drawing file." ); return; } try { ACTransaction tr = db.TransactionManager.StartTransaction(); using (tr) { List entityHandle = new List(); // Open the blocktable, get the modelspace BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); // Iterate through it, dumping objects foreach (ACObjectId objId in btr) { Entity ent = (Entity)tr.GetObject( objId, OpenMode.ForWrite ); ent.TransformBy(ACMatrix3d.Displacement(tranformPoint - ACPoint3d.Origin)); ent.ColorIndex = 2; Entity ent1 = ent.Clone() as Entity; ent1.TransformBy(ACMatrix3d.Displacement(new ACPoint3d(0, 150, 350) - ACPoint3d.Origin)); ent1.ColorIndex = 1; entityHandle.Add(ent1); } for (int i = 0; i < entityHandle.Count; i++) { Entity ent = entityHandle[i]; btr.AppendEntity(ent); tr.AddNewlyCreatedDBObject(ent, true); } tr.Commit(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } public void Create() { { DocumentManager.LockCurrentDocument(); string templateFilePath = "D:/Tread.dwg"; LoadAndTranformDWGFile(ref templateFilePath, new ACPoint3d(0, 100, 150)); DocumentManager.UnlockCurrentDocument(); } { DocumentManager.LockCurrentDocument(); StraightBeam beam; { ASTransaction tr = ASTransactionManager.StartTransaction(); //create column (vertical beam) with a default size ProfileName profName = new ProfileName(); ProfilesManager.GetProfTypeAsDefault("I", out profName); Point3d beamEnd = new Point3d(0, 0, 500); Point3d beamStart = Point3d.kOrigin; beam = new StraightBeam(profName.Name, beamStart, beamEnd, Vector3d.kXAxis); beam.WriteToDb(); tr.Commit(); } DocumentManager.UnlockCurrentDocument(); } } } public sealed class Plugin : IExtensionApplication { void IExtensionApplication.Initialize() { RibbonControl ribbon = ComponentManager.Ribbon; if (ribbon != null) { RibbonTab rtab = ribbon.FindTab("MyCommand"); if (rtab != null) { ribbon.Tabs.Remove(rtab); } rtab = new RibbonTab(); rtab.Title = "MyCommand"; rtab.Id = "Testing"; //Add the Tab ribbon.Tabs.Add(rtab); addContent(rtab); } } static void addContent(RibbonTab rtab) { rtab.Panels.Add(AddOnePanel()); } static RibbonPanel AddOnePanel() { RibbonButton rb; RibbonPanelSource rps = new RibbonPanelSource(); rps.Title = "My Command"; RibbonPanel rp = new RibbonPanel(); rp.Source = rps; //Create a Command Item that the Dialog Launcher can use, // for this test it is just a place holder. RibbonButton rci = new RibbonButton(); rci.Name = "MyCommand"; //assign the Command Item to the DialgLauncher which auto-enables // the little button at the lower right of a Panel rps.DialogLauncher = rci; rb = new RibbonButton(); rb.Name = "Create"; rb.ShowText = true; rb.Text = "Create"; rb.Id = "Create1"; rb.CommandHandler = new MyRibbonCommandHandler(); rb.CommandParameter = "MyCommand"; //Add the Button to the Tab rps.Items.Add(rb); return rp; } void IExtensionApplication.Terminate() { } } }