Message 1 of 10
Adding Closest Grid Point Intersection to object in Revit
Not applicable
11-14-2014
10:07 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, everyone,
I am working on a project in which we want to locate objects with the nearest grids intersection.
so i have used the column location mark property to meet my need. the solution is described with the codes belows:
using (TransactionGroup transGroup = new TransactionGroup(document,"Transaction Group"))
{
transGroup.Start("Upgrade signages identity informations");
foreach (ElementId eid in SelectedElements)
{
var e = document.GetElement(eid) as FamilyInstance;
LocationPoint lp = e.Location as LocationPoint;
XYZ loc = new XYZ(lp.Point.X,lp.Point.Y,0);
ElementId levelId = e.LevelId;
Level level = document.GetElement(levelId) as Level;
Transaction tr1 = new Transaction(document,"Get Coordinates");
tr1.Start();
FamilyInstance newPoteau = document.Create.NewFamilyInstance(loc, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
tr1.Commit();
Parameter p1 = newPoteau.get_Parameter(BuiltInParameter.COLUMN_LOCATION_MARK);
string locationParam = p1.AsString();
//enlever distance dans la chaine de caractère
int index1= locationParam.IndexOf('(');
int index2= locationParam.IndexOf(')');
if(index1!=-1)
{locationParam = locationParam.Remove(index1,index2-index1+1);}
int index3= locationParam.IndexOf('(');
if(index3!=-1)
{locationParam = locationParam.Remove(index3);}
locationParam = locationParam.Replace('-',',');
//Take Level Code and Increment number
Parameter pLevel = level.get_Parameter(levelCodeParam);
levelCode = pLevel.AsString();
if(String.IsNullOrEmpty(levelCode))
{
levelCode ="??";
}
Parameter pIncrement = e.get_Parameter(incrementParam);
increment = pIncrement.AsString();
if(String.IsNullOrEmpty(increment))
{
increment="1";
}
Parameter pType = document.GetElement(e.GetTypeId()).get_Parameter(signageTypeParam);
signageType = pType.AsString();
Parameter pID= e.get_Parameter(BuiltInParameter.DOOR_NUMBER);
signageID = signageType+"-"+levelCode+"-"+locationParam+"-"+increment;
//Fill Tag
Transaction tr2 = new Transaction (document,"Fill Tag");
tr2.Start();
e.get_Parameter(xyParam).Set(locationParam);
document.Delete(newPoteau.Id);
e.get_Parameter(signageLevelCodeParam).Set(levelCode);
e.get_Parameter(incrementParam).Set(increment);
e.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(signageID);
tr2.Commit();
}
transGroup.Assimilate();
}I have to commit a column creation transaction in order to get the COLUMN_LOCATION_MARK property, and then delete the column in a other transaction.
I am pretty sure that this is not a good idea to do the thing in this way since there are so many operations on the file. so i am wondering if i can:
1. get the things done without commit the transaction in which we have creation and supression of a column object.
2. if there's a API methode to get the location mark
Thanks a lot.