Editing Elements. Autodesk 2014 Platform API
जाहिरात
जाहिरात
Implementing all of the collections is similar. The following example uses ElementSet and ModelCurveArray to demonstrate how to use the main collection properties:
Code Region 9-2: Using collections
1. UIDocument uidoc =
new
UIDocument(document);
2. SelElementSet selection = uidoc.Selection.Elements;
3. // Store the ModelLine references
4. ModelCurveArray lineArray =
new
ModelCurveArray();
5.
6. // … Store operation
7. Autodesk.Revit.DB.ElementId id =
new
Autodesk.Revit.DB.ElementId(131943); //assume 131943 is a model line element id
8. lineArray.Append(document.GetElement(id)
as
ModelLine);
9.
10. // use Size property of Array
11. TaskDialog.Show( "Revit" , "Before Insert: " + lineArray.Size + " in lineArray." );
12.
13. // use IsEmpty property of Array
14.
if
(!lineArray.IsEmpty)
15. {
16. // use Item(int) property of Array
17. ModelCurve modelCurve = lineArray.get_Item(0)
as
ModelCurve;
18.
19. // erase the specific element from the set of elements
20. selection.Erase(modelCurve);
21.
22. // create a new model line and insert to array of model line
23. SketchPlane sketchPlane = modelCurve.SketchPlane;
24.
25. XYZ startPoint =
new
XYZ(0, 0, 0); // the start point of the line
26. XYZ endPoint =
new
XYZ(10, 10, 0); // the end point of the line
27. // create geometry line
28. Line geometryLine = Line.CreateBound(startPoint, endPoint);
29.
30. // create the ModelLine
31. ModelLine line =
32. document.Create.NewModelCurve(geometryLine, sketchPlane)
as
ModelLine;
33.
34. lineArray.Insert(line, lineArray.Size - 1);
35. }
36.
37. TaskDialog.Show( "Revit" , "After Insert: " + lineArray.Size + " in lineArray." );
38.
39. // use the Clear() method to remove all elements in lineArray
40. lineArray.Clear();
41.
42. TaskDialog.Show( "Revit
Editing Elements
In Revit, you can move, copy, rotate, align, delete, mirror, group, and array one element or a set of elements with the Revit Platform API.
Using the editing functionality in the API is similar to the commands in the Revit UI.
Moving Elements
The ElementTransformUtils class provides two static methods to move one or more elements from one place to another.
Table 19: Move Methods
Member Description
MoveElement( Document, ElementId, XYZ) Move an element in the document by a specified vector.
MoveElements(Document, ICollection<ElementId>, XYZ) Move several elements by a set of IDs in the document by a specified vector.
Note
When you use the MoveElement() or MoveElements() methods, the following rules apply.
• The methods cannot move a level-based element up or down from the level. When the element is level-based, you cannot change the
Z coordinate value. However, you can place the element at any location in the same level. As well, some level based elements have an offset instance parameter you can use to move them in the Z direction.
For example, if you create a new column at the original location (0, 0, 0) in Level1, and then move it to the new location (10, 20,
30), the column is placed at the location (10, 20, 0) instead of (10, 20, 30).
Code Region 10-1: Using MoveElement()
1.
public void
MoveColumn(Autodesk.Revit.DB.Document document, FamilyInstance column)
2. {
3. // get the column current location
4. LocationPoint columnLocation = column.Location
as
LocationPoint;
5.
6. XYZ oldPlace = columnLocation.Point;
7.
8. // Move the column to new location.
9. XYZ newPlace =
new
XYZ(10, 20, 30);
10. ElementTransformUtils.MoveElement(document, column.Id, newPlace);
11.
12. // now get the column's new location
13. columnLocation = column.Location
as
LocationPoint;
14. XYZ newActual = columnLocation.Point;
15.
16.
string
info = "Original Z location: " + oldPlace.Z +
17. "\nNew Z location: " + newActual.Z;
18.
19. TaskDialog.Show( "Revit" ,info);
20. }
• When you move one or more elements, associated elements are moved. For example, if a wall with windows is moved, the windows are also moved.
•
Pinned elements cannot be moved.
Another way to move an element in Revit is to use Location and its derivative objects. In the Revit Platform API, the Location object provides the ability to translate and rotate elements. More location information and control is available using the Location object derivatives such as
LocationPoint or LocationCurve. If the Location element is downcast to a LocationCurve object or a LocationPoint object, move the curve or the point to a new place directly.
Code Region 10-2: Moving using Location
1.
bool
MoveUsingLocationCurve(Autodesk.Revit.ApplicationServices.Application application, Wall wall)
2. {
3. LocationCurve wallLine = wall.Location
as
LocationCurve;
4. XYZ translationVec =
new
XYZ(10, 20, 0);
5.
return
(wallLine.Move(translationVec));
6. }
When you move the element, note that the vector (10, 20, 0) is not the destination but the offset. The following picture illustrates the wall position before and after moving.
Figure 30: Move a wall using the LocationCurve
In addition, you can use the LocationCurve Curve property or the LocationPoint Point property to move one element in Revit.
Use the Curve property to move a curve-driven element to any specified position. Many elements are curve-driven, such as walls, beams, and braces. Also use the property to resize the length of the element.
डाउनलोड
जाहिरात