Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get dimensions from sketch??

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
612 Views, 4 Replies

How to get dimensions from sketch??

hi 

 

i need to get dimensions from sketch

 

here is the code

 

 

Element e1 = (Element)Fmly;
ElementId eid = e1.Id;

Transaction t = new Transaction(doc, "fake");
t.Start();
ICollection<ElementId> ids = doc.Delete(eid);
t.RollBack();

foreach (ElementId id in ids)
{
Element ele = doc.GetElement(id);
string name = ele.Name;
list1.Add(name);
if (ele is Sketch)
{
Sketch s = (Sketch)ele;
string name4 = ele.Name;
SketchPlane sp = (SketchPlane)doc.GetElement(name4);
CurveArrArray caa = s.Profile;
foreach (CurveArray ca in caa)
{
foreach (Curve c in ca)
{

}
}
}
else if (ele is Dimension)
{
Dimension d = (Dimension)ele;
string dname = d.Name;
string dvalue = d.Value.ToString();
}

4 REPLIES 4
Message 2 of 5
aignatovich
in reply to: Anonymous

Hi! The idea of an element deletion + temporary transaction seems good for me. But source element must have a sketch in such case, e.g. source element should be a Floor, for example.

 

I think you need to improve your code: first of all, find sketch in ids list, get all model curves references, then find dimensions in this list and filter them - sketch dimensions must have references to sketch model curves (just compare stable representations)

Message 3 of 5
Anonymous
in reply to: aignatovich

hi 

i am looking to get the sweep/extrusion pathsketch dimensions.

first i am getting the sweep profile and then traversing the curves in the profile..apparently i am getting the wrong dimensions

 

can you help me out here??

where am i wrong??

 

 

 

 

Transaction t = new Transaction(doc, "GetElementId's");
t.Start();
ICollection<ElementId> ids = doc.Delete(eid);
t.RollBack();
List<string> sweeplist = new List<string>();

foreach (ElementId id in ids)
{
Element ele = doc.GetElement(id);
string name = ele.Name;
list1.Add(name);

if (ele is Sweep)
{
Sweep s1 = (Sweep)ele;
Sketch s2 = s1.PathSketch;
SketchPlane sp = s2.SketchPlane;
CurveArrArray caa = s2.;
foreach (CurveArray ca in caa)
{
foreach (Curve c in ca)
{
string cleng = c.Length.ToString();
}
}
}
}

Message 4 of 5
aignatovich
in reply to: Anonymous

I'm not sure about what you want to achieve.

Perhaps, this will help you:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
	var uiapp = commandData.Application;
	var uidoc = uiapp.ActiveUIDocument;
	var doc = uidoc.Document;

	var collector = new FilteredElementCollector(doc);

	var sweep = (Sweep) collector
		.OfClass(typeof (Sweep))
		.FirstElement();

	var profileCurves = sweep
		.ProfileSketch
		.Profile
		.Cast<CurveArray>()
		.SelectMany(x => x.Cast<Curve>());

	TaskDialog.Show("dev", $"Profile curves length: {UnitUtils.ConvertFromInternalUnits(profileCurves.Sum(x => x.Length), DisplayUnitType.DUT_MILLIMETERS)} mm");

	return Result.Succeeded;
}	
Message 5 of 5
Anonymous
in reply to: aignatovich

hi

UnitUtils.ConvertFromInternalUnits(profileCurves.Sum(x => x.Length), DisplayUnitType.DUT_MILLIMETERS)} mm");

 

thank you  @aignatovich  for this. i didn't see the units. when i run my code the length is not in mm..

so thanks for helping me out.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community