Setting ModelCurve.ByCurve to Work Plane within Family

How would one go about setting a ModelCurve.ByCurve to Workplane within a family? So the Revit geometry can be rotated using this plane after being sent from Dynamo to Revit. As currently unless the reference workplane is selected before the code is rerun there is no association between the plane and the new curves.

Following on from this I know its possible to select all reference planes with Categories or all graphic styles with Element types but is there a good workflow to just get all this data from the Family and only this data while working in the .rfa not linked yet to any project?

From reading this I found that I can set my model curves to Sketch plane in my family (standard Adaptive family current) metric Meters but it does not work as i need it too when i try and code this using. Autodesk.Revit.DB.CurveElement.SetSketchPlaneAndCurve()
It says it requires 3 arguments not just 2 but all the documentation just asks for a SketchPlane and Curve as input.

They maybe other errors in the code i am still learning how to code Python in Dynamo/Revit

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables.
Crv = IN [0]
Skplane =IN[1]
# Place your code below this line

Autodesk.Revit.DB.CurveElement.SetSketchPlaneAndCurve(Skplane,Crv)

# Assign your output to the OUT variable.
OUT = 0


File Here:SetSketchPlaneAndCurves Error.dyn (26.0 KB)

Hi @Matt_Gaydon,

As you are feeding Dynamo wrapped Revit elements to the python node, you need to unwrap them by using the UnwrapElement() method.

Give it a try and see if it helps :slightly_smiling_face:

Tried that with the UnwrapElement and still got the same error. So tried to guess what the 3rd Argument might be as can’t find it listed anywhere and when you open brackets in the Python code or in Visual studio with the same code it does not list what needs to be put in.

So if i put Autodesk.Revit.DB.CurveElement.SetSketchPlaneAndCurve(Crv,SkPlane,Crv) or True Etc, it says either expected Curve got Model Arc for the Crv.

If you try to make it Skplane first it says wanted Curve.Element but not worked out how to create that. as all the nodes only go from Curve.Element to curve and not the other way. Even tried to change the second Crv to a boolean to see what it would give and that also gave an error saying it needed a curve so out of ideas.

@Thomas_Mahon
Any thoughts on this issue, I realise your node for importing CAD are in C# and not python but maybe you have tried doing this in Python at some time.

You are attempting to call a non-static method - SetSketchPlaneAndCurve - statically, hence why Pythons interpreter is getting confused and requesting a third input.

@MartinSpence is correct, you need to unwrap your ModelCurve and sketch plane, then call the method on the unwrapped instances. Whats a bit confusing is, you call the method on the model curve and set its new curve back to itself again (although technically, you are creating a new curve to set the ModelCurve element again)…just on a difference sketch plane. Also, you forgot to add a transaction which is required as you’re modifying a Revit Element so make sure you add that otherwise the code below still wont work:

modelCurve = UnwrapElement(IN[0])
sketchPlane = UnwrapElement(IN[1])

modelCurve.SetSketchPlaneAndCurve(sketchPlane, modelCurve.GeometryCurve)
3 Likes

Ok good to know, did not know that.

So I now have the code working, but still not as expected as the curves are still not associated to the plane. Currently i have been able to set the sketch plane to the work and then rewrite them out to this plane. But maybe because this plane currently is not named or referenced from a Reference line it is not linked if you click on the curves in the Revit.

The plan is to have a plane that can be rotated in Revit with a Parameter and the curves associated to this so the curves in the family change rotation independent of Dynamo.

Latest python Code including loop so it does all curves. I realise it would be good to make the output a print to say it has been completed or event the new model curves just not go that far yet.

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import System

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)

# The inputs to this node will be stored as a list in the IN variables.
modelCurves = UnwrapElement(IN[0])
sketchPlane = UnwrapElement(IN[1])

doc.ActiveView.SketchPlane = sketchPlane

for modelCurve in modelCurves:
	modelCurve.SetSketchPlaneAndCurve(sketchPlane, modelCurve.GeometryCurve)

TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = 0

I guess in some-ways my question is answered that model curve is now on the workplane/sketch plane. But this is still not associated with the sketch plane. This maybe because the sketchplane has not name. Which i have not been able to set either.

Also i have yet to be able to use a plane from reference line my plane to be picked up by Dynamo and used as associated sketch plane so when you change the angle of the reference Curve with an angle parameter the geometry associated with it rotates much like it does in Revit if you do it manually.