Hi fellows!
I want to make a pick of NurbSpline in a linked DWG(the DWG contains many NurbSplines) and convert it into Dynamo.I’ve tried this:
MessageBox.Show("Pick the NurbsCurve in DWG");
UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
Document doc = uidoc.Document;
Reference rf = null;
string ss;
GeometryObject geoObj = null;
rf = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, "Pick the NurbsCurve in DWG");
ss = rf.ConvertToStableRepresentation(doc);
geoObj = doc.GetElement(rf).GetGeometryObjectFromReference(rf);
return geoObj.Convert();
My question is, I moved DWG before I run my script, while “geoObj.Convert()” returns a Dynamo geometry at the original location of the DWG, how can I get the transformed NurbSpline into Dynamo.
I’ve also tried what Revit.Elements.Element.cs did: to loop DWG GeometryElement and GeometryInstance, hoping to get “the” NurbsSpline I picked, but I didn’t figure out how to determine whether two NurbSpline(aka. GeometryObject) are the same:
private static GeometryObject GetGeometryObject(GeometryElement geometryElement, GeometryObject geoObj)
{
foreach (var geob in geometryElement)
{
var geomInstance = geob as GeometryInstance;
var geomElement = geob as GeometryElement;
if (geomInstance != null)
{
var innergeomem = geomInstance.GetInstanceGeometry();
return GetGeometryObject(innergeomem, geoObj);
}
else if (geomElement != null)
{
return GetGeometryObject(geometryElement, geoObj);
}
else if(geob == geoObj)
{
return geob;
}
}
return null;
}
Can any mentor tell me how? Appreciate!
1 Like
@805164062 ,
did also load packages from geniusLoci, or bimmorph tools ? they are in this topic…
1 Like
@Draxl_Andreas Thank you so much! Inspired by bimmorph, I figured it out, but not elegant. By comparing the values of GetEndPoint(0), one from the GeometryObject(NurbSpline) I selected by PickObject() and the other one from each GeometryObject by looping GeometryElement:
//I moved the DWG before I run my script
MessageBox.Show("Pick the NurbsCurve in DWG");
UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
Document doc = uidoc.Document;
Reference rf = null;
string ss;
GeometryObject geoObj = null;
rf = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, "Pick the NurbsCurve in DWG");
ss = rf.ConvertToStableRepresentation(doc);
geoObj = doc.GetElement(rf).GetGeometryObjectFromReference(rf);
Autodesk.Revit.DB.Element elem = doc.GetElement(rf.ElementId);
Transform trans = (elem as Autodesk.Revit.DB.ImportInstance).GetTransform();
XYZ nurbStart = trans.OfPoint((geoObj as NurbSpline).GetEndPoint(0)); //instance coordinate whithin the model
GeometryObject geoms = GetGeometryObject(uidoc.Document.GetElement(rf).get_Geometry(new Options()), nurbStart);
return geoms.Convert();
Here’s the altered Geometry() method from Revit.Elements.Element.cs:
private static GeometryObject GetGeometryObject(GeometryElement geometryElement, XYZ nurbStart)
{
foreach (var geob in geometryElement)
{
var geomInstance = geob as GeometryInstance;
var geomElement = geob as GeometryElement;
if (geomInstance != null)
{
var innergeomem = geomInstance.GetInstanceGeometry();
return GetGeometryObject(innergeomem, ntrans, nurbStart);
}
else if (geomElement != null)
{
return GetGeometryObject(geometryElement, ntrans, nurbStart);
}
else
{
NurbSpline nurbs = geob as NurbSpline;
if (nurbs != null)
{
XYZ xYZ = nurbs.GetEndPoint(0); //also an instance WCS coordinate
if (xYZ.X == nurbStart.X && xYZ.Y == nurbStart.Y && xYZ.Z == nurbStart.Z) //It seems that equality(==) between two XYZ objects has some precision error
return nurbs;
}
}
}
return null;
}
2 Likes
Hi @805164062
You can use BriMohareb_2023 package it has node to get element from cad to revit. The package access to cad as application thats means you do not need to link cad to the revit file
@RMohareb Is this package compatible with Revit 2018 and AutoCAD 2018
I’m restricted to older version of Revit
@805164062 the publiched package compatible with Revit 2023 and AutoCAD 2023 but only the Autocad link class can be work with old cad version. can you test and let me know? if it is not work i will create one for you.
OK, I’ll let you know once I make a test
Could you please share a download link. My network is terrible and I couldn’t even search dynamopackages.com
what you need to open autocad at the same time you run the script in dynamo revit. it accessthe Autocad aplication
Looks like my Dynamo 2.0.4 is too old
I can only load Google-related nodes. the “BriMohareb_2023.dll” cannot be loaded
Yes, indeed. We need upgrade urgently, otherwise many advanced packages are not available.
Best wishes for you!
1 Like