Need location of geometry imorted from OBJ file

Need location of geometry imorted from OBJ file

Anonymous
Not applicable
976 Views
6 Replies
Message 1 of 7

Need location of geometry imorted from OBJ file

Anonymous
Not applicable

I used DirectShape to load the geometry from obj file. Model is coming good in Revit. However I want to create family for all components in OBJ file. To place instance of each family at correction location so that complete assembly can be formed correctly, I need location of each family created by using DirectShape. DirectShape does have property as "Location", but it is giving NULL. 

Please help me how to get location of newly imported geometry by using DirectShape.

977 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

I think the direct shape is always created exactly where you specify it.

 

Can you please check what happens if you move it manually after it has been created?

 

Maybe that sets the location somehow?

 

You can use RevitLookup to examine the result.

 

If you have not yet installed RevitLookup, you should do so immediately, right away, before doing a single other thing.

 

It is an invaluable Revit database exploration and analysis tool, and you cannot effectively develop add-ins without it.

 

Cheers,

 

Jeremy



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

0 Likes
Message 3 of 7

bahaaeldien.metwaly
Contributor
Contributor

Still not possible in Revit 2021 .. Element.Location property returns a Location object that can't be cast to Location Point or Location Curve .. Dead end ..

0 Likes
Message 4 of 7

jeremy_tammik
Alumni
Alumni

I am sure there are workable solutions for this, e.g., create a family definition containing a direct shape and place instances of that, which do have a valid location point, or explore how to use the DirectShapeLibrary class:

 

https://www.revitapidocs.com/2022/07489bae-ab9f-e2a8-0ac1-0a4d70cea458.htm

 

> DirectShapeLibrary is used to store pre-created geometry for further referencing via the definition/instance mechanism.

  

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

bahaaeldien.metwaly
Contributor
Contributor

@jeremy_tammik wrote:

I am sure there are workable solutions for this, e.g., create a family definition containing a direct shape and place instances of that, which do have a valid location point, or explore how to use the DirectShapeLibrary class:

 

https://www.revitapidocs.com/2022/07489bae-ab9f-e2a8-0ac1-0a4d70cea458.htm

 

> DirectShapeLibrary is used to store pre-created geometry for further referencing via the definition/instance mechanism.

  


Hi Jeremy,

The underlined is exactly what we are looking to do .. but automatically, so Imagine you received a model in IFC format , and you need to replace a couple of hundred elements(DirectShape)s with proper families .. You can't extract their location and you can't change their type to proper FamilyType of the same category.

I'll try to explore the DirectShapeLibrary a bit though. Thanks.

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor

Yes you can use the Transform.Origin of the direct shape instance when you use instance/type approach rather than just creating a isolated direct shape.

 

Using type/instance approach with DirectShapeLibrary or DirectShape.CreateElementInstance also allows type category bound parameters to be added in the project to the direct shape type.

 

Public Function Obj_211003a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result
        Dim uidoc = commandData.Application.ActiveUIDocument
        Dim IntDoc = uidoc.Document

        Dim Pt As New XYZ(0, 0, 0)
        Dim Unit As Double = 0.5

        Dim Fr As New Frame(Pt, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ)
        Dim LN As Line = Line.CreateBound(Pt - (XYZ.BasisZ * Unit), Pt + (XYZ.BasisZ * Unit))
        Dim Pl As Plane = Plane.CreateByNormalAndOrigin(XYZ.BasisY, Pt)
        Dim Arc As Arc = Arc.Create(Pl, Unit, 0, Math.PI)
        Dim Cl As New CurveLoop
        Cl.Append(LN)
        Cl.Append(Arc)
        Dim CLa = New CurveLoop() {Cl}.ToList
        Dim Ob As Solid = GeometryCreationUtilities.CreateRevolvedGeometry(Fr, CLa, 0, 2 * Math.PI)

        Using Tr As New Transaction(IntDoc, "DS")
            If Tr.Start = TransactionStatus.Started Then

                Dim DSt As DirectShapeType = DirectShapeType.Create(IntDoc, "Sphere", New ElementId(BuiltInCategory.OST_GenericModel))
                DSt.AppendShape(New GeometryObject(0) {Ob}.ToList)

                Dim Location As New XYZ(10, 15, 20)
                Dim T As Transform = Transform.CreateTranslation(Location)

                Dim DSL = DirectShapeLibrary.GetDirectShapeLibrary(IntDoc)
                DSL.AddDefinitionType("Sphere_AA", DSt.Id)

                'Contains geometry transform with origin
                Dim LL As List(Of GeometryObject) = DirectShape.CreateGeometryInstance(IntDoc, "Sphere_AA", T)

                Dim DSX = DirectShape.CreateElement(IntDoc, New ElementId(BuiltInCategory.OST_GenericModel))
                DSX.SetShape(LL)

                'This set below is apparently not required but it associates the instance with the type
                'Therefore any type parameters added in project to the associated category will be available in the DS type
                DSX.SetTypeId(DSt.Id)

                Tr.Commit()

            End If
        End Using

        Return Result.Succeeded
    End Function

 

When you extract the geometry of the above shape it will contain a GeometryInstance with Transform.Origin set to 10,15,20 and the symbol geometry will be at 0,0,0.

Message 7 of 7

bahaaeldien.metwaly
Contributor
Contributor
That's very helpful .. Thank you Thomas!..
0 Likes