SKETCH_PLANE_PARAM read only

SKETCH_PLANE_PARAM read only

Anonymous
Not applicable
1,529 Views
8 Replies
Message 1 of 9

SKETCH_PLANE_PARAM read only

Anonymous
Not applicable

Hi,

 

is there a way to set the work plane for an element via the API. Following code doesn't work:

 

Parameter p = c.get_Parameter(BuiltInParameter.SKETCH_PLANE_PARAM);
if (p != null)
{
    p.Set(r.Name);
} 

as this parameter is read only. Who knows why?

 

Any ideas?

 

Thanks

Christian

0 Likes
Accepted solutions (1)
1,530 Views
8 Replies
Replies (8)
Message 2 of 9

matthew_taylor
Advisor
Advisor

Hi Christian,

Depending on the element type the sketchplane may be governed by the level or the host. See FamilyPlacementType also.

What are you trying to do?

 

-Matt

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 9

Anonymous
Not applicable

Hey Matt,

 

I am in a family document. The element I am trying to set the workplane for is a modelcurve.

 

 

public static Result Create(ReferencePlane r, ModelCurve c)
{
    Parameter p = c.get_Parameter(BuiltInParameter.SKETCH_PLANE_PARAM);
    if (p != null)
    {
        p.Set(r.Name);
        return Result.Succeeded;
    } 
    else
    {
        return Result.Failed;
    }
}

Well you can do it in the UI. Please see image attached.

 

Thanks

Christian

 

 

 

0 Likes
Message 4 of 9

matthew_taylor
Advisor
Advisor

Hi Christian,

Right.

You could do something line this if you know where you want your curve:

Dim locationCurve As DB.LocationCurve = TryCast(modelCurve.Location, DB.LocationCurve)

Dim startPoint As DB.XYZ = locationCurve.Curve.GetEndPoint(0)

Dim endPoint As DB.XYZ = locationCurve.Curve.GetEndPoint(1)

Dim newCurve As DB.Line = DB.Line.CreateBound( _
New DB.XYZ(startPoint.X, startPoint.Y, startPoint.Z + 1.0), _
New DB.XYZ(endPoint.X, endPoint.Y, endPoint.Z + 1.0)) locationCurve.Curve = newCurve

 

 

Or you could use:

 

 modelCurve.SetGeometryCurve(newCurve, True)

 

or (I haven't used this one):

    Dim sketchplane As DB.SketchPlane = Nothing 'define your sketch plane here
            modelCurve.SetSketchPlaneAndCurve(sketchPlane, newCurve)

or (I haven't used this one):

 

   Dim sketchplane As DB.SketchPlane = Nothing 'define your sketch plane here
            modelCurve.SketchPlane = sketchplane

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 5 of 9

Anonymous
Not applicable

The ModelCurve gets created in the right sketchplane, but is not associated with the workplane. The line sits in the right spot. This is not the issue. I just need to set the work plane. That's all I need.

 

Revit API developer team: Please make this parameter write accessible.

 

Thanks

Christian

0 Likes
Message 6 of 9

matthew_taylor
Advisor
Advisor

Christian,

 

'I've just hard-coded the ref plane id, but you can use a filteredelementcollector to find a specific one.
Dim refPlane As DB.ReferencePlane = TryCast(doc.GetElement(New DB.ElementId(2628)), DB.ReferencePlane)
Dim sketchplane As DB.SketchPlane = DB.SketchPlane.Create(doc, refPlane.Id)
'you may be able to reuse an existing sketchplane instead of creating one. modelCurve.SketchPlane = sketchplane

 

If the line is on the sketch plane it'll stay in the same place. If not, it'll move.

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 7 of 9

Anonymous
Not applicable

When I create the ModelCurve I am already assigning a sketchplane:

 

ModelCurve hidCurve = famdoc.FamilyCreate.NewModelCurve(hidCurves[i], sk);

Still the workplane is not set and I need to assign. I will do some more testing this afternoon, but the easiest would be: make the parameter writable.

 

Thanks

Christian

0 Likes
Message 8 of 9

matthew_taylor
Advisor
Advisor

Er, if you already have the sketch plane, then just set it via modelCurve.SketchPlane.

If that doesn't work, it's probably because your line isn't parallel or on the sketch plane. I would imagine that's why it wasn't set in the first place.

 

Edit: POST CODE.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 9 of 9

Anonymous
Not applicable
Accepted solution

Even though the parameter is read only I think I have a solution now. Quite obvios now, but .....

 

The SketchPlane.Create() method as three overwrites and one is:

 

11-29-2016 11-50-44 AM.png

 

Find the right ReferencePlane, pass the reference of that plane to create a SketchPlane and use this SketchPlane to create your ModelCurve. The ModelCurve will be sitting in the right WorkPlane.

 

Hope this helps someone. Here the code:

 

// Get the ReferencePlane by name
ReferencePlane r = Utility.GetRefPlaneByName("Center (Front/Back)", famdoc);
// Take the reference of that plane to create a new SketchPlane SketchPlane sk = SketchPlane.Create(famdoc, r.GetReference());
// Make the ModelCurve or whatever else ModelCurve ElevCurve = famdoc.FamilyCreate.NewModelCurve(ElevCurves[i], sk);

 

regards

Christian