Revit API for getting NWD geometry

Revit API for getting NWD geometry

achapp
Participant Participant
917 Views
5 Replies
Message 1 of 6

Revit API for getting NWD geometry

achapp
Participant
Participant

Hello,

We have a revit file that have a Navis work file .nwd load into Revit as a link. We are trying to extract the geometry.
1. What I do know is that IPhotoRenderContext::OnFaceBegin doesn't get called on it to get faces.
2. Tried recursively the DirectShape's geometry element + geometry object but doesn't hit a
Solid, Face, Mesh, etc... was wondering if there a way to get .nwd geometry.

 

  DirectShape^ pDirectShape = dynamic_cast<DirectShape^>(pElemEntry->m_curElement);
		if (pDirectShape)
		{
			m_pGeometryOption->IncludeNonVisibleObjects = true;
			m_pGeometryOption->ComputeReferences = true;
		}
		GeometryElement ^geoElement = pElemEntry->m_curElement->Geometry::get ( m_pGeometryOption );
		for each ( GeometryObject ^pGeometryObject in geomElemt )
		{
			AddGeometryObjects ( pGeometryObject, ... );
		}
    ----- function ----
    
    void AddGeometryObject( GeometryObject ^pGeometryObject, ... )
    {
      		GeometryInstance ^pGeometryInstance = dynamic_cast<GeometryInstance ^>( pGeometryObject );   <-- It is geometry instance
          Solid ^pSolid = dynamic_cast<Solid ^>( pGeometryObject );
          Face ^pFace = dynamic_cast<Face ^>( pGeometryObject );
          Mesh ^pMesh = dynamic_cast<Mesh ^>( pGeometryObject );
          Curve ^pCurve = dynamic_cast<Curve ^>( pGeometryObject );
          PolyLine ^pPolyLine = dynamic_cast<PolyLine ^>( pGeometryObject );
          Point ^pPoint = dynamic_cast<Point ^>( pGeometryObject );
          GeometryElement ^pGeometryElement = dynamic_cast<GeometryElement ^>( pGeometryObject );
          Profile ^pProfile = dynamic_cast<Profile^>( pGeometryObject );
          Edge^ pEdge = dynamic_cast<Edge^>(pGeometryObject);
    
    
        DirectShapeType^ pDirectShapeType = dynamic_cast<DirectShapeType^>(pGeometryInstance->Symbol);
        Reference^ pRef = gcnew Reference(pDirectShapeType);
				GeometryObject^ pGeoObject = pDirectShapeType->GetGeometryObjectFromReference(pRef);
				GeometryElement^ pGeoElement = dynamic_cast<GeometryElement^>(pGeoObject);
        
        if (pGeoElement)
				{
					AddGeoElement(pGeoElement ...);
				}
    }
    ---- function ---
    AddGeoElement ( GeometryElement ^pGeometryElement... )
    {
        if ( nullptr == pGeometryElement )
        {
            return;
        }

        //get all geometric primitives contained in the GeometryElement
        for each ( GeometryObject ^pGeometryObject in pGeometryElement )
        {
          AddGeometryObjects ( pGeometryObject, mTransform, bCalcSubInstance, a_pTreeNode, level, a_pDocMaterialHash );
        }
    }

Best.

 

Alex Chapp

918 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni

I am not aware of any Revit API support for retrieving NWD geometry. I think you will have to use the NavisWorks API to achieve that:

 

https://www.autodesk.com/developer-network/platform-technologies/navisworks

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 6

achapp
Participant
Participant

Hello again,

 

Thanks for the Revit Lookup plugin it is very useful,

Probably to fill in some information that last post may not have is that the navis file, was added as a Coordination Model. Also we do have another plugin to Navisworks that extract goeometry but the plugin requires Navis to be installed. If the client doesn't have Navis but only Revit then not sure how that would work. Also is there a way to "include" Navis api into the Revit plugin? Revit plugin is c++ managed, while Navis is c# & COM.

 

Best,

Alex

0 Likes
Message 4 of 6

kirylXDQF6
Contributor
Contributor

Revit has C# .NET API, so you can reference Navis dlls in theory, but I'm not sure if it will work without running Navis.

Also I experience the same issue, Revit doesn't return geometry  of .nwd CoordinationModel element:

var geomElement = document
    .GetElement(coordinationModelElementId)
    .get_Geometry(new Options { View = document.ActiveView, ComputeReferences = true });
var solid = geomElement.FirstOrDefault(go => go is Solid) as Solid;
// solid is not null but solid.Faces.Size is 0
0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor

Coordination model doesn't physically link the Navis model in to Revit it displays graphics for it via Autodesk.Revit.DB.DirectContext3D. So I believe it is generally no more physically present in your Revit model than your mouse cursor.

 

RPTHOMAS108_0-1677030176776.png

You may be able to find the C# wrapper above and utilise that to get the Navis graphics in the same way coordination model does perhaps. However the reality is you will probably be dealing with low level triangles rather than solids etc. (since that is ultimately what DirectContext3D uses to display such in Revit).

Message 6 of 6

kirylXDQF6
Contributor
Contributor

Low level triangles is exactly what I need. Though at this point I'm not sure if it's worthy to dive that deep... Thanks anyway!
P.S. Where did you get this picture? May be I'll find more clues there once decide that I need nwd.

0 Likes