Retrieving Definition DirectShape Library
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been trying to do some tasks which involves the usage of direct shape library and i'm stuck with it. The details are specified below. Any help would be appreciated.
QUICK INFO ON THE TASK: In a project that I'm working on, we need to import ".ifc" files (These are the models developed in Tekla and exported as ".ifc"). Once imported inside Revit, the file size exceeds more than 800 Mb (in some cases 1 GB). So, we are trying to develop some strategy to split the Revit files (after importing the ".ifc") into multiple files. Based on some logical calculations, new files are created. (Since this is just a split up of the main Revit file, it could be easier to duplicate files and delete unwanted elements. However, for some internal reasons, we decided to re create all the elements as direct shape in the new project files).
ISSUE: In one part of the code, we need to add the geometry instances of the objects to Shapelibrary and need to retrieve the same again later. However, we are able to add geometry instances to the shape library but unable to retrieve the same.
Please look at the code below:
1. We have retrieved an element from the Revit file. For each element, we have created a custom element wrapper class which stores the list of geometry objects.
2. We have a function which takes a Geometry instance as the input, as shown below.
Private Function ObtainInstanceTypeData (CurrentDoc As Document, GeoInstance As GeometryInstance) As Tuple(Of String, ElementId) Dim ituple As Tuple(Of String,ElementId) = Nothing Dim ishapelib As DirectShapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(CurrentDoc) ' Obtain the library from the current document Dim iDSType As DirectShapeType = TryCast(GeoInstance.Symbol,DirectShapeType) ' To obtain unique id for each element Dim inewObjectslist As IList(Of GeometryObject) = GeoInstance.SymbolGeometry.ToList Dim DefName As String = iDSType.Id.ToString ' Using the TypeId as the definition string name as well. If ishapelib.Contains(iDSType.Id.ToString) = False Then ishapelib.AddDefinition(iDSType.Id.ToString,inewObjectslist) End If ituple = New Tuple(Of String, ElementId)(DefName,iDSType.Id) Return ituple End Function
3. It works perfectly until above point (at least we believe it works perfectly. Please point out if there is any issue with above code)
4. "ObtainInstanceTypeData" is a function to confirm if the shapelibrary contains a specific instance geometry and add the same if not present. We obtain a string (definition id) and feed it into "DirectShape.CreateGeometryInstance" to create a geometry instance (as shown below) . This is where the issue arises, it results in Null exception.
If ibelement.GeometryInstanceList.Count <> 0 Then For Each iGeoInst As GeometryInstance In ibelement.GeometryInstanceList 'Custom Element Wrapper which provides the List of Geometry instances inside a given element Try Dim pTuple As Tuple(Of String,ElementId) = ObtainInstanceTypeData(pdoc,iGeoInst) Dim newObjList As IList(Of GeometryObject) = DirectShape.CreateGeometryInstance(pdoc,pTuple.Item1,iGeoInst.Transform) Dim kds As DirectShape = DirectShape.CreateElement(pdoc,ibelement.ElementCategory.Id) kds.SetShape(newObjList) Dim kdsoptions As DirectShapeOptions = kds.GetOptions kdsoptions.ReferencingOption = DirectShapeReferencingOption.Referenceable kds.SetOptions(kdsoptions) Catch ex As Exception 'TaskDialog.Show ("Error",ex.ToString) End Try Next End If
5. Question is: Is there a better way to use shapelibrary and retrieve objects? Why does the "CreateGeometryInstance" returns null error when the defintion was added just a step earlier.? Any help would be appreciated.