Custom Exporter with created inactive 3D View

Custom Exporter with created inactive 3D View

Anonymous
Not applicable
687 Views
3 Replies
Message 1 of 4

Custom Exporter with created inactive 3D View

Anonymous
Not applicable

Hey guys,

 

I try to export a scene in revit using a custom exporter. I would like to export the scene without forcing the user to click on the 3D view button. In order to do this I create my own 3D view and send it to the exporter but then revit crashes somewhere by trying to access an invalid location: "Unhandled exception at 0x00007ffcb9b0a814 in Revit.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff."
In all the tutorials I could only find code which uses the active view of the document. So my question is: Can I do this without the active view but with my own "offline view" to fake the user 3D mode? I mean the view should be just a view projection matrix with some additional bounding box calculations etc. for optimization isn't it?

 

 

Here is the way I create the 3D view:

 

System::Collections::Generic::IList<Autodesk::Revit::DB::ViewFamilyType^>^ viewFamilyTypes = gcnew System::Collections::Generic::List<Autodesk::Revit::DB::ViewFamilyType^>();
FilteredElementCollector^ elementCollector = gcnew FilteredElementCollector(this->doc);
for each(Autodesk::Revit::DB::Element^ type in elementCollector->OfClass(Autodesk::Revit::DB::ViewFamilyType::typeid))
{
  if (((Autodesk::Revit::DB::ViewFamilyType^)type)->ViewFamily == Autodesk::Revit::DB::ViewFamily::ThreeDimensional)
  {
    viewFamilyTypes->Add((Autodesk::Revit::DB::ViewFamilyType^)type);
  }
}

try
{
  offlineView3D = Autodesk::Revit::DB::View3D::CreateIsometric(this->doc, viewFamilyTypes[0]->Id);
}
catch (Exception^ e)
{
}

if (nullptr != offlineView3D)
{
  XYZ^ eye = gcnew XYZ(-23.04f, 27.42f, 23.12f);
  XYZ^ forward = (gcnew XYZ(-0.344f, -0.776f, -0.528f))->Normalize();
  XYZ^ up = gcnew XYZ(-0.214f, -0.483f, 0.85f);
  offlineView3D->SetOrientation(gcnew ViewOrientation3D(eye, up, forward));

  Autodesk::Revit::DB::Parameter^ farClip = offlineView3D->LookupParameter("Far Clip Active");
  farClip->Set(0);
}

 

And then later on the document changed event I'm using the view like this:

 

MyOwnExportContext^ exportContext;
Autodesk::Revit::DB::CustomExporter^ exporter;

if (View3D^ view3D = dynamic_cast<View3D^>(view))
{
  exporter->Export(view3D);
}

 

0 Likes
688 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

You may need to regenerate the document between the view creation and the custom export:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for the fast response, I've updated the document directly after creating the view but it still crashes.

 

offlineView3D = Autodesk::Revit::DB::View3D::CreateIsometric(this->doc, viewFamilyTypes[0]->Id);
this->doc->Regenerate();

 

I can't regenerate the document just before using the view in the custom exporter because this happens inside of a OnDocumentChanged event where it is of course not allowed to regenerate the document.

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

Thank you for your appreciation.

 

Are you using the custom exported inside the OnDocumentChanged event handler?

 

That may very well crash.

 

Please postpone the custom export until later.

 

One way yo do so is to subscribe to the Idling event, and, in the handler, unsubscrbe again and do whatever you like.

 

The Idling event context is more robust and free of other limitations.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes