Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Transaction(TransactionMode.Manual)]
- public class Command : IExternalCommand
- {
- public Result Execute(
- ExternalCommandData commandData,
- ref string message,
- ElementSet elements)
- {
- UIApplication uiapp = commandData.Application;
- UIDocument uidoc = uiapp.ActiveUIDocument;
- Application app = uiapp.Application;
- Document doc = uidoc.Document;
- Reference r;
- try
- {
- r = uidoc.Selection.PickObject(ObjectType.Element, new ReferencePlaneSelectionFilter());
- }
- catch (OperationCanceledException)
- {
- return Result.Cancelled;
- }
- var referencePlane = doc.GetElement(r.ElementId) as ReferencePlane;
- FilteredElementCollector collector =
- new FilteredElementCollector(doc);
- var familySymbol =
- collector
- .OfClass(typeof (FamilySymbol))
- .FirstOrDefault(fs => fs.Name.Equals("Семейство на основе грани")) as FamilySymbol;
- using (var t = new Transaction(doc, "Вставка семейства"))
- {
- t.Start();
- for (double x = -1; x <= 1; x += 1)
- {
- for (double y = -1; y <= 1; y += 1)
- {
- for (double z = -1; z <= 1; z += 1)
- {
- XYZ direction = new XYZ(x, y, z);
- Debug.Print("X: {0}; Y: {1}; Z: {2}", direction.X, direction.Y, direction.Z);
- FamilyInstance createdFamilyInstance =
- CreateFamilyInstanceOnReference(doc, referencePlane.Reference, referencePlane.Plane.Origin, direction, familySymbol);
- if (createdFamilyInstance != null)
- {
- Debug.Print(direction.ToString());
- }
- }
- }
- }
- //var fs1 = doc.Create.NewFamilyInstance(XYZ.Zero, familySymbol, new XYZ(0,0,1), referencePlane,
- // StructuralType.NonStructural);
- //var fs = doc.Create.NewFamilyInstance(referencePlane.Reference,
- // XYZ.Zero, referencePlane.Normal,
- // familySymbol);
- t.Commit();
- }
- return Result.Succeeded;
- }
- FamilyInstance CreateFamilyInstanceOnReference(Document doc, Reference r, XYZ position, XYZ direction, FamilySymbol fs)
- {
- try
- {
- return doc.Create.NewFamilyInstance(r, position, direction, fs);
- }
- catch (Exception ex)
- {
- //Debug.Print(ex.Message);
- return null;
- }
- }
- }
- public class ReferencePlaneSelectionFilter : ISelectionFilter
- {
- public bool AllowElement(Element elem)
- {
- return elem is ReferencePlane;
- }
- public bool AllowReference(Reference reference, XYZ position)
- {
- throw new NotImplementedException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement