Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create Mesh from Solid

1 REPLY 1
Reply
Message 1 of 2
Anonymous
510 Views, 1 Reply

Create Mesh from Solid

Hello,

 

I try to migrate our ObjectArx Api to Inventor. Therefore I need a function to create a mesh from a solid.

With Autocad .Net Api, I can use GetObjectMesh(DbObject obj, MeshFaceterData parameter). Does in the Inventor Api a similiar function exist?

In the parameters I need to set the deviation in the same way as in the Autocad .Net Api.

 

Example:

FaceterDevNormal = 0.1;

FaceterDevSurface = 0.1;

FaceterMeshType = 2;

 

Thanks for further help.

Regards,

Markus

1 REPLY 1
Message 2 of 2
philippe.leefsma
in reply to: Anonymous

Hi Markus,

 

There isn't a way to set the deviation similarly than in AutoCAD, but you need to use the "CalculateFacets" API where you can specify a tolerance. Below is a VBA sample, it can be used on SurfaceBody or Face objects, client graphics are used to visualize the result:

 

Public Sub GenerateFacets(facetable As Variant)

    Dim tolerance As Double
    Dim VertexCount As Long
    Dim FacetCount As Long
    Dim VertexCoords() As Double
    Dim normals() As Double
    Dim Indices() As Long
    
    tolerance = 0.003
    Call facetable.CalculateFacets(tolerance, VertexCount, FacetCount, VertexCoords, normals, Indices)
    
    Dim nbTriangles As Long
    nbTriangles = 0

    Dim i As Integer
    For i = 0 To UBound(Indices) Step 3
    
        Dim vIndex1 As Integer
        Dim vIndex2 As Integer
        Dim vIndex3 As Integer
        
        vIndex1 = (Indices(i) - 1) * 3
        vIndex2 = (Indices(i + 1) - 1) * 3
        vIndex3 = (Indices(i + 2) - 1) * 3

        Dim vertex1(2) As Double
        Dim vertex2(2) As Double
        Dim vertex3(2) As Double
        
        vertex1(0) = VertexCoords(vIndex1)
        vertex1(1) = VertexCoords(vIndex1 + 1)
        vertex1(2) = VertexCoords(vIndex1 + 2)
        
        vertex2(0) = VertexCoords(vIndex2)
        vertex2(1) = VertexCoords(vIndex2 + 1)
        vertex2(2) = VertexCoords(vIndex2 + 2)
        
        vertex3(0) = VertexCoords(vIndex3)
        vertex3(1) = VertexCoords(vIndex3 + 1)
        vertex3(2) = VertexCoords(vIndex3 + 2)
        
        'Call custom method to visualize facet edges
        Call DrawLineGraphics(vertex1, vertex2)
        Call DrawLineGraphics(vertex2, vertex3)
        Call DrawLineGraphics(vertex3, vertex1)
        
        nbTriangles = nbTriangles + 1
        
    Next
    
    ThisApplication.ActiveView.Update
   
End Sub

 

 

Public Sub DrawLineGraphics(startpt() As Double, endpt() As Double)

    Dim doc As Document
    Set doc = ThisApplication.ActiveDocument
    
    Dim compDef As ComponentDefinition
    Set compDef = doc.ComponentDefinition
       
    On Error Resume Next
       
    Dim dataSets As GraphicsDataSets
    Set dataSets = doc.GraphicsDataSetsCollection("LineGraphics")
    
    Dim clientGraphics As clientGraphics
    Set clientGraphics = compDef.ClientGraphicsCollection("LineGraphics")
    
    If Err Then
        Err.clear
        Set dataSets = doc.GraphicsDataSetsCollection.Add("LineGraphics")
        Set clientGraphics = compDef.ClientGraphicsCollection.Add("LineGraphics")
        
        Call dataSets.CreateCoordinateSet(1)
        Call clientGraphics.AddNode(1)
        Call clientGraphics(1).AddLineGraphics
    End If
    
    On Error GoTo 0
    
    Dim coordSet As GraphicsCoordinateSet
    Set coordSet = dataSets(1)

    Dim coords() As Double
    
    Call coordSet.GetCoordinates(coords)
    
    Dim idx As Long
    idx = 3 * coordSet.count
    
    ReDim Preserve coords(0 To idx + 5)
    
    coords(idx) = startpt(0)
    coords(idx + 1) = startpt(1)
    coords(idx + 2) = startpt(2)
    
    coords(idx + 3) = endpt(0)
    coords(idx + 4) = endpt(1)
    coords(idx + 5) = endpt(2)
    
    Call coordSet.PutCoordinates(coords)
                                               
    Dim lineGraphics As lineGraphics
    Set lineGraphics = clientGraphics(1).item(1)
    
    lineGraphics.CoordinateSet = coordSet
    
End Sub

 

Regards,

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report