public def SelectAll3dSolidsAndLines(prompt as string) as ObjectIdCollection:
db = HostApplicationServices.WorkingDatabase
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
ids = ObjectIdCollection()
using tr = db.TransactionManager.StartTransaction():
//roll over the block table and get useable entity types:
bt = (tr.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable)
if bt is null:
ed.WriteMessage('{0}Catastrophic error: Failed to open the BlockTable!', Environment.NewLine)
return
modelspace = (tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord)
if modelspace is null:
ed.WriteMessage('{0}Catastrophic error: Failed to open the modelspace btr!', Environment.NewLine)
return
for msid as ObjectId in modelspace:
l = (tr.GetObject(msid, OpenMode.ForRead) as Line)
if l is not null:
ids.Add(msid)
s = (tr.GetObject(msid, OpenMode.ForRead) as Solid3d)
if s is not null:
ids.Add(msid)
tr.Commit()
return ids
// Autocad enums, we need to fudge these as Boo doesn't handle enums to well just yet :(
// these values are taken from the C++ ARX documentation on PromptStatus enums
// eNone 5000 No result
// eNormal 5100 Request succeeded
// eError -5001 Nonspecific error
// eCancel -5002 User canceled the request with a CTRL-C
// eRejected -5003 AutoCAD rejected the request as invalid
// eFailed -5004 Link failure, possibly with the LISP interpreter
// eKeyword -5005 Keyword returned from a "get" routine
// eDirect -5999 Passed to endGetPoint() if the getpoint was nested within
// another geometric value prompt (such as for angle), and the response
// entered was such a value rather than a point
public static def Select3dSolids(prompt as string) as (ObjectId):
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
// set up some prompt options:
pso = PromptSelectionOptions()
pso.MessageForAdding = prompt
pso.AllowDuplicates = false
// create an sset filter to only grab 3d solids, an array of typed values
ssFilter = SelectionFilter((TypedValue(0, "3DSOLID"),)) // notice the ','!
// get the sset:
res as PromptSelectionResult = ed.GetSelection(pso, ssFilter)
if res.Status != 5100 or res.Status == -5002: // OK and Cancel enums.
return null
return res.Value.GetObjectIds()
//inspired by Donnia Tabor-Hanson's (CadMama) continuous copy lisp 'cc.lsp'
[CommandMethod("CC")]
public static void ContinuousCopy()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
db.CurrentSpaceId,
OpenMode.ForWrite,
false);
using (tr)
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Object >>");
peo.SetRejectMessage("\nNothing selected >>");
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
Point3d pt = res.PickedPoint;
PromptAngleOptions pao =
new PromptAngleOptions("\nSelect angle: ");
PromptDoubleResult ares;
ares = ed.GetAngle(pao);
if (ares.Status != PromptStatus.OK)
return;
double ang = ares.Value;
PromptDistanceOptions pdo =
new PromptDistanceOptions("\nEnter a distance >>");
pdo.AllowNone = true;
pdo.UseDefaultValue = true;
pdo.DefaultValue = 12.0;
pdo.Only2d = true;
PromptDoubleResult dres;
dres = ed.GetDistance(pdo);
if (dres.Status != PromptStatus.OK)
return;
double dist = dres.Value;
double step = dist;
PromptKeywordOptions pko = new PromptKeywordOptions("\nCopy or Break out? [Copy/Break]:", "Copy Break");
pko.AllowNone = true;
pko.Keywords.Default = "Copy";
PromptResult kres = ed.GetKeywords(pko);
ed.WriteMessage("\n" + kres.StringResult);
while (kres.StringResult == "Copy")
{
Entity cent =(Entity) ent.Clone() as Entity;
Point3d topt = PolarPoint(pt, ang, dist);
Matrix3d mtx = Matrix3d.Displacement(pt.GetVectorTo(topt));
cent.TransformBy(mtx);
btr.AppendEntity(cent);
tr.AddNewlyCreatedDBObject(cent, true);
db.TransactionManager.QueueForGraphicsFlush();
dist = dist+step;
kres = ed.GetKeywords(pko);
if (kres.StringResult != "Copy") break;
}
tr.Commit();
}
}
// by Tony Tanzillo
public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)
{
return new Point3d(
basepoint.X + (distance * Math.Cos(angle)),
basepoint.Y + (distance * Math.Sin(angle)),
basepoint.Z);
}
public static PromptSelectionResult GetCurveSelection(this Editor ed, params TypedValue[] filter)
{
ed.SelectionAdded += new SelectionAddedEventHandler(OnCurveSelectionAdded);
PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
ed.SelectionAdded -= new SelectionAddedEventHandler(OnCurveSelectionAdded);
return psr;
}
static void OnCurveSelectionAdded(object sender, SelectionAddedEventArgs e)
{
ObjectId[] ids = e.AddedObjects.GetObjectIds();
for (int i = 0; i < ids.Length; i++)
{
if (!ids[i].ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(Curve))))
e.Remove(i);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ObservableSelectionSample
{
public partial class SelectionView : UserControl
{
public SelectionView()
{
InitializeComponent();
DataContext = new SelectionViewModel();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
foreach (var item in tbbt.Items)
{
var ITT0 = item.Type;
var ITT1 = item.Qty;
var ITT2 = item.Length;
}
}
}
}