How to retrieve Section View / elevation view Marker Current location from its location property (marker.Location)?

How to retrieve Section View / elevation view Marker Current location from its location property (marker.Location)?

akahay
Observer Observer
148 Views
3 Replies
Message 1 of 4

How to retrieve Section View / elevation view Marker Current location from its location property (marker.Location)?

akahay
Observer
Observer

I am trying to move the view markers (e.g. section view markers, or elevation view) in the active floor plan view to given the position. However, I am stuck at trying to find the marker current location then use the Location.Move(move_vector) method to move it to the new location which is determined by move_vector = (NewLocation.X -CurrentLocation.X, NewLocation.Y -CurrentLocation.Y,NewLocation.Z -CurrentLocation.Z). Please help advise on how to retrieve the current location of the marker or show a better way to achieve this?

#Revit Dynamo Python 
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements) 
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

#input 
NewLocation=IN[0] # IN[0] XYZ(10,10,10)

#Collect all the markers
markers = FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Viewers).WhereElementIsNotElementType().ToElements()

for markr in markers:
	markr.Move(NewLocation) # this works but it moves the marker 10 unit on X, Y, Z respectively but not to Point(10,10,10). I would like to move it to Point(10,10,10))

OUT= "None"       

 

0 Likes
149 Views
3 Replies
Replies (3)
Message 2 of 4

Mohamed_Arshad
Advisor
Advisor

Hi @akahay 

 you need to find the original position point of the elevation marker and then find the translation vector with newLocation using (newLocation-orignalLocation) and pass this vector to below method.

 

ElementTransformUtils.MoveElement(doc, element.Id, translationVector); 

 

Translation vector => Distance x Direction ( if you want move 5 unit from (0,0,0) position in x direction means then your translation vector will be (5,0,0).

 

To Find Original Position.

Element Marker is a Revit type element, so you need to calculate the center point of the element using bounding box, set it as a original location.

 

Reference C# Code

///Get Original Position of the Elevation marker
BoundingBoxXYZ bb = e.get_BoundingBox(doc.ActiveView);

///Get the center of the BoundingBox
XYZ origin = (bb.Min + bb.Max) / 2.0;

///New Location for the Elevation marker
XYZ newLocation = new XYZ(14.2032460977063, 49.7652126901109, origin.Z);

XYZ translationVector = newLocation - origin;

Transaction moveElemeent = new Transaction(doc, "Move Elevation Marker");

moveElemeent.Start();

DirectShape ds= DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.SetShape(new List<GeometryObject> {Point.Create(origin) });

ElementTransformUtils.MoveElement(doc, e.Id, translationVector);

moveElemeent.Commit();

 

Reference GIF

Maker Move.gif

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 3 of 4

mari.shimode
Community Manager
Community Manager

Hi @akahay, did the information provided answer your question? If so, please use Accept Solution so that others may find this in the future.

If you still have the issue, please let us know. Thank you.



Mari Shimode
Community Manager
0 Likes
Message 4 of 4

akahay
Observer
Observer

Thanks, Mohamed, for the response. I just had time this week to implement your solution. Your solution is partly working for my case because probably my . However, I am able to leverage the BoundingBox node in dynamo and use the information to get the center point of the bounding. Then still use, the marker.Location.Move(TranslationVector) to move the marker. Really appreciate the response!