Create sketch plane based on reference line

Create sketch plane based on reference line

net.k.kiselev
Contributor Contributor
3,574 Views
5 Replies
Message 1 of 6

Create sketch plane based on reference line

net.k.kiselev
Contributor
Contributor

I want create some extrusion that will have dependence on reference plane. 
I know that i can create sketch plane with geometry reference, and this reference line have surfaces, but reference of this surfaces always equal null. 

Is in Revit API possibilities for creating sketch plane based on reference line surfaces?

0 Likes
Accepted solutions (2)
3,575 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

I see no direct way (there may be a utility class similar to HostObjectUtils somewhere). Without such you may be able to create a reference manually from string using:

Reference.ParseFromStableRepresentation

 

From two reference lines within a family file the below reference representations were noted:

 

The directions relate to orientation of the member, drawn from left to right on plan:

Left
ea0d44b8-86cc-48d2-814b-ef579c33eeda-00000c5f:1:12:SURFACE
Right
ea0d44b8-86cc-48d2-814b-ef579c33eeda-00000c5f:1:17:SURFACE
Top/Bottom
ea0d44b8-86cc-48d2-814b-ef579c33eeda-00000c5f:1:2:SURFACE
Front/Back
ea0d44b8-86cc-48d2-814b-ef579c33eeda-00000c5f:1:7:SURFACE

Left
462fa80a-60c1-48bd-9742-b98d6a32fb93-00000617:1:12:SURFACE
Right
462fa80a-60c1-48bd-9742-b98d6a32fb93-00000617:1:17:SURFACE
Top/Bottom
462fa80a-60c1-48bd-9742-b98d6a32fb93-00000617:1:2:SURFACE
Front/Back
462fa80a-60c1-48bd-9742-b98d6a32fb93-00000617:1:7:SURFACE

 

Capture210219.PNG

 

Probably better to use a sweep with a profile as shape and ref line as path rather than extrusion (if the aim is to extrude along the ref line).

 

 

Message 3 of 6

net.k.kiselev
Contributor
Contributor
Accepted solution

Hello! Thanks, i think it is must work. 
I make some simple method that create reference from face without reference, and it's works for me


public static Reference GetFaceReference(this Face f, Element e){
var stableRepr = $"{e.UniqueId}:{f.Id}:SURFACE";
return Reference.ParseFromStableRepresentation(e.Document, stableRepr);
 

 

0 Likes
Message 4 of 6

RPTHOMAS108
Mentor
Mentor

Yes but format appears to be UID:ObjectIndex:FaceIndex:SURFACE 

 

Where object index could relate to solid, curve (GeometryObject) etc.

 

Depending on the type of object you get different forms of this (:::) I think.

 

Not sure you are able to extract surfaces from reference lines (subcategory of model lines) so may have to resort to the numbers above which seem consistent.

0 Likes
Message 5 of 6

net.k.kiselev
Contributor
Contributor

If model is reference line, then i can extract geometry (line with this category have solid with 4 faces, i think it's some trick for creating sketch planes because in base it require surface reference ), and create reference with this method.

0 Likes
Message 6 of 6

Anonymous
Not applicable

I want to thank you guys.

 

I was able to create a reference to a workplane using this method, which I am then able to set an elements workplane on creation.

 

What I did was use one of the stable representation strings from RPT's findings. Then I created a new sketch plane with this reference. Finally I set the sketch plane of the view I wanted to use for creating a new element, and then created the element. Hopefully this can help someone else.

 

 

var reference_line = new FilteredElementCollector(doc)
                .OfClass(typeof(CurveElement))
                .OfType<ModelLine>()
                .Where(line =>
                    line
                        .CurveElementType
                        .Equals(CurveElementType.ReferenceLine))
                .FirstOrDefault();

            var line_face = reference_line
                .get_Geometry(
                    WWUtils.NewOptions())
                .OfType<Solid>()
                .FirstOrDefault()
                .Faces
                .get_Item(0);
            var stable_rep = $"{reference_line.UniqueId}:1:2:SURFACE";
            var new_ref = Reference.ParseFromStableRepresentation(
                doc,
                stable_rep);
            using (var tx = new Transaction(doc, "new sketch plane"))
            {
                tx.Start();
                var new_sketch_plane = SketchPlane.Create(doc, new_ref);
                var doc_import_view = doc.ActiveView;
                doc_import_view.SketchPlane = new_sketch_plane;
                dwg_import_options.ThisViewOnly = true;
                ElementId new_id;
                doc.Import(
                    dwg_path,
                    dwg_import_options,
                    doc_import_view,
                    out new_id);
                var new_import = doc.GetElement(new_id);
                tx.Commit();
            }