How to create a New Solid using the API ?

How to create a New Solid using the API ?

bravaiser
Enthusiast Enthusiast
779 Views
6 Replies
Message 1 of 7

How to create a New Solid using the API ?

bravaiser
Enthusiast
Enthusiast

I am trying to emulate the functionality of the UI CREATE > EXTRUDE > NEW SOLID using the API. Is this possible?

0 Likes
780 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kNewBodyOperation)

 In CreateExtrudeDefinition use kNewBodyOperation

0 Likes
Message 3 of 7

bravaiser
Enthusiast
Enthusiast

Thank you Ken, I am trying this right away... 

 

 

0 Likes
Message 4 of 7

Anonymous
Not applicable

Here is the full code for the edit profile of an extrude feature example from the API documentation.

Look under the "create base extrusion 4cm thick" comment.

You can see how the extrusion is made.

Just replace the kJoinOperation line with kNewBodyOperation for Inventor to create a new body.

 

Public Sub EditFeatureProfile()
    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
    ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))

    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition

    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry

    Dim oCenter As Point2d
    Set oCenter = oTransGeom.CreatePoint2d(-5, 0)

    ' Create a sketch circle
    Dim oCircle As SketchCircle
    Set oCircle = oSketch.SketchCircles.AddByCenterRadius(oCenter, 1)

    ' Create a profile based on the circle
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid

    ' Create a base extrusion 4 cm thick.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent(4, kPositiveExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
    
    ' Draw a 4cm x 3cm rectangle with the corner at (0,0)
    Dim oRectangleLines As SketchEntitiesEnumerator
    Set oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle( _
    oTransGeom.CreatePoint2d(0, 0), _
    oTransGeom.CreatePoint2d(4, 3))

    ' Add all the lines of the rectangle to an ObjectCollection
    Dim oPathSegments As ObjectCollection
    Set oPathSegments = ThisApplication.TransientObjects.CreateObjectCollection

    Dim oEntity As SketchEntity
    For Each oEntity In oRectangleLines
      oPathSegments.Add oEntity
    Next

    ' Create a profile that represents the newly created rectangle
    ' and excludes the original circle.
    Set oProfile = oSketch.Profiles.AddForSolid(False, oPathSegments)

    ' Set the new profile
    oExtrude.Definition.Profile = oProfile
End Sub

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

Did you find one of my replies helpful ? If so please use the Accept as Solution or Kudos button below.

0 Likes
Message 6 of 7

bravaiser
Enthusiast
Enthusiast

kNewBodyOperation 

 

I got a message saying that t does not appear in the current context, I am using c# on VS2012 targeting Inventor 2015

 

 

0 Likes
Message 7 of 7

bravaiser
Enthusiast
Enthusiast

oExtrudeDefkBody = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation);

 

I needed to use PartFeatureOperationEnum let me try it now

 

0 Likes