Hi Claudio,
the follow VBA code is a mixture of examples from the Inventor API help, has to be personalized and improved.
Copy/paste this code whitin a module
Option Explicit
Public Sub EmbossedText()
' Create a new clsSelect object.
Dim oSelect As New clsSelect
' Set a reference to the part component definition.
' This assumes that a part document is active.
Dim oCompDef As PartComponentDefinition
Set oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Call the pick method of the clsSelect object and set
' the filter to pick any face.
Dim oFace As Face
Set oFace = oSelect.Pick(kPartFaceFilter)
' Check to make sure an object was selected.
If Not oFace Is Nothing Then
Dim oSketch As PlanarSketch
Set oSketch = oCompDef.Sketches.Add(oFace, True)
oSketch.Name = "Embossed text"
' Create text with simple string as input. Since this doesn't use
' any text overrides, it will default to the active text style.
Dim sText As String
Dim oTextBox As TextBox
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
' Simple single line text.
sText = "Here is the last and final line of text."
Set oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(oSketch.OriginPointGeometry.X, _
oSketch.OriginPointGeometry.Y), sText)
With oTextBox
.VerticalJustification = kAlignTextMiddle
.HorizontalJustification = kAlignTextCenter
End With
' Add the text box to an object collection
Dim oPaths As ObjectCollection
Set oPaths = ThisApplication.TransientObjects.CreateObjectCollection
oPaths.Add oTextBox
' Create a profile. Calling the AddForSolid method without any
' arguments will result in a profile containing all possible
' paths in the sketch. By passing in the text box, the profile
' is restricted to the input text path.
Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid(False, oPaths)
' Extrude the text.
Dim oExtrudeDef As ExtrudeDefinition
Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
Call oExtrudeDef.SetDistanceExtent(0.25, kNegativeExtentDirection)
Dim oExtrude As ExtrudeFeature
Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
End If
End Sub
Copy/paste this code in a class named "clsSelect" (Inventor API help)
Option Explicit
' Declare the event objects
Private WithEvents oInteractEvents As InteractionEvents
Private WithEvents oSelectEvents As SelectEvents
' Declare a flag that's used to determine when selection stops.
Private bStillSelecting As Boolean
Public Function Pick(filter As SelectionFilterEnum) As Object
' Initialize flag.
bStillSelecting = True
' Create an InteractionEvents object.
Set oInteractEvents = ThisApplication.CommandManager.CreateInteractionEvents
' Ensure interaction is enabled.
oInteractEvents.InteractionDisabled = False
' Set a reference to the select events.
Set oSelectEvents = oInteractEvents.SelectEvents
' Set the filter using the value passed in.
oSelectEvents.AddSelectionFilter filter
' Start the InteractionEvents object.
oInteractEvents.Start
' Loop until a selection is made.
Do While bStillSelecting
ThisApplication.UserInterfaceManager.DoEvents
Loop
' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelectEvents.SelectedEntities
If oSelectedEnts.Count > 0 Then
Set Pick = oSelectedEnts.Item(1)
Else
Set Pick = Nothing
End If
' Stop the InteractionEvents object.
oInteractEvents.Stop
' Clean up.
Set oSelectEvents = Nothing
Set oInteractEvents = Nothing
End Function
Private Sub oInteractEvents_OnTerminate()
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
Private Sub oSelectEvents_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, ByVal SelectionDevice As SelectionDeviceEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
' Set the flag to indicate we're done.
bStillSelecting = False
End Sub
You have to run the macro and then select the plan, that's all.
I've used VBA because you need of an event trigger for select the plan, alternatively you have to use the .NET.
Bregs
Rossano Praderi
--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------